File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -479,9 +479,33 @@ func (n *Node) Unsplit() bool {
479479 if n .parent .IsLeaf () {
480480 return n .parent .Unsplit ()
481481 }
482+
483+ n .parent .simplify ()
482484 return true
483485}
484486
487+ // simplify removes unnecessary intermediate parents that have only one child
488+ func (n * Node ) simplify () {
489+ if n .parent == nil || len (n .children ) != 1 {
490+ n .markResize ()
491+ return
492+ }
493+
494+ ind := 0
495+ for i , c := range n .parent .children {
496+ if c .id == n .id {
497+ ind = i
498+ }
499+ }
500+
501+ parent := n .parent
502+ kind := n .Kind
503+ parent .children [ind ] = n .children [0 ]
504+ parent .children [ind ].parent = parent
505+ parent .children [ind ].Kind = kind
506+ parent .simplify ()
507+ }
508+
485509// String returns the string form of the node and all children (used for debugging)
486510func (n * Node ) String () string {
487511 var strf func (n * Node , ident int ) string
You can’t perform that action at this time.
0 commit comments