changeset 40706:0650be877a37

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.
author Boris Feld <boris.feld@octobus.net>
date Fri, 09 Nov 2018 18:45:23 +0100
parents 4ec6a24029d2
children cc76ca9fca20
files mercurial/cext/revlog.c
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/revlog.c	Fri Nov 09 18:43:16 2018 +0100
+++ b/mercurial/cext/revlog.c	Fri Nov 09 18:45:23 2018 +0100
@@ -1078,6 +1078,24 @@
 	return (end_offset - start_offset) + (int64_t)end_size;
 }
 
+/* returns revs[startidx:endidx] without empty trailing revs */
+static Py_ssize_t trim_endidx(indexObject *self, const Py_ssize_t *revs,
+                              Py_ssize_t startidx, Py_ssize_t endidx)
+{
+	int length;
+	while (endidx > 1 && endidx > startidx) {
+		length = index_get_length(self, revs[endidx - 1]);
+		if (length < 0) {
+			return -1;
+		}
+		if (length != 0) {
+			break;
+		}
+		endidx -= 1;
+	}
+	return endidx;
+}
+
 static inline int nt_level(const char *node, Py_ssize_t level)
 {
 	int v = node[level >> 1];