Patchwork [2,of,8,faster-obsmarkers] util: add getbe{u, }int16 utility methods

login
register
mail settings
Submitter Augie Fackler
Date Feb. 2, 2015, 4:01 p.m.
Message ID <20ac130001c176b0fbc2.1422892883@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/7595/
State Superseded
Headers show

Comments

Augie Fackler - Feb. 2, 2015, 4:01 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1421780997 18000
#      Tue Jan 20 14:09:57 2015 -0500
# Branch stable
# Node ID 20ac130001c176b0fbc2c99d9fe3741df3b71bca
# Parent  a981174fee88c527794466a487ff07a46c329512
util: add getbe{u,}int16 utility methods
Martin von Zweigbergk - Feb. 2, 2015, 6:26 p.m.
On Mon Feb 02 2015 at 8:03:12 AM Augie Fackler <raf@durin42.com> wrote:

> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1421780997 18000
> #      Tue Jan 20 14:09:57 2015 -0500
> # Branch stable
> # Node ID 20ac130001c176b0fbc2c99d9fe3741df3b71bca
> # Parent  a981174fee88c527794466a487ff07a46c329512
> util: add getbe{u,}int16 utility methods
>
> diff --git a/mercurial/util.h b/mercurial/util.h
> --- a/mercurial/util.h
> +++ b/mercurial/util.h
> @@ -172,6 +172,22 @@ static inline uint32_t getbe32(const cha
>                 (d[3]));
>  }
>
> +static inline int16_t getbeint16(const char *c)
> +{
> +       const unsigned char *d = (const unsigned char *)c;
> +
> +       return ((d[0] << 8) |
> +               (d[1]));
>

Nit: For numbers with more bits, I can see why this formatting makes sense,
but here I find it more distracting that a single line would have been.


> +}
> +
> +static inline uint16_t getbeuint16(const char *c)
> +{
> +       const unsigned char *d = (const unsigned char *)c;
> +
> +       return ((d[0] << 8) |
> +               (d[1]));
> +}
> +
>  static inline void putbe32(uint32_t x, char *c)
>  {
>         c[0] = (x >> 24) & 0xff;
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/util.h b/mercurial/util.h
--- a/mercurial/util.h
+++ b/mercurial/util.h
@@ -172,6 +172,22 @@  static inline uint32_t getbe32(const cha
 		(d[3]));
 }
 
+static inline int16_t getbeint16(const char *c)
+{
+	const unsigned char *d = (const unsigned char *)c;
+
+	return ((d[0] << 8) |
+		(d[1]));
+}
+
+static inline uint16_t getbeuint16(const char *c)
+{
+	const unsigned char *d = (const unsigned char *)c;
+
+	return ((d[0] << 8) |
+		(d[1]));
+}
+
 static inline void putbe32(uint32_t x, char *c)
 {
 	c[0] = (x >> 24) & 0xff;