Mercurial > hg-stable
changeset 37973:9c6d1d41b3e6
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
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 04 May 2018 22:17:28 -0700 |
parents | 7cd1e1adc471 |
children | 892592475094 |
files | mercurial/cext/revlog.c |
diffstat | 1 files changed, 20 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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); }