comparison mercurial/cext/revlog.c @ 39072:34eb999e29bf

index: make capacity argument to nt_init be measured in revisions The nodetree's internal capacity field is measures in nodetree nodes, which is not something the caller should have to know about. Differential Revision: https://phab.mercurial-scm.org/D4166
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 09 Aug 2018 00:09:03 -0700
parents 06ff7ea4f440
children beab6690f202
comparison
equal deleted inserted replaced
39071:06ff7ea4f440 39072:34eb999e29bf
1063 } 1063 }
1064 1064
1065 static int nt_init(nodetree *self, indexObject *index, unsigned capacity) 1065 static int nt_init(nodetree *self, indexObject *index, unsigned capacity)
1066 { 1066 {
1067 self->index = index; 1067 self->index = index;
1068 self->capacity = capacity; 1068 /* The input capacity is in terms of revisions, while the field is in
1069 * terms of nodetree nodes. */
1070 self->capacity = (capacity < 4 ? 4 : capacity / 2);
1069 self->depth = 0; 1071 self->depth = 0;
1070 self->splits = 0; 1072 self->splits = 0;
1071 if ((size_t)self->capacity > INT_MAX / sizeof(nodetreenode)) { 1073 if ((size_t)self->capacity > INT_MAX / sizeof(nodetreenode)) {
1072 PyErr_SetString(PyExc_ValueError, "overflow in init_nt"); 1074 PyErr_SetString(PyExc_ValueError, "overflow in init_nt");
1073 return -1; 1075 return -1;
1139 self->nt = PyMem_Malloc(sizeof(nodetree)); 1141 self->nt = PyMem_Malloc(sizeof(nodetree));
1140 if (self->nt == NULL) { 1142 if (self->nt == NULL) {
1141 PyErr_NoMemory(); 1143 PyErr_NoMemory();
1142 return -1; 1144 return -1;
1143 } 1145 }
1144 unsigned capacity = (self->raw_length < 4 ? 4 : (int)self->raw_length / 2); 1146 if (nt_init(self->nt, self, self->raw_length) == -1) {
1145 if (nt_init(self->nt, self, capacity) == -1) {
1146 PyMem_Free(self->nt); 1147 PyMem_Free(self->nt);
1147 self->nt = NULL; 1148 self->nt = NULL;
1148 return -1; 1149 return -1;
1149 } 1150 }
1150 if (nt_insert(self->nt, nullid, -1) == -1) { 1151 if (nt_insert(self->nt, nullid, -1) == -1) {