summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7faf068)
raw | patch | inline | side by side (parent: 7faf068)
author | Linus Torvalds <torvalds@linux-foundation.org> | |
Wed, 30 May 2007 17:32:19 +0000 (10:32 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 30 May 2007 22:01:37 +0000 (15:01 -0700) |
Make hexval_table[] "const". Also make sure that the accessor
function hexval() does not access the table with out-of-range
values by declaring its parameter "unsigned char", instead of
"unsigned int".
With this, gcc can just generate:
movzbl (%rdi), %eax
movsbl hexval_table(%rax),%edx
movzbl 1(%rdi), %eax
movsbl hexval_table(%rax),%eax
sall $4, %edx
orl %eax, %edx
for the code to generate a byte from two hex characters.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
function hexval() does not access the table with out-of-range
values by declaring its parameter "unsigned char", instead of
"unsigned int".
With this, gcc can just generate:
movzbl (%rdi), %eax
movsbl hexval_table(%rax),%edx
movzbl 1(%rdi), %eax
movsbl hexval_table(%rax),%eax
sall $4, %edx
orl %eax, %edx
for the code to generate a byte from two hex characters.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
cache.h | patch | blob | history | |
sha1_file.c | patch | blob | history |
index 7cedda684f81e5b7bc111c2322ef1f4b2fc97d90..bea8cad5b2b1f81199153f1755e81113b963655b 100644 (file)
--- a/cache.h
+++ b/cache.h
extern int has_pack_file(const unsigned char *sha1);
extern int has_pack_index(const unsigned char *sha1);
-extern signed char hexval_table[256];
-static inline unsigned int hexval(unsigned int c)
+extern const signed char hexval_table[256];
+static inline unsigned int hexval(unsigned char c)
{
return hexval_table[c];
}
diff --git a/sha1_file.c b/sha1_file.c
index 523417027a1785d4ab5b729d03ba794efc1bb4d4..ae9bd1fc2f9eca19b9708fef876faff16fd917fe 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
static unsigned int sha1_file_open_flag = O_NOATIME;
-signed char hexval_table[256] = {
+const signed char hexval_table[256] = {
-1, -1, -1, -1, -1, -1, -1, -1, /* 00-07 */
-1, -1, -1, -1, -1, -1, -1, -1, /* 08-0f */
-1, -1, -1, -1, -1, -1, -1, -1, /* 10-17 */