# HG changeset patch # User Bryan O'Sullivan # Date 2012-05-08 21:48:39 # Node ID 96fa9dd1db38fe6b241554423d42fd93d1a4be6b # Parent 1d800eb9ba5287344cf8e1d3723720c4491a17e4 parsers: factor out radix tree initialization diff --git a/mercurial/parsers.c b/mercurial/parsers.c --- a/mercurial/parsers.c +++ b/mercurial/parsers.c @@ -636,6 +636,24 @@ static int nt_insert(indexObject *self, 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 @@ static int index_find_node(indexObject * 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,