[PATCH 05 of 10 V2] sparse-revlog: add a `index_get_length` function in C

Boris Feld boris.feld at octobus.net
Thu Nov 15 05:38:43 EST 2018


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1541785378 -3600
#      Fri Nov 09 18:42:58 2018 +0100
# Node ID 7d80481596f245d7f299c8a473907a22f2f3c947
# Parent  f78fcec5ba387ff17ace7ca99294a90c7ba92387
# EXP-Topic sparse-perf
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 7d80481596f2
sparse-revlog: add a `index_get_length` function in C

We are about to implement a native version of `slicechunktodensity`. For
clarity, we introduce the helper functions first. This new function provides
an efficient way to retrieve some of the information needed by
`slicechunktodensity`.

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -206,6 +206,18 @@ static inline uint64_t index_get_start(i
 	return offset;
 }
 
+static inline int index_get_length(indexObject *self, Py_ssize_t rev)
+{
+	if (rev >= self->length) {
+		PyObject *tuple =
+		    PyList_GET_ITEM(self->added, rev - self->length);
+		return (int)PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, 1));
+	} else {
+		const char *data = index_deref(self, rev);
+		return getbe32(data + 8);
+	}
+}
+
 /*
  * RevlogNG format (all in big endian, data may be inlined):
  *    6 bytes: offset


More information about the Mercurial-devel mailing list