@matheusbsbs / matheus-bagliano / commits / e49521b56d
Fork 0

Make hexval() available to others.

builtin-mailinfo.c has its own hexval implementaiton but it can share the table-lookup one recently implemented in sha1_file.c Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Sep 20, 2006 at 16:04 UTC e49521b56d8715f46b93ee6bc95f7de9c6858365
3 files changed +40 -49
builtin-mailinfo.c
-11
@@ -451,17 +451,6 @@ static int read_one_header_line(char *line, int sz, FILE *in)
451 return ofs;
452 }
453
454 -static unsigned hexval(int c)
455 -{
456 - if (c >= '0' && c <= '9')
457 - return c - '0';
458 - if (c >= 'a' && c <= 'f')
459 - return c - 'a' + 10;
460 - if (c >= 'A' && c <= 'F')
461 - return c - 'A' + 10;
462 - return ~0;
463 -}
464 -
454 static int decode_q_segment(char *in, char *ot, char *ep, int rfc2047)
455 {
456 int c;
cache.h
+6
@@ -278,6 +278,12 @@ enum object_type {
278 OBJ_BAD,
279 };
280
281 +extern signed char hexval_table[256];
282 +static inline unsigned int hexval(unsigned int c)
283 +{
284 + return hexval_table[c];
285 +}
286 +
287 /* Convert to/from hex/sha1 representation */
288 #define MINIMUM_ABBREV 4
289 #define DEFAULT_ABBREV 7
sha1_file.c
+34 -38
@@ -26,44 +26,40 @@ const unsigned char null_sha1[20];
26
27 static unsigned int sha1_file_open_flag = O_NOATIME;
28
29 -static inline unsigned int hexval(unsigned int c)
30 -{
31 - static signed char val[256] = {
32 - -1, -1, -1, -1, -1, -1, -1, -1, /* 00-07 */
33 - -1, -1, -1, -1, -1, -1, -1, -1, /* 08-0f */
34 - -1, -1, -1, -1, -1, -1, -1, -1, /* 10-17 */
35 - -1, -1, -1, -1, -1, -1, -1, -1, /* 18-1f */
36 - -1, -1, -1, -1, -1, -1, -1, -1, /* 20-27 */
37 - -1, -1, -1, -1, -1, -1, -1, -1, /* 28-2f */
38 - 0, 1, 2, 3, 4, 5, 6, 7, /* 30-37 */
39 - 8, 9, -1, -1, -1, -1, -1, -1, /* 38-3f */
40 - -1, 10, 11, 12, 13, 14, 15, -1, /* 40-47 */
41 - -1, -1, -1, -1, -1, -1, -1, -1, /* 48-4f */
42 - -1, -1, -1, -1, -1, -1, -1, -1, /* 50-57 */
43 - -1, -1, -1, -1, -1, -1, -1, -1, /* 58-5f */
44 - -1, 10, 11, 12, 13, 14, 15, -1, /* 60-67 */
45 - -1, -1, -1, -1, -1, -1, -1, -1, /* 68-67 */
46 - -1, -1, -1, -1, -1, -1, -1, -1, /* 70-77 */
47 - -1, -1, -1, -1, -1, -1, -1, -1, /* 78-7f */
48 - -1, -1, -1, -1, -1, -1, -1, -1, /* 80-87 */
49 - -1, -1, -1, -1, -1, -1, -1, -1, /* 88-8f */
50 - -1, -1, -1, -1, -1, -1, -1, -1, /* 90-97 */
51 - -1, -1, -1, -1, -1, -1, -1, -1, /* 98-9f */
52 - -1, -1, -1, -1, -1, -1, -1, -1, /* a0-a7 */
53 - -1, -1, -1, -1, -1, -1, -1, -1, /* a8-af */
54 - -1, -1, -1, -1, -1, -1, -1, -1, /* b0-b7 */
55 - -1, -1, -1, -1, -1, -1, -1, -1, /* b8-bf */
56 - -1, -1, -1, -1, -1, -1, -1, -1, /* c0-c7 */
57 - -1, -1, -1, -1, -1, -1, -1, -1, /* c8-cf */
58 - -1, -1, -1, -1, -1, -1, -1, -1, /* d0-d7 */
59 - -1, -1, -1, -1, -1, -1, -1, -1, /* d8-df */
60 - -1, -1, -1, -1, -1, -1, -1, -1, /* e0-e7 */
61 - -1, -1, -1, -1, -1, -1, -1, -1, /* e8-ef */
62 - -1, -1, -1, -1, -1, -1, -1, -1, /* f0-f7 */
63 - -1, -1, -1, -1, -1, -1, -1, -1, /* f8-ff */
64 - };
65 - return val[c];
66 -}
29 +signed char hexval_table[256] = {
30 + -1, -1, -1, -1, -1, -1, -1, -1, /* 00-07 */
31 + -1, -1, -1, -1, -1, -1, -1, -1, /* 08-0f */
32 + -1, -1, -1, -1, -1, -1, -1, -1, /* 10-17 */
33 + -1, -1, -1, -1, -1, -1, -1, -1, /* 18-1f */
34 + -1, -1, -1, -1, -1, -1, -1, -1, /* 20-27 */
35 + -1, -1, -1, -1, -1, -1, -1, -1, /* 28-2f */
36 + 0, 1, 2, 3, 4, 5, 6, 7, /* 30-37 */
37 + 8, 9, -1, -1, -1, -1, -1, -1, /* 38-3f */
38 + -1, 10, 11, 12, 13, 14, 15, -1, /* 40-47 */
39 + -1, -1, -1, -1, -1, -1, -1, -1, /* 48-4f */
40 + -1, -1, -1, -1, -1, -1, -1, -1, /* 50-57 */
41 + -1, -1, -1, -1, -1, -1, -1, -1, /* 58-5f */
42 + -1, 10, 11, 12, 13, 14, 15, -1, /* 60-67 */
43 + -1, -1, -1, -1, -1, -1, -1, -1, /* 68-67 */
44 + -1, -1, -1, -1, -1, -1, -1, -1, /* 70-77 */
45 + -1, -1, -1, -1, -1, -1, -1, -1, /* 78-7f */
46 + -1, -1, -1, -1, -1, -1, -1, -1, /* 80-87 */
47 + -1, -1, -1, -1, -1, -1, -1, -1, /* 88-8f */
48 + -1, -1, -1, -1, -1, -1, -1, -1, /* 90-97 */
49 + -1, -1, -1, -1, -1, -1, -1, -1, /* 98-9f */
50 + -1, -1, -1, -1, -1, -1, -1, -1, /* a0-a7 */
51 + -1, -1, -1, -1, -1, -1, -1, -1, /* a8-af */
52 + -1, -1, -1, -1, -1, -1, -1, -1, /* b0-b7 */
53 + -1, -1, -1, -1, -1, -1, -1, -1, /* b8-bf */
54 + -1, -1, -1, -1, -1, -1, -1, -1, /* c0-c7 */
55 + -1, -1, -1, -1, -1, -1, -1, -1, /* c8-cf */
56 + -1, -1, -1, -1, -1, -1, -1, -1, /* d0-d7 */
57 + -1, -1, -1, -1, -1, -1, -1, -1, /* d8-df */
58 + -1, -1, -1, -1, -1, -1, -1, -1, /* e0-e7 */
59 + -1, -1, -1, -1, -1, -1, -1, -1, /* e8-ef */
60 + -1, -1, -1, -1, -1, -1, -1, -1, /* f0-f7 */
61 + -1, -1, -1, -1, -1, -1, -1, -1, /* f8-ff */
62 +};
63
64 int get_sha1_hex(const char *hex, unsigned char *sha1)
65 {