Patchwork [2,of,7,V3] sparse-revlog: add a `index_get_length` function in C

login
register
mail settings
Submitter Boris Feld
Date Nov. 19, 2018, 9:42 a.m.
Message ID <4e94d1562f28f424e68c.1542620534@localhost.localdomain>
Download mbox | patch
Permalink /patch/36640/
State Superseded
Headers show

Comments

Boris Feld - Nov. 19, 2018, 9:42 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1541785378 -3600
#      Fri Nov 09 18:42:58 2018 +0100
# Node ID 4e94d1562f28f424e68cf98f60bf8006dc3256ba
# Parent  e1ccc1643335b82f6c0bc94aed969590e15460b1
# EXP-Topic sparse-perf
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 4e94d1562f28
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`.

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -209,6 +209,22 @@  static inline bool index_get_start(index
 	return 1;
 }
 
+static inline bool index_get_length(indexObject *self, Py_ssize_t rev,
+                                    long *result)
+{
+	if (rev >= self->length) {
+		PyObject *tuple =
+		    PyList_GET_ITEM(self->added, rev - self->length);
+		if (!pylong_to_long(PyTuple_GET_ITEM(tuple, 1), result)) {
+			return 0;
+		};
+	} else {
+		const char *data = index_deref(self, rev);
+		*result = getbe32(data + 8);
+	}
+	return 1;
+}
+
 /*
  * RevlogNG format (all in big endian, data may be inlined):
  *    6 bytes: offset