@@ -34,7 +34,7 @@ impl<T: fmt::Debug> Node<T> {
3434 }
3535
3636 pub fn insert_bytes ( & mut self , mut bytes : & [ u8 ] ) -> & mut Self {
37- let ( cursor , diff) = match & mut self . kind {
37+ let diff = match & mut self . kind {
3838 NodeKind :: String ( p) => {
3939 if p. is_empty ( ) {
4040 * p = bytes. to_vec ( ) ;
@@ -47,29 +47,30 @@ impl<T: fmt::Debug> Node<T> {
4747 . take_while ( |( a, b) | a == b)
4848 . count ( ) ;
4949
50- (
51- cursor,
52- if cursor == 0 {
50+ if cursor == 0 {
51+ true
52+ } else {
53+ // split node
54+ if cursor < p. len ( ) {
55+ let ( prefix, suffix) = p. split_at ( cursor) ;
56+ let mut node = Node :: new ( NodeKind :: String ( prefix. to_vec ( ) ) , None ) ;
57+ * p = suffix. to_vec ( ) ;
58+ :: std:: mem:: swap ( self , & mut node) ;
59+ self . nodes0 . get_or_insert_with ( Vec :: new) . push ( node) ;
60+ }
61+ if cursor != bytes. len ( ) {
62+ bytes = & bytes[ cursor..] ;
5363 true
5464 } else {
55- // split node
56- if cursor < p. len ( ) {
57- let ( prefix, suffix) = p. split_at ( cursor) ;
58- let mut node = Node :: new ( NodeKind :: String ( prefix. to_vec ( ) ) , None ) ;
59- * p = suffix. to_vec ( ) ;
60- :: std:: mem:: swap ( self , & mut node) ;
61- self . nodes0 . get_or_insert_with ( Vec :: new) . push ( node) ;
62- }
63- cursor != bytes. len ( )
64- } ,
65- )
65+ false
66+ }
67+ }
6668 }
67- NodeKind :: Parameter ( _) => ( 0 , true ) ,
69+ NodeKind :: Parameter ( _) => true ,
6870 } ;
6971
7072 // insert node
7173 if diff {
72- bytes = & bytes[ cursor..] ;
7374 let nodes = self . nodes0 . get_or_insert_with ( Vec :: new) ;
7475 return match nodes. binary_search_by ( |node| match & node. kind {
7576 NodeKind :: String ( s) => {
0 commit comments