[PATCH 3 of 7 V3] sparse-revlog: add a `index_segment_span` function in C

Boris Feld boris.feld at octobus.net
Mon Nov 19 09:42:15 UTC 2018


# HG changeset patch
# User Boris Feld <boris.feld at octobus.net>
# Date 1541785396 -3600
#      Fri Nov 09 18:43:16 2018 +0100
# Node ID 80a29996df2b2735d1134c7bd18d3e31e10884b3
# Parent  4e94d1562f28f424e68cf98f60bf8006dc3256ba
# EXP-Topic sparse-perf
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 80a29996df2b
sparse-revlog: add a `index_segment_span` 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
@@ -1030,6 +1030,25 @@ bail:
 	return NULL;
 }
 
+static inline bool index_segment_span(indexObject *self, Py_ssize_t start_rev,
+                                      Py_ssize_t end_rev, long *result)
+{
+	long tmp1;
+	long tmp2;
+	long tmp3;
+	if (!index_get_start(self, end_rev, &tmp1)) {
+		return 0;
+	}
+	if (!index_get_start(self, start_rev, &tmp2)) {
+		return 0;
+	}
+	if (!index_get_length(self, end_rev, &tmp3)) {
+		return 0;
+	}
+	*result = tmp1 - tmp2 + tmp3;
+	return 1;
+}
+
 static inline int nt_level(const char *node, Py_ssize_t level)
 {
 	int v = node[level >> 1];



More information about the Mercurial-devel mailing list