Patchwork [10,of,14] sparse-revlog: add a `index_segment_span` function in C

login
register
mail settings
Submitter Boris Feld
Date Nov. 12, 2018, 9:55 a.m.
Message ID <036a7425b869b5b8e3e7.1542016545@localhost.localdomain>
Download mbox | patch
Permalink /patch/36518/
State Accepted
Headers show

Comments

Boris Feld - Nov. 12, 2018, 9:55 a.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1541785396 -3600
#      Fri Nov 09 18:43:16 2018 +0100
# Node ID 036a7425b869b5b8e3e7f528ed6d992c48ebb52e
# Parent  ef4813b8b4911e5a73309b41f1f7496983792b64
# EXP-Topic sparse-perf
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 036a7425b869
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`.

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -1010,6 +1010,14 @@  bail:
 	return NULL;
 }
 
+static inline long index_segment_span(indexObject *self, Py_ssize_t start_rev,
+                                      Py_ssize_t end_rev)
+{
+	return (index_get_start(self, end_rev) -
+	        index_get_start(self, start_rev) +
+	        index_get_length(self, end_rev));
+}
+
 static inline int nt_level(const char *node, Py_ssize_t level)
 {
 	int v = node[level >> 1];