Skip to content

Commit 629ccb2

Browse files
committed
treesteps: deduplicate tree printing code
1 parent 29c445d commit 629ccb2

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

internal/treesteps/tree_steps_on.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"sync"
1515
"sync/atomic"
1616
"unicode"
17-
18-
"github.com/cockroachdb/pebble/internal/treeprinter"
1917
)
2018

2119
const Enabled = true
@@ -281,20 +279,19 @@ func firstWord(str string) string {
281279
// TreeToString returns a string representation of the current state of a Node
282280
// tree.
283281
func TreeToString(n Node) string {
284-
tp := treeprinter.New()
285-
treePrint(n, tp)
286-
return tp.String()
287-
}
288-
289-
func treePrint(n Node, tp treeprinter.Node) {
290-
ni := n.TreeStepsNode()
291-
tpNode := tp.Child(ni.name)
292-
for _, prop := range ni.properties {
293-
tpNode.Childf("%s: %s", prop[0], prop[1])
294-
}
295-
for _, child := range ni.children {
296-
treePrint(child, tpNode)
282+
var buildTree func(n Node) TreeNode
283+
buildTree = func(n Node) TreeNode {
284+
var t TreeNode
285+
info := n.TreeStepsNode()
286+
t.Name = info.name
287+
t.Properties = info.properties
288+
for _, child := range info.children {
289+
t.Children = append(t.Children, buildTree(child))
290+
}
291+
return t
297292
}
293+
t := buildTree(n)
294+
return t.String()
298295
}
299296

300297
type nodeState struct {

0 commit comments

Comments
 (0)