##// END OF EJS Templates
parsers: factor out radix tree initialization
Bryan O'Sullivan -
r16615:96fa9dd1 default
parent child Browse files
Show More
@@ -636,6 +636,24 b' static int nt_insert(indexObject *self, '
636 return -1;
636 return -1;
637 }
637 }
638
638
639 static int nt_init(indexObject *self)
640 {
641 if (self->nt == NULL) {
642 self->ntcapacity = self->raw_length < 4
643 ? 4 : self->raw_length / 2;
644 self->nt = calloc(self->ntcapacity, sizeof(nodetree));
645 if (self->nt == NULL) {
646 PyErr_NoMemory();
647 return -1;
648 }
649 self->ntlength = 1;
650 self->ntrev = (int)index_length(self) - 1;
651 self->ntlookups = 1;
652 self->ntmisses = 0;
653 }
654 return 0;
655 }
656
639 /*
657 /*
640 * Return values:
658 * Return values:
641 *
659 *
@@ -653,19 +671,8 b' static int index_find_node(indexObject *'
653 if (rev >= -1)
671 if (rev >= -1)
654 return rev;
672 return rev;
655
673
656 if (self->nt == NULL) {
674 if (nt_init(self) == -1)
657 self->ntcapacity = self->raw_length < 4
658 ? 4 : self->raw_length / 2;
659 self->nt = calloc(self->ntcapacity, sizeof(nodetree));
660 if (self->nt == NULL) {
661 PyErr_SetString(PyExc_MemoryError, "out of memory");
662 return -3;
675 return -3;
663 }
664 self->ntlength = 1;
665 self->ntrev = (int)index_length(self) - 1;
666 self->ntlookups = 1;
667 self->ntmisses = 0;
668 }
669
676
670 /*
677 /*
671 * For the first handful of lookups, we scan the entire index,
678 * For the first handful of lookups, we scan the entire index,
General Comments 0
You need to be logged in to leave comments. Login now