Mercurial > hg
changeset 16615:96fa9dd1db38
parsers: factor out radix tree initialization
author | Bryan O'Sullivan <bryano@fb.com> |
---|---|
date | Tue, 08 May 2012 14:48:39 -0700 |
parents | 1d800eb9ba52 |
children | 8f79aabd96f6 |
files | mercurial/parsers.c |
diffstat | 1 files changed, 20 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/parsers.c Tue May 08 14:46:06 2012 -0700 +++ b/mercurial/parsers.c Tue May 08 14:48:39 2012 -0700 @@ -636,6 +636,24 @@ return -1; } +static int nt_init(indexObject *self) +{ + if (self->nt == NULL) { + self->ntcapacity = self->raw_length < 4 + ? 4 : self->raw_length / 2; + self->nt = calloc(self->ntcapacity, sizeof(nodetree)); + if (self->nt == NULL) { + PyErr_NoMemory(); + return -1; + } + self->ntlength = 1; + self->ntrev = (int)index_length(self) - 1; + self->ntlookups = 1; + self->ntmisses = 0; + } + return 0; +} + /* * Return values: * @@ -653,19 +671,8 @@ if (rev >= -1) return rev; - if (self->nt == NULL) { - self->ntcapacity = self->raw_length < 4 - ? 4 : self->raw_length / 2; - self->nt = calloc(self->ntcapacity, sizeof(nodetree)); - if (self->nt == NULL) { - PyErr_SetString(PyExc_MemoryError, "out of memory"); - return -3; - } - self->ntlength = 1; - self->ntrev = (int)index_length(self) - 1; - self->ntlookups = 1; - self->ntmisses = 0; - } + if (nt_init(self) == -1) + return -3; /* * For the first handful of lookups, we scan the entire index,