From abb47b5a6cae1a814f56893df1f2572203fd8faa Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 2 Aug 2009 13:58:34 -0700 Subject: http: split uncommon_field into a separate function 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. --- ext/unicorn_http/common_field_optimization.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'ext/unicorn_http/common_field_optimization.h') 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 */ -- cgit v1.2.3-24-ge0c7