changeset 38868:0db50770f388

index: don't add 1 to length variables A lot of "+ 1" and "-1" were mechanically added to ease the transition in 781b2720d2ac (index: don't include nullid in len(), 2018-07-20). Let's clean it up now. Differential Revision: https://phab.mercurial-scm.org/D4106
author Martin von Zweigbergk <martinvonz@google.com>
date Sat, 04 Aug 2018 23:15:06 -0700
parents 4c0fd3f0a15d
children ad24b581e4d9
files mercurial/cext/revlog.c
diffstat 1 files changed, 9 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/revlog.c	Sat Aug 04 22:48:25 2018 -0700
+++ b/mercurial/cext/revlog.c	Sat Aug 04 23:15:06 2018 -0700
@@ -155,7 +155,7 @@
 	int comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2;
 	const char *c_node_id;
 	const char *data;
-	Py_ssize_t length = index_length(self) + 1;
+	Py_ssize_t length = index_length(self);
 	PyObject *entry;
 
 	if (pos == -1) {
@@ -163,7 +163,7 @@
 		return nullentry;
 	}
 
-	if (pos < 0 || pos >= length - 1) {
+	if (pos < 0 || pos >= length) {
 		PyErr_SetString(PyExc_IndexError, "revlog index out of range");
 		return NULL;
 	}
@@ -225,13 +225,13 @@
  */
 static const char *index_node(indexObject *self, Py_ssize_t pos)
 {
-	Py_ssize_t length = index_length(self) + 1;
+	Py_ssize_t length = index_length(self);
 	const char *data;
 
 	if (pos == -1)
 		return nullid;
 
-	if (pos >= length - 1)
+	if (pos >= length)
 		return NULL;
 
 	if (pos >= self->length - 1) {
@@ -285,7 +285,7 @@
 	if (node_check(PyTuple_GET_ITEM(obj, 7), &node) == -1)
 		return NULL;
 
-	len = index_length(self) + 1;
+	len = index_length(self);
 
 	if (self->added == NULL) {
 		self->added = PyList_New(0);
@@ -297,7 +297,7 @@
 		return NULL;
 
 	if (self->nt)
-		nt_insert(self, node, len - 1);
+		nt_insert(self, node, len);
 
 	Py_CLEAR(self->headrevs);
 	Py_RETURN_NONE;
@@ -844,7 +844,7 @@
 	int stoprev, iterrev, baserev = -1;
 	int stopped;
 	PyObject *chain = NULL, *result = NULL;
-	const Py_ssize_t length = index_length(self) + 1;
+	const Py_ssize_t length = index_length(self);
 
 	if (!PyArg_ParseTuple(args, "iOi", &rev, &stoparg, &generaldelta)) {
 		return NULL;
@@ -865,7 +865,7 @@
 		return NULL;
 	}
 
-	if (rev < 0 || rev >= length - 1) {
+	if (rev < 0 || rev >= length) {
 		PyErr_SetString(PyExc_ValueError, "revlog index out of range");
 		return NULL;
 	}
@@ -908,7 +908,7 @@
 			break;
 		}
 
-		if (iterrev >= length - 1) {
+		if (iterrev >= length) {
 			PyErr_SetString(PyExc_IndexError, "revision outside index");
 			return NULL;
 		}