changeset 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
files mercurial/cext/revlog.c
diffstat 1 files changed, 4 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/revlog.c	Wed Aug 08 23:41:50 2018 -0700
+++ b/mercurial/cext/revlog.c	Thu Aug 09 00:09:03 2018 -0700
@@ -1065,7 +1065,9 @@
 static int nt_init(nodetree *self, indexObject *index, unsigned capacity)
 {
 	self->index = index;
-	self->capacity = capacity;
+	/* The input capacity is in terms of revisions, while the field is in
+	 * terms of nodetree nodes. */
+	self->capacity = (capacity < 4 ? 4 : capacity / 2);
 	self->depth = 0;
 	self->splits = 0;
 	if ((size_t)self->capacity > INT_MAX / sizeof(nodetreenode)) {
@@ -1141,8 +1143,7 @@
 			PyErr_NoMemory();
 			return -1;
 		}
-		unsigned capacity = (self->raw_length < 4 ? 4 : (int)self->raw_length / 2);
-		if (nt_init(self->nt, self, capacity) == -1) {
+		if (nt_init(self->nt, self, self->raw_length) == -1) {
 			PyMem_Free(self->nt);
 			self->nt = NULL;
 			return -1;