+ PRTL_SPLAY_LINKS SplayLinks;
+ PUNICODE_PREFIX_TABLE_ENTRY Entry;
+ PUNICODE_PREFIX_TABLE_ENTRY CaseMatchEntry;
+
+ /* We might need this entry 2/3rd of the time, so cache it now */
+ CaseMatchEntry = PrefixTable->LastNextEntry->CaseMatch;
+
+ /* Check if this is a restart or if we don't have a last entry */
+ if ((Restart) || !(PrefixTable->LastNextEntry))
+ {
+ /* Get the next entry and validate it */
+ Entry = PrefixTable->NextPrefixTree;
+ if (Entry->NodeTypeCode == PFX_NTC_TABLE) return NULL;
+
+ /* Now get the Splay Tree Links */
+ SplayLinks = &Entry->Links;
+
+ /* Loop until we get the first node in the tree */
+ while (RtlLeftChild(SplayLinks)) SplayLinks = RtlLeftChild(SplayLinks);
+
+ /* Get the entry from it */
+ Entry = CONTAINING_RECORD(SplayLinks,
+ UNICODE_PREFIX_TABLE_ENTRY,
+ Links);
+ }
+ else if (CaseMatchEntry->NodeTypeCode == PFX_NTC_CASE_MATCH)
+ {
+ /* If the last entry was a Case Match, then return it */
+ Entry = CaseMatchEntry;
+ }
+ else
+ {
+ /* Find the successor */
+ SplayLinks = RtlRealSuccessor(&CaseMatchEntry->Links);
+ if (!SplayLinks)
+ {
+ /* Didn't find one, we'll have to search the tree */
+ SplayLinks = &PrefixTable->LastNextEntry->Links;
+
+ /* Get the topmost node (root) */
+ while (!RtlIsRoot(SplayLinks)) SplayLinks = RtlParent(SplayLinks);
+ Entry = CONTAINING_RECORD(SplayLinks,
+ UNICODE_PREFIX_TABLE_ENTRY,
+ Links);
+
+ /* Get its tree and make sure somethign is in it */
+ Entry = Entry->NextPrefixTree;
+ if (Entry->NameLength <= 0) return NULL;
+
+ /* Select these new links and find the first node */
+ while (RtlLeftChild(SplayLinks)) SplayLinks = RtlLeftChild(SplayLinks);
+ }
+
+ /* Get the entry from it */
+ Entry = CONTAINING_RECORD(SplayLinks,
+ UNICODE_PREFIX_TABLE_ENTRY,
+ Links);
+ }
+
+ /* Save this entry as the last one returned, and return it */
+ PrefixTable->LastNextEntry = Entry;
+ return Entry;