diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-08-02 13:58:34 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-08-09 01:24:56 -0700 |
commit | abb47b5a6cae1a814f56893df1f2572203fd8faa (patch) | |
tree | 007826593aee09e7c39b96ebea71297bfeca4139 /ext/unicorn_http/common_field_optimization.h | |
parent | 4dc2a9e95d115547b7c2680f198293d6e25658b3 (diff) | |
download | unicorn-abb47b5a6cae1a814f56893df1f2572203fd8faa.tar.gz |
There's also no point in validating field hits if our field is a common field; so only do the validation for field length if we need to allocate memory for a new field.
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 */ |