52 expects (= 2/3), so as soon as we cross the threshold we'll resize |
45 expects (= 2/3), so as soon as we cross the threshold we'll resize |
53 anyway. So create a dictionary that's at least 3/2 the size. */ |
46 anyway. So create a dictionary that's at least 3/2 the size. */ |
54 return _PyDict_NewPresized(((1 + expected_size) / 2) * 3); |
47 return _PyDict_NewPresized(((1 + expected_size) / 2) * 3); |
55 } |
48 } |
56 |
49 |
57 static const int8_t hextable[256] = { |
|
58 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
59 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
60 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
61 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 0-9 */ |
|
62 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* A-F */ |
|
63 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
64 -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* a-f */ |
|
65 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
66 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
67 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
68 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
69 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
70 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
71 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
72 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
|
73 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 |
|
74 }; |
|
75 |
|
76 static inline int hexdigit(const char *p, Py_ssize_t off) |
|
77 { |
|
78 int8_t val = hextable[(unsigned char)p[off]]; |
|
79 |
|
80 if (val >= 0) { |
|
81 return val; |
|
82 } |
|
83 |
|
84 PyErr_SetString(PyExc_ValueError, "input contains non-hex character"); |
|
85 return 0; |
|
86 } |
|
87 |
|
88 #endif /* _HG_UTIL_H_ */ |
50 #endif /* _HG_UTIL_H_ */ |