Patchwork D4106: index: don't add 1 to length variables

login
register
mail settings
Submitter phabricator
Date Aug. 5, 2018, 1:04 p.m.
Message ID <4b935d0bdd86af86878c97d6bb1371d6@localhost.localdomain>
Download mbox | patch
Permalink /patch/33267/
State Not Applicable
Headers show

Comments

phabricator - Aug. 5, 2018, 1:04 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG0db50770f388: index: don&#039;t add 1 to length variables (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4106?vs=9909&id=9930

REVISION DETAIL
  https://phab.mercurial-scm.org/D4106

AFFECTED FILES
  mercurial/cext/revlog.c

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -155,15 +155,15 @@ 
 	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) {
 		Py_INCREF(nullentry);
 		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;
 		}