Patchwork D3497: revlog: extract function for fully populating the radix tree

login
register
mail settings
Submitter phabricator
Date May 8, 2018, 6:07 p.m.
Message ID <differential-rev-PHID-DREV-jdd6pbxgykrqebih7lh4-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/31382/
State Superseded
Headers show

Comments

phabricator - May 8, 2018, 6:07 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This code is currently used for partialmatch(), but I want to reuse it
  when I implement shortest() in native code.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3497

AFFECTED FILES
  mercurial/cext/revlog.c

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -1230,25 +1230,31 @@ 
 	return NULL;
 }
 
+/*
+ * Fully populate the radix tree.
+ */
+static int nt_populate(indexObject *self) {
+	int rev;
+	if (self->ntrev > 0) {
+		for (rev = self->ntrev - 1; rev >= 0; rev--) {
+			const char *n = index_node_existing(self, rev);
+			if (n == NULL)
+				return -1;
+			if (nt_insert(self, n, rev) == -1)
+				return -1;
+		}
+		self->ntrev = rev;
+	}
+	return 0;
+}
+
 static int nt_partialmatch(indexObject *self, const char *node,
 			   Py_ssize_t nodelen)
 {
-	int rev;
-
 	if (nt_init(self) == -1)
 		return -3;
-
-	if (self->ntrev > 0) {
-		/* ensure that the radix tree is fully populated */
-		for (rev = self->ntrev - 1; rev >= 0; rev--) {
-			const char *n = index_node_existing(self, rev);
-			if (n == NULL)
-				return -3;
-			if (nt_insert(self, n, rev) == -1)
-				return -3;
-		}
-		self->ntrev = rev;
-	}
+	if (nt_populate(self) == -1)
+	  return -3;
 
 	return nt_find(self, node, nodelen, 1);
 }