diff options
Diffstat (limited to 'ext/unicorn_http/common_field_optimization.h')
-rw-r--r-- | ext/unicorn_http/common_field_optimization.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/ext/unicorn_http/common_field_optimization.h b/ext/unicorn_http/common_field_optimization.h index adebe2c..97640c6 100644 --- a/ext/unicorn_http/common_field_optimization.h +++ b/ext/unicorn_http/common_field_optimization.h @@ -93,4 +93,17 @@ static VALUE find_common_field(const char *field, size_t flen) return Qnil; } +/* + * We got a strange header that we don't have a memoized value for. + * Fallback to creating a new string to use as a hash key. + */ +static VALUE uncommon_field(const char *field, size_t flen) +{ + VALUE f = rb_str_new(NULL, HTTP_PREFIX_LEN + flen); + memcpy(RSTRING_PTR(f), HTTP_PREFIX, HTTP_PREFIX_LEN); + memcpy(RSTRING_PTR(f) + HTTP_PREFIX_LEN, field, flen); + assert(*(RSTRING_PTR(f) + RSTRING_LEN(f)) == '\0'); /* paranoia */ + return f; +} + #endif /* common_field_optimization_h */ |