Show More
@@ -553,8 +553,10 b' static inline int nt_level(const char *n' | |||
|
553 | 553 | * -2: not found |
|
554 | 554 | * rest: valid rev |
|
555 | 555 | */ |
|
556 |
static int nt_find(indexObject *self, const char *node, Py_ssize_t nodelen |
|
|
556 | static int nt_find(indexObject *self, const char *node, Py_ssize_t nodelen, | |
|
557 | int hex) | |
|
557 | 558 | { |
|
559 | int (*getnybble)(const char *, Py_ssize_t) = hex ? hexdigit : nt_level; | |
|
558 | 560 | int level, maxlevel, off; |
|
559 | 561 | |
|
560 | 562 | if (nodelen == 20 && node[0] == '\0' && memcmp(node, nullid, 20) == 0) |
@@ -563,21 +565,28 b' static int nt_find(indexObject *self, co' | |||
|
563 | 565 | if (self->nt == NULL) |
|
564 | 566 | return -2; |
|
565 | 567 | |
|
568 | if (hex) | |
|
569 | maxlevel = nodelen > 40 ? 40 : nodelen; | |
|
570 | else | |
|
566 | 571 | maxlevel = nodelen > 20 ? 40 : ((int)nodelen * 2); |
|
567 | 572 | |
|
568 | 573 | for (level = off = 0; level < maxlevel; level++) { |
|
569 |
int k = |
|
|
574 | int k = getnybble(node, level); | |
|
570 | 575 | nodetree *n = &self->nt[off]; |
|
571 | 576 | int v = n->children[k]; |
|
572 | 577 | |
|
573 | 578 | if (v < 0) { |
|
574 | 579 | const char *n; |
|
580 | Py_ssize_t i; | |
|
581 | ||
|
575 | 582 | v = -v - 1; |
|
576 | 583 | n = index_node(self, v); |
|
577 | 584 | if (n == NULL) |
|
578 | 585 | return -2; |
|
579 | return memcmp(node, n, nodelen > 20 ? 20 : nodelen) | |
|
580 | ? -2 : v; | |
|
586 | for (i = level; i < maxlevel; i++) | |
|
587 | if (getnybble(node, i) != nt_level(n, i)) | |
|
588 | return -2; | |
|
589 | return v; | |
|
581 | 590 | } |
|
582 | 591 | if (v == 0) |
|
583 | 592 | return -2; |
@@ -679,7 +688,7 b' static int index_find_node(indexObject *' | |||
|
679 | 688 | int rev; |
|
680 | 689 | |
|
681 | 690 | self->ntlookups++; |
|
682 | rev = nt_find(self, node, nodelen); | |
|
691 | rev = nt_find(self, node, nodelen, 0); | |
|
683 | 692 | if (rev >= -1) |
|
684 | 693 | return rev; |
|
685 | 694 |
General Comments 0
You need to be logged in to leave comments.
Login now