From c3d8da571f11b0146e60591c040da399d411c3f2 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 23 Jan 2014 16:26:42 -0500 Subject: read-cache: use get_be32 instead of hand-rolled ntoh_l Commit d60c49c (read-cache.c: allow unaligned mapping of the index file, 2012-04-03) introduced helpers to access unaligned data. However, we already have get_be32, which has a few advantages: 1. It's already written, so we avoid duplication. 2. It's probably faster, since it does the endian conversion and the alignment fix at the same time. 3. The get_be32 code is well-tested, having been in block-sha1 for a long time. By contrast, our custom helpers were probably almost never used, since the user needed to manually define a macro to enable them. We have to add a get_be16 implementation to the existing get_be32, but that is very simple to do. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- compat/bswap.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'compat/bswap.h') diff --git a/compat/bswap.h b/compat/bswap.h index 7d17953a65..120c6c1d37 100644 --- a/compat/bswap.h +++ b/compat/bswap.h @@ -136,11 +136,15 @@ static inline uint64_t git_bswap64(uint64_t x) defined(__powerpc__) || defined(__powerpc64__) || \ defined(__s390__) || defined(__s390x__) +#define get_be16(p) ntohs(*(unsigned short *)(p)) #define get_be32(p) ntohl(*(unsigned int *)(p)) #define put_be32(p, v) do { *(unsigned int *)(p) = htonl(v); } while (0) #else +#define get_be16(p) ( \ + (*((unsigned char *)(p) + 0) << 8) | \ + (*((unsigned char *)(p) + 1) << 0) ) #define get_be32(p) ( \ (*((unsigned char *)(p) + 0) << 24) | \ (*((unsigned char *)(p) + 1) << 16) | \ -- cgit v1.2.1