Combine final metadata traversal

This commit is contained in:
2026-10-09 00:52:55 +00:00
parent 673faea097
commit c546124029
4 changed files with 328 additions and 20 deletions

View File

@@ -109,10 +109,9 @@ func (m Metadata) hasHistoricalPath(path Path) bool {
}
func finalizeMetadataPaths(m *Metadata, final *document.Node, applications []historyApplication, earlier ...*document.Node) {
m.effectivePaths = effectivePathIndex(final)
m.effectivePaths = make(map[string]Path)
m.historicalPaths = make(map[string][]Path)
add := func(path Path, _ *document.Node) {
pointer := path.String()
addHistorical := func(path Path, pointer string) {
for _, prior := range m.historicalPaths[pointer] {
if matchesPathShape(path, prior) {
return
@@ -120,7 +119,14 @@ func finalizeMetadataPaths(m *Metadata, final *document.Node, applications []his
}
m.historicalPaths[pointer] = append(m.historicalPaths[pointer], path.clone())
}
walkDocument(final, Path{}, add)
walkDocument(final, Path{}, func(path Path, _ *document.Node) {
pointer := path.String()
m.effectivePaths[pointer] = path.clone()
addHistorical(path, pointer)
})
add := func(path Path, _ *document.Node) {
addHistorical(path, path.String())
}
for _, tree := range earlier {
walkDocument(tree, Path{}, add)
}