@@ -34,7 +34,7 @@ impl<T: fmt::Debug> Node<T> {
34
34
}
35
35
36
36
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 {
38
38
NodeKind :: String ( p) => {
39
39
if p. is_empty ( ) {
40
40
* p = bytes. to_vec ( ) ;
@@ -47,29 +47,30 @@ impl<T: fmt::Debug> Node<T> {
47
47
. take_while ( |( a, b) | a == b)
48
48
. count ( ) ;
49
49
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..] ;
53
63
true
54
64
} 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
+ }
66
68
}
67
- NodeKind :: Parameter ( _) => ( 0 , true ) ,
69
+ NodeKind :: Parameter ( _) => true ,
68
70
} ;
69
71
70
72
// insert node
71
73
if diff {
72
- bytes = & bytes[ cursor..] ;
73
74
let nodes = self . nodes0 . get_or_insert_with ( Vec :: new) ;
74
75
return match nodes. binary_search_by ( |node| match & node. kind {
75
76
NodeKind :: String ( s) => {
0 commit comments