[PATCH 3 of 7 V4] sparse-revlog: add a `index_segment_span` function in C
Yuya Nishihara
yuya at tcha.org
Wed Nov 21 07:27:52 EST 2018
On Tue, 20 Nov 2018 21:44:34 +0100, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld at octobus.net>
> # Date 1541785396 -3600
> # Fri Nov 09 18:43:16 2018 +0100
> # Node ID 5bb00d137c14d311c91c7a4f32f58378cd9195ec
> # Parent 8863dc1f7d078827708d178bbbfee5519b4c9b0f
> # EXP-Topic sparse-perf
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> # hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 5bb00d137c14
> 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`.
>
> diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
> --- a/mercurial/cext/revlog.c
> +++ b/mercurial/cext/revlog.c
> @@ -1068,6 +1068,27 @@ bail:
> return NULL;
> }
>
> +static inline int64_t
> +index_segment_span(indexObject *self, Py_ssize_t start_rev, Py_ssize_t end_rev)
> +{
> + int64_t start_offset;
> + int64_t end_offset;
> + int end_size;
> + start_offset = index_get_start(self, start_rev);
> + if (start_offset < 0) {
> + return -1;
> + }
> + end_offset = index_get_start(self, end_rev);
> + if (end_offset < 0) {
> + return -1;
> + }
> + end_size = index_get_length(self, end_rev);
> + if (end_size < 0) {
> + return -1;
> + }
> + return (end_offset - start_offset) + (int64_t)end_size;
Nit: maybe raise error if end_offset - start_offset) + (int64_t)end_size < 0 ?
Other than that, the series looks good to me.
More information about the Mercurial-devel
mailing list