about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-08-02 15:00:03 -0700
committerEric Wong <normalperson@yhbt.net>2009-08-09 01:28:16 -0700
commit04872aa8c6e7a88d56add4e082b485da02da33f0 (patch)
treed60348469d2cf707519ab2c542fe79c993325223
parent7bb9cf8e08eae1ab9fa058d62753eda044707627 (diff)
downloadunicorn-04872aa8c6e7a88d56add4e082b485da02da33f0.tar.gz
Create a Ruby string object before jumping into the function
to reduce the number of parameters passed and to take advantage
of our STR_NEW macro to reduce noise.
-rw-r--r--ext/unicorn_http/unicorn_http.rl15
1 files changed, 5 insertions, 10 deletions
diff --git a/ext/unicorn_http/unicorn_http.rl b/ext/unicorn_http/unicorn_http.rl
index 48fc5fc..462281c 100644
--- a/ext/unicorn_http/unicorn_http.rl
+++ b/ext/unicorn_http/unicorn_http.rl
@@ -24,8 +24,7 @@ struct http_parser {
   size_t field_len;
 };
 
-static void http_field(VALUE req, const char *field,
-                       size_t flen, const char *value, size_t vlen);
+static void http_field(VALUE req, const char *field, size_t flen, VALUE val);
 static void header_done(VALUE req, const char *at, size_t length);
 
 static int http_parser_has_error(struct http_parser *hp);
@@ -50,8 +49,8 @@ static int http_parser_is_finished(struct http_parser *hp);
   action write_field { hp->field_len = LEN(start.field, fpc); }
   action start_value { MARK(mark, fpc); }
   action write_value {
-    http_field(req, PTR_TO(start.field), hp->field_len,
-               PTR_TO(mark), LEN(mark, fpc));
+    VALIDATE_MAX_LENGTH(LEN(mark, fpc), FIELD_VALUE);
+    http_field(req, PTR_TO(start.field), hp->field_len, STR_NEW(mark, fpc));
   }
   action request_method {
     rb_hash_aset(req, g_request_method, STR_NEW(mark, fpc));
@@ -165,14 +164,10 @@ static struct http_parser *data_get(VALUE self)
   assert(hp);
   return hp;
 }
-
-static void http_field(VALUE req, const char *field,
-                       size_t flen, const char *value, size_t vlen)
+static void http_field(VALUE req, const char *field, size_t flen, VALUE val)
 {
   VALUE f = find_common_field(field, flen);
 
-  VALIDATE_MAX_LENGTH(vlen, FIELD_VALUE);
-
   if (f == Qnil) {
     VALIDATE_MAX_LENGTH(flen, FIELD_NAME);
     f = uncommon_field(field, flen);
@@ -180,7 +175,7 @@ static void http_field(VALUE req, const char *field,
     return;
   }
 
-  rb_hash_aset(req, f, rb_str_new(value, vlen));
+  rb_hash_aset(req, f, val);
 }
 
 static int is_https(VALUE str)