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

login
register
mail settings
Submitter Boris Feld
Date Nov. 19, 2018, 9:42 a.m.
Message ID <f9ce23d5d3aeec9a9e85.1542620536@localhost.localdomain>
Download mbox | patch
Permalink /patch/36642/
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 1541785523 -3600
#      Fri Nov 09 18:45:23 2018 +0100
# Node ID f9ce23d5d3aeec9a9e8589ec83d089b2df83da82
# Parent  80a29996df2b2735d1134c7bd18d3e31e10884b3
# EXP-Topic sparse-perf
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r f9ce23d5d3ae
sparse-revlog: add a `trim_endidx` function in C

We are about to implement a native version of `slicechunktodensity`. For
clarity, we introduce the helper functions first.

This function implement a subpart of the python function `_trimchunk` in
`mercurial/revlogutils/deltas.py`. Handling of actual Python objects is left
to the caller function.

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -1049,6 +1049,25 @@  static inline bool index_segment_span(in
 	return 1;
 }
 
+/* returns revs[startidx:endidx] without empty trailing revs */
+static bool trim_endidx(indexObject *self, Py_ssize_t *revs,
+                        Py_ssize_t startidx, Py_ssize_t endidx,
+                        Py_ssize_t *result)
+{
+	long length;
+	while (endidx > 1 && endidx > startidx) {
+		if (!index_get_length(self, revs[endidx - 1], &length)) {
+			return 0;
+		}
+		if (length != 0) {
+			break;
+		}
+		endidx -= 1;
+	}
+	*result = endidx;
+	return 1;
+}
+
 static inline int nt_level(const char *node, Py_ssize_t level)
 {
 	int v = node[level >> 1];