# HG changeset patch # User Martin von Zweigbergk # Date 1525497448 25200 # Node ID 9c6d1d41b3e61117aeb920c3b5669205787f7b15 # Parent 7cd1e1adc4718c9fc83dccaea5ce03b8aab40c22 revlog: extract function for fully populating the radix tree This code is currently used for partialmatch(), but I want to reuse it when I implement shortest() in native code. Differential Revision: https://phab.mercurial-scm.org/D3497 diff -r 7cd1e1adc471 -r 9c6d1d41b3e6 mercurial/cext/revlog.c --- a/mercurial/cext/revlog.c Fri Apr 27 12:07:57 2018 -0400 +++ b/mercurial/cext/revlog.c Fri May 04 22:17:28 2018 -0700 @@ -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); }