On Mon, 12 Nov 2018 10:55:46 +0100, Boris Feld wrote: > # HG changeset patch > # User Boris Feld <boris.f...@octobus.net> > # Date 1541785523 -3600 > # Fri Nov 09 18:45:23 2018 +0100 > # Node ID 0ea42453fa491793d1e145f5093b65e84cb65e97 > # Parent 036a7425b869b5b8e3e7f528ed6d992c48ebb52e > # EXP-Topic sparse-perf > # Available At https://bitbucket.org/octobus/mercurial-devel/ > # hg pull https://bitbucket.org/octobus/mercurial-devel/ -r > 0ea42453fa49 > sparse-revlog: add a `_trimchunk` function in C > > We are about to implement a native version of `slicechunktodensity`. For > clarity, we introduce the helper functions first. > > This function is a native implementation of the python function `_trimchunk` > in `mercurial/revlogutils/deltas.py`. > > diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c > --- a/mercurial/cext/revlog.c > +++ b/mercurial/cext/revlog.c > @@ -1018,6 +1018,29 @@ static inline long index_segment_span(in > index_get_length(self, end_rev)); > } > > +/* returns revs[startidx:endidx] without empty trailing revs */ > +static PyObject *_trimchunk(indexObject *self, PyObject *revs, long startidx, > + long endidx) > +{ > + while (endidx > 1 && endidx > startidx) { > + PyObject *rev = PyList_GET_ITEM(revs, endidx - 1); > + if (rev == NULL) { > + return NULL; > + }
PyList_GET_ITEM() should never fail. > + Py_ssize_t r = PyInt_AsLong(rev); > + if (r == -1 && PyErr_Occurred()) { > + return NULL; > + } > + if (index_get_length(self, r - 1) != 0) { > + break; > + } > + endidx -= 1; > + } > + PyObject *chunk = PyList_GetSlice(revs, startidx, endidx); > + Py_INCREF(chunk); > + return chunk; Excessive incref? PyList_GetSlice() is documented to return new reference. _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel