@@ -91,7 +91,7 @@ void CompletionTrie_Collect(completion_trie_root_t* root,
9191 uint32_t parentStack [128 ];
9292 uint16_t childIndexStack [128 ];
9393 uint16_t completionLengthAddStack [128 ];
94- uint32_t unmatchedPrefixLengthStack [128 ];
94+ uint8_t matchedLengthStack [128 ];
9595
9696 completion_trie_node_t const * nodes = root -> Nodes ;
9797 const uint32_t completionLengthBase = matchedUntil - PrefixLen (nodes [startNodeIdx ].Prefix4 );
@@ -134,10 +134,10 @@ void CompletionTrie_Collect(completion_trie_root_t* root,
134134 for (uint32_t i = childBeginIdx + currentChildIndex ; i < childEndIdx ; i ++ )
135135 {
136136 const completion_trie_node_t * child = nodes + i ;
137+ uint32_t checkLength = currentUnmatchedPrefixLength ;
137138
138139 if (currentUnmatchedPrefixLength )
139140 {
140- uint32_t checkLength = currentUnmatchedPrefixLength ;
141141 uint32_t childPrefixLen = PrefixLen (child -> Prefix4 );
142142 if (childPrefixLen < checkLength )
143143 {
@@ -149,6 +149,7 @@ void CompletionTrie_Collect(completion_trie_root_t* root,
149149 continue ;
150150 }
151151 currentUnmatchedPrefixLength -= checkLength ;
152+ matchedUntil += checkLength ;
152153 assert (currentUnmatchedPrefixLength >= 0 && currentUnmatchedPrefixLength <= 512 );
153154 }
154155
@@ -166,17 +167,18 @@ void CompletionTrie_Collect(completion_trie_root_t* root,
166167 if (currentNodeIdx == startNodeIdx )
167168 currentUnmatchedPrefixLength = unmatchedPrefixLength ;
168169 }
169- else if ( descend )
170+ else
170171 {
171- // Push Completion stacks
172+ assert (descend );
173+ // Push Completion stacks
172174 {
173175 parentStack [currentStackIndex ] = currentNodeIdx ;
174176 childIndexStack [currentStackIndex ] = i - childBeginIdx ;
175177 completionLengthAddStack [currentStackIndex ] = completionLength - completionLengthBase ;
176- unmatchedPrefixLengthStack [currentStackIndex ] = currentUnmatchedPrefixLength ;
178+ matchedLengthStack [currentStackIndex ] = checkLength ;
177179 ++ currentStackIndex ;
178180 }
179- // change relevant iteration state
181+ // change relevant iteration state
180182 currentNodeIdx = i ;
181183 currentChildIndex = 0 ;
182184 goto LSetCurrent ;
@@ -192,7 +194,8 @@ void CompletionTrie_Collect(completion_trie_root_t* root,
192194 currentNodeIdx = parentStack [currentStackIndex ];
193195 currentChildIndex = childIndexStack [currentStackIndex ];
194196 completionLength = completionLengthBase + completionLengthAddStack [currentStackIndex ];
195- currentUnmatchedPrefixLength = unmatchedPrefixLengthStack [currentStackIndex ];
197+ currentUnmatchedPrefixLength += matchedLengthStack [currentStackIndex ];
198+ matchedUntil -= matchedLengthStack [currentStackIndex ];
196199 descend = false;
197200 }
198201 }
0 commit comments