Reconcile retained history accounting
This commit is contained in:
@@ -40,50 +40,6 @@ func (c *retainedNodeCounter) add(root *document.Node) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *retainedNodeCounter) canAddClones(roots []*document.Node, copies int) bool {
|
||||
if c == nil || c.limit < 0 {
|
||||
return true
|
||||
}
|
||||
remaining := c.limit - c.count
|
||||
if remaining < 0 {
|
||||
return false
|
||||
}
|
||||
for copyIndex := 0; copyIndex < copies; copyIndex++ {
|
||||
for _, root := range roots {
|
||||
count, within := documentCloneNodeCount(root, remaining)
|
||||
if !within {
|
||||
return false
|
||||
}
|
||||
remaining -= count
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func documentCloneNodeCount(root *document.Node, limit int) (int, bool) {
|
||||
if root == nil {
|
||||
return 0, true
|
||||
}
|
||||
count := 0
|
||||
stack := []*document.Node{root}
|
||||
for len(stack) != 0 {
|
||||
node := stack[len(stack)-1]
|
||||
stack = stack[:len(stack)-1]
|
||||
if node == nil {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
if count > limit {
|
||||
return 0, false
|
||||
}
|
||||
for _, entry := range node.Mapping {
|
||||
stack = append(stack, entry.Value)
|
||||
}
|
||||
stack = append(stack, node.Sequence...)
|
||||
}
|
||||
return count, true
|
||||
}
|
||||
|
||||
func addInspectionHistory(counter *retainedNodeCounter, inspection *Inspection) bool {
|
||||
if inspection == nil || inspection.history == nil {
|
||||
return false
|
||||
@@ -93,7 +49,7 @@ func addInspectionHistory(counter *retainedNodeCounter, inspection *Inspection)
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
return counter.add(inspection.final)
|
||||
}
|
||||
|
||||
// History applications borrow immutable policy-validated input trees. Metadata
|
||||
|
||||
Reference in New Issue
Block a user