Mercurial > hg
comparison mercurial/cext/revlog.c @ 38915:fff675dfb80b
index: pass only nodetree to nt_new()
The function now only depends on the nodetree, not the index.
Differential Revision: https://phab.mercurial-scm.org/D4111
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 16 May 2018 15:14:37 -0700 |
parents | f28e64bbdd29 |
children | 05c1f5f49ebb |
comparison
equal
deleted
inserted
replaced
38914:f28e64bbdd29 | 38915:fff675dfb80b |
---|---|
1013 } | 1013 } |
1014 /* multiple matches against an ambiguous prefix */ | 1014 /* multiple matches against an ambiguous prefix */ |
1015 return -4; | 1015 return -4; |
1016 } | 1016 } |
1017 | 1017 |
1018 static int nt_new(indexObject *self) | 1018 static int nt_new(nodetree *self) |
1019 { | 1019 { |
1020 nodetree *nt = self->nt; | 1020 if (self->length == self->capacity) { |
1021 if (nt->length == nt->capacity) { | 1021 if (self->capacity >= INT_MAX / (sizeof(nodetreenode) * 2)) { |
1022 if (nt->capacity >= INT_MAX / (sizeof(nodetreenode) * 2)) { | |
1023 PyErr_SetString(PyExc_MemoryError, | 1022 PyErr_SetString(PyExc_MemoryError, |
1024 "overflow in nt_new"); | 1023 "overflow in nt_new"); |
1025 return -1; | 1024 return -1; |
1026 } | 1025 } |
1027 nt->capacity *= 2; | 1026 self->capacity *= 2; |
1028 nt->nodes = realloc(nt->nodes, | 1027 self->nodes = realloc(self->nodes, |
1029 nt->capacity * sizeof(nodetreenode)); | 1028 self->capacity * sizeof(nodetreenode)); |
1030 if (nt->nodes == NULL) { | 1029 if (self->nodes == NULL) { |
1031 PyErr_SetString(PyExc_MemoryError, "out of memory"); | 1030 PyErr_SetString(PyExc_MemoryError, "out of memory"); |
1032 return -1; | 1031 return -1; |
1033 } | 1032 } |
1034 memset(&nt->nodes[nt->length], 0, | 1033 memset(&self->nodes[self->length], 0, |
1035 sizeof(nodetreenode) * (nt->capacity - nt->length)); | 1034 sizeof(nodetreenode) * (self->capacity - self->length)); |
1036 } | 1035 } |
1037 return nt->length++; | 1036 return self->length++; |
1038 } | 1037 } |
1039 | 1038 |
1040 static int nt_insert(indexObject *self, const char *node, int rev) | 1039 static int nt_insert(indexObject *self, const char *node, int rev) |
1041 { | 1040 { |
1042 int level = 0; | 1041 int level = 0; |
1062 return -1; | 1061 return -1; |
1063 if (!memcmp(oldnode, node, 20)) { | 1062 if (!memcmp(oldnode, node, 20)) { |
1064 n->children[k] = -rev - 2; | 1063 n->children[k] = -rev - 2; |
1065 return 0; | 1064 return 0; |
1066 } | 1065 } |
1067 noff = nt_new(self); | 1066 noff = nt_new(self->nt); |
1068 if (noff == -1) | 1067 if (noff == -1) |
1069 return -1; | 1068 return -1; |
1070 /* self->nt->nodes may have been changed by realloc */ | 1069 /* self->nt->nodes may have been changed by realloc */ |
1071 self->nt->nodes[off].children[k] = noff; | 1070 self->nt->nodes[off].children[k] = noff; |
1072 off = noff; | 1071 off = noff; |