@@ -117,8 +117,16 @@ void register_string_constants(INIT_FUNC_ARGS)
117
117
118
118
int php_tag_find (char * tag , size_t len , const char * set );
119
119
120
+ #ifdef PHP_WIN32
121
+ # define SET_ALIGNED (alignment , decl ) __declspec(align(alignment)) decl
122
+ #elif HAVE_ATTRIBUTE_ALIGNED
123
+ # define SET_ALIGNED (alignment , decl ) decl __attribute__ ((__aligned__ (alignment)))
124
+ #else
125
+ # define SET_ALIGNED (alignment , decl ) decl
126
+ #endif
127
+
120
128
/* this is read-only, so it's ok */
121
- static char hexconvtab [] = "0123456789abcdef" ;
129
+ SET_ALIGNED ( 16 , static char hexconvtab [ ]) = "0123456789abcdef" ;
122
130
123
131
/* localeconv mutex */
124
132
#ifdef ZTS
@@ -155,25 +163,22 @@ static zend_string *php_hex2bin(const unsigned char *old, const size_t oldlen)
155
163
156
164
for (i = j = 0 ; i < target_length ; i ++ ) {
157
165
unsigned char c = old [j ++ ];
166
+ unsigned char l = c & ~0x20 ;
167
+ int is_letter = ((unsigned int ) ((l - 'A' ) ^ (l - 'F' - 1 ))) >> (8 * sizeof (unsigned int ) - 1 );
158
168
unsigned char d ;
159
169
160
- if (c >= '0' && c <= '9' ) {
161
- d = (c - '0' ) << 4 ;
162
- } else if (c >= 'a' && c <= 'f' ) {
163
- d = (c - 'a' + 10 ) << 4 ;
164
- } else if (c >= 'A' && c <= 'F' ) {
165
- d = (c - 'A' + 10 ) << 4 ;
170
+ /* basically (c >= '0' && c <= '9') || (l >= 'A' && l <= 'F') */
171
+ if (EXPECTED ((((c ^ '0' ) - 10 ) >> (8 * sizeof (unsigned int ) - 1 )) | is_letter )) {
172
+ d = (l - 0x10 - 0x27 * is_letter ) << 4 ;
166
173
} else {
167
174
zend_string_free (str );
168
175
return NULL ;
169
176
}
170
177
c = old [j ++ ];
171
- if (c >= '0' && c <= '9' ) {
172
- d |= c - '0' ;
173
- } else if (c >= 'a' && c <= 'f' ) {
174
- d |= c - 'a' + 10 ;
175
- } else if (c >= 'A' && c <= 'F' ) {
176
- d |= c - 'A' + 10 ;
178
+ l = c & ~0x20 ;
179
+ is_letter = ((unsigned int ) ((l - 'A' ) ^ (l - 'F' - 1 ))) >> (8 * sizeof (unsigned int ) - 1 );
180
+ if (EXPECTED ((((c ^ '0' ) - 10 ) >> (8 * sizeof (unsigned int ) - 1 )) | is_letter )) {
181
+ d |= l - 0x10 - 0x27 * is_letter ;
177
182
} else {
178
183
zend_string_free (str );
179
184
return NULL ;
0 commit comments