@@ -266,73 +266,6 @@ static ALWAYS_INLINE char *identify_http_method(struct lwan_request *request,
266
266
return NULL ;
267
267
}
268
268
269
- /* has_zero() routines stolen from the Bit Twiddling Hacks page */
270
- static ALWAYS_INLINE uint64_t has_zero64 (uint64_t v )
271
- {
272
- return (v - 0x0101010101010101ull ) & ~v & 0x8080808080808080ull ;
273
- }
274
-
275
- static ALWAYS_INLINE uint32_t has_zero32 (uint64_t v )
276
- {
277
- return (v - 0x01010101u ) & ~v & 0x80808080u ;
278
- }
279
-
280
- static char * find_pct_or_plus (const char * input )
281
- {
282
- const uint64_t mask_plus64 = '+' * 0x0101010101010101ull ;
283
- const uint64_t mask_pct64 = '%' * 0x0101010101010101ull ;
284
- const uint32_t mask_plus32 = '+' * 0x01010101u ;
285
- const uint32_t mask_pct32 = '%' * 0x01010101u ;
286
- char * str = (char * )input ;
287
-
288
- while (true) {
289
- uint64_t v = string_as_uint64 (str );
290
- uint64_t has_plus = has_zero64 (v ^ mask_plus64 );
291
- uint64_t has_pct = has_zero64 (v ^ mask_pct64 );
292
- uint64_t has_zero = has_zero64 (v );
293
- uint64_t m = LWAN_MAX (has_plus , has_pct );
294
-
295
- if (has_zero && LWAN_MAX (has_zero , m ) == has_zero ) {
296
- if (__builtin_ctzll (has_zero ) / 8 < 4 )
297
- goto check_small ;
298
- goto check_at_least_four ;
299
- }
300
-
301
- if (m ) {
302
- return str + __builtin_ctzll (m ) / 8 ;
303
- }
304
-
305
- str += 8 ;
306
- }
307
-
308
- check_at_least_four : {
309
- uint32_t v = string_as_uint32 (str );
310
- uint32_t has_plus = has_zero32 (v ^ mask_plus32 );
311
- uint32_t has_pct = has_zero32 (v ^ mask_pct32 );
312
- uint32_t has_zero = has_zero32 (v );
313
- uint32_t m = LWAN_MAX (has_plus , has_pct );
314
-
315
- if (has_zero && LWAN_MAX (has_zero , m ) == has_zero ) {
316
- return NULL ;
317
- }
318
-
319
- if (m ) {
320
- return str + __builtin_ctz (m ) / 8 ;
321
- }
322
-
323
- str += 4 ;
324
- }
325
-
326
- check_small :
327
- while (* str ) {
328
- if (* str == '%' || * str == '+' )
329
- return str ;
330
- str ++ ;
331
- }
332
-
333
- return NULL ;
334
- }
335
-
336
269
__attribute__((nonnull (1 ))) static ssize_t url_decode (char * str )
337
270
{
338
271
static const unsigned char tbl1 [256 ] = {
@@ -353,7 +286,7 @@ __attribute__((nonnull(1))) static ssize_t url_decode(char *str)
353
286
const char * inptr = str ;
354
287
char * outptr = str ;
355
288
356
- for (char * p = find_pct_or_plus (inptr ); p ; p = find_pct_or_plus (inptr )) {
289
+ for (char * p = strpbrk (inptr , "%+" ); p ; p = strpbrk (inptr , "%+" )) {
357
290
const ptrdiff_t diff = p - inptr ;
358
291
if (diff )
359
292
outptr = mempmove (outptr , inptr , (size_t )diff );
0 commit comments