ext/iodine/http1_parser.h
/**
 * This seems to be faster on some systems, especially for smaller distances.
 *
 * On newer systems, `memchr` should be faster.
 */
This seems to be faster on some systems, especially for smaller distances.
On newer systems, `memchr` should be faster.
This seems to be faster on some systems especially for smaller distances . On newer systems ` memchr ` should be faster .
static int seek2ch(uint8_t **buffer, register uint8_t *const limit,
                   const uint8_t c) {
  if (*buffer >= limit)
    return 0;
  if (**buffer == c) {
    return 1;
  }
#if !HTTP1_UNALIGNED_MEMORY_ACCESS_ENABLED
  if ((uintptr_t)limit <= 16 + ((uintptr_t)*buffer & (~(uintptr_t)7)))
    goto finish;
  {
    const uint8_t *alignment =
        (uint8_t *)(((uintptr_t)(*buffer) & (~(uintptr_t)7)) + 8);
    if (*buffer < alignment)
      *buffer += 1; 
    if (limit >= alignment) {
      while (*buffer < alignment) {
        if (**buffer == c) {
          return 1;
        }
        *buffer += 1;
      }
    }
  }
  const uint8_t *limit64 = (uint8_t *)((uintptr_t)limit & (~(uintptr_t)7));
#else
  const uint8_t *limit64 = (uint8_t *)limit - 7;
#endif
  uint64_t wanted1 = 0x0101010101010101ULL * c;
  for (; *buffer < limit64; *buffer += 8) {
    const uint64_t eq1 = ~((*((uint64_t *)*buffer)) ^ wanted1);
    const uint64_t t0 = (eq1 & 0x7f7f7f7f7f7f7f7fllu) + 0x0101010101010101llu;
    const uint64_t t1 = (eq1 & 0x8080808080808080llu);
    if ((t0 & t1)) {
      break;
    }
  }
#if !HTTP1_UNALIGNED_MEMORY_ACCESS_ENABLED
finish:
#endif
  while (*buffer < limit) {
    if (**buffer == c) {
      return 1;
    }
    (*buffer)++;
  }
  return 0;
}
static int seek2ch ( uint8_t * * buffer , register uint8_t * const limit , const uint8_t c ) { if ( * buffer >= limit ) return 0 ; if ( * * buffer == c ) { return 1 ; } #if ! HTTP1_UNALIGNED_MEMORY_ACCESS_ENABLED if ( ( uintptr_t ) limit <= 16 + ( ( uintptr_t ) * buffer & ( ~ ( uintptr_t ) 7 ) ) ) goto finish ; { const uint8_t * alignment = ( uint8_t * ) ( ( ( uintptr_t ) ( * buffer ) & ( ~ ( uintptr_t ) 7 ) ) + 8 ) ; if ( * buffer < alignment ) * buffer += 1 ; if ( limit >= alignment ) { while ( * buffer < alignment ) { if ( * * buffer == c ) { return 1 ; } * buffer += 1 ; } } } const uint8_t * limit64 = ( uint8_t * ) ( ( uintptr_t ) limit & ( ~ ( uintptr_t ) 7 ) ) ; #else const uint8_t * limit64 = ( uint8_t * ) limit - 7 ; #endif uint64_t wanted1 = 0x0101010101010101ULL * c ; for ( ; * buffer < limit64 ; * buffer += 8 ) { const uint64_t eq1 = ~ ( ( * ( ( uint64_t * ) * buffer ) ) ^ wanted1 ) ; const uint64_t t0 = ( eq1 & 0x7f7f7f7f7f7f7f7fllu ) + 0x0101010101010101llu ; const uint64_t t1 = ( eq1 & 0x8080808080808080llu ) ; if ( ( t0 & t1 ) ) { break ; } } #if ! HTTP1_UNALIGNED_MEMORY_ACCESS_ENABLED finish : #endif while ( * buffer < limit ) { if ( * * buffer == c ) { return 1 ; } ( * buffer ) ++ ; } return 0 ; }
This seems to be faster on some systems, especially for smaller distances.
This seems to be faster on some systems especially for smaller distances .
/* too short for this mess */ /* align memory */ /* we already tested this char */