Submitter | Boris Feld |
---|---|
Date | Nov. 22, 2018, 6:08 p.m. |
Message ID | <cc7132133f0e391b5398.1542910086@localhost.localdomain> |
Download | mbox | patch |
Permalink | /patch/36719/ |
State | Accepted |
Headers | show |
Comments
On Thu, 22 Nov 2018 19:08:06 +0100, Boris Feld wrote: > # HG changeset patch > # User Boris Feld <boris.feld@octobus.net> > # Date 1541785523 -3600 > # Fri Nov 09 18:45:23 2018 +0100 > # Node ID cc7132133f0e391b53985b4d08072304032fd444 > # Parent 4ad3891a07ed83cda837db8d0cbe285ebb377869 > # EXP-Topic sparse-perf > # Available At https://bitbucket.org/octobus/mercurial-devel/ > # hg pull https://bitbucket.org/octobus/mercurial-devel/ -r cc7132133f0e > 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. > > diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c > --- a/mercurial/cext/revlog.c > +++ b/mercurial/cext/revlog.c > @@ -1077,6 +1077,24 @@ index_segment_span(indexObject *self, Py > return (end_offset - start_offset) + (int64_t)end_size; > } > > +/* returns revs[startidx:endidx] without empty trailing revs */ The function doc isn't correct. Can you update as a follow up? > +static Py_ssize_t trim_endidx(indexObject *self, Py_ssize_t *revs, > + Py_ssize_t startidx, Py_ssize_t endidx) I've changed *revs to const * to make it clear revs isn't an output variable. > +{ > + 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; > +}
Patch
diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c --- a/mercurial/cext/revlog.c +++ b/mercurial/cext/revlog.c @@ -1077,6 +1077,24 @@ index_segment_span(indexObject *self, Py 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, 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];