Patchwork [7,of,8,faster-obsmarkers] getbeint16: write in terms of getbeuint16

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

Comments

Augie Fackler - Feb. 2, 2015, 4:01 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1421791151 28800
#      Tue Jan 20 13:59:11 2015 -0800
# Branch stable
# Node ID 6969fa0e9ab6ae8c4642ea1f90e9374e4e5a9b28
# Parent  22d73e82c50d1126c7640d960cf74fcf328add6c
getbeint16: write in terms of getbeuint16
Augie Fackler - Feb. 2, 2015, 4:12 p.m.
Similarly, I'm slightly fuzzy on how this cast behaves. If it's legal,
please consider folding it into the patch that introduces getbeint16.

On Mon, Feb 2, 2015 at 11:01 AM, Augie Fackler <raf@durin42.com> wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1421791151 28800
> #      Tue Jan 20 13:59:11 2015 -0800
> # Branch stable
> # Node ID 6969fa0e9ab6ae8c4642ea1f90e9374e4e5a9b28
> # Parent  22d73e82c50d1126c7640d960cf74fcf328add6c
> getbeint16: write in terms of getbeuint16
>
> diff --git a/mercurial/util.h b/mercurial/util.h
> --- a/mercurial/util.h
> +++ b/mercurial/util.h
> @@ -172,7 +172,7 @@ static inline uint32_t getbe32(const cha
>                 (d[3]));
>  }
>
> -static inline int16_t getbeint16(const char *c)
> +static inline uint16_t getbeuint16(const char *c)
>  {
>         const unsigned char *d = (const unsigned char *)c;
>
> @@ -180,12 +180,9 @@ static inline int16_t getbeint16(const c
>                 (d[1]));
>  }
>
> -static inline uint16_t getbeuint16(const char *c)
> +static inline int16_t getbeint16(const char *c)
>  {
> -       const unsigned char *d = (const unsigned char *)c;
> -
> -       return ((d[0] << 8) |
> -               (d[1]));
> +       return (int16_t)getbeuint16(c);
>  }
>
>  static inline void putbe32(uint32_t x, char *c)
> _______________________________________________
> 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,7 +172,7 @@  static inline uint32_t getbe32(const cha
 		(d[3]));
 }
 
-static inline int16_t getbeint16(const char *c)
+static inline uint16_t getbeuint16(const char *c)
 {
 	const unsigned char *d = (const unsigned char *)c;
 
@@ -180,12 +180,9 @@  static inline int16_t getbeint16(const c
 		(d[1]));
 }
 
-static inline uint16_t getbeuint16(const char *c)
+static inline int16_t getbeint16(const char *c)
 {
-	const unsigned char *d = (const unsigned char *)c;
-
-	return ((d[0] << 8) |
-		(d[1]));
+	return (int16_t)getbeuint16(c);
 }
 
 static inline void putbe32(uint32_t x, char *c)