equal
deleted
inserted
replaced
634 } |
634 } |
635 |
635 |
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 * |
642 * -3: error (exception set) |
660 * -3: error (exception set) |
643 * -2: not found (no exception set) |
661 * -2: not found (no exception set) |
651 self->ntlookups++; |
669 self->ntlookups++; |
652 rev = nt_find(self, node, nodelen); |
670 rev = nt_find(self, node, nodelen); |
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 |
675 return -3; |
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; |
|
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, |
672 * and cache only the matching nodes. This optimizes for cases |
679 * and cache only the matching nodes. This optimizes for cases |
673 * like "hg tip", where only a few nodes are accessed. |
680 * like "hg tip", where only a few nodes are accessed. |