[PATCH 4 of 6 RFC] radixlink: add pure C implementation for radixlink read operation

Augie Fackler raf at durin42.com
Wed May 24 17:21:48 EDT 2017


On Sun, May 21, 2017 at 06:31:11PM -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1495404843 25200
> #      Sun May 21 15:14:03 2017 -0700
> # Node ID 23ea47ebaf6e9f0d711b90d7677cf4628c8761c6
> # Parent  929ea30d953466dc04f0e5d8ca8cd9ed06ca2310
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r 23ea47ebaf6e
> radixlink: add pure C implementation for radixlink read operation
>
> diff --git a/mercurial/cext/radixlink.c b/mercurial/cext/radixlink.c
> new file mode 100644
> --- /dev/null
> +++ b/mercurial/cext/radixlink.c
> @@ -0,0 +1,122 @@
> +/* radixlink.c - on-disk radixtree index pointing to linked list data
> + *
> + * Copyright 2017 Facebook, Inc.
> + *
> + * This software may be used and distributed according to the terms of the
> + * GNU General Public License version 2 or any later version. */
> +
> +#include <stdlib.h>
> +#include "radixlink.h"
> +
> +/* safe read utilities (assuming "return -1" is error reporting) */

nit: could these be static inline and let the compiler do the work of
making it efficient? I'd kind of rather that than macros...

> +#define read8(dest, rlbuf, offset) \
> +	if (rlbuf->size < (offset) + 1) return -1; \
> +	else dest = rlbuf->buf[(offset)];
> +#define read16(dest, rlbuf, offset) \
> +	if (rlbuf->size < (offset) + 2) return -1; \
> +	else dest = getbeuint16((const char *)(rlbuf->buf + (offset)));
> +#define read32(dest, rlbuf, offset) \
> +	if (rlbuf->size < (offset) + 4) return -1; \
> +	else dest = getbe32((const char *)(rlbuf->buf + (offset)));
> +
> +#define getb16(dest, key, boffset) { \
> +	uint8_t _v = key[(boffset) / 2]; \
> +	dest = ((boffset) & 1) ? (_v & 0xf) : (_v >> 4); }
> +
> +static const uint8_t RADIX_TYPE = 0;
> +static const uint8_t LEAF_TYPE = 1;

[...]


More information about the Mercurial-devel mailing list