summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-02-19 11:36:18 +0000
committerEric Wong <normalperson@yhbt.net>2013-02-24 21:48:41 +0000
commit3ef703179891fa3f6f9d03f2ae58d289c691738e (patch)
tree83aa78c9e0b3b9f4b5e7b3c58b7e37402f624dc2
parentf8829e69e28bb93dbbf9a220cdff163a6ba182d5 (diff)
Extra pointers waste space in the DSO.  Normally I wouldn't
care, but the string lengths are identical and this code
already made it into another project in this form.

size(1) output:

         text      data     bss     dec     hex  filename
before: 42881      2040     336   45257    b0c9  unicorn_http.so
 after: 42499      1888     336   44723    aeb3  unicorn_http.so

ref: http://www.akkadia.org/drepper/dsohowto.pdf
-rw-r--r--ext/unicorn_http/httpdate.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/ext/unicorn_http/httpdate.c b/ext/unicorn_http/httpdate.c
index bfa11ca..bf54fdd 100644
--- a/ext/unicorn_http/httpdate.c
+++ b/ext/unicorn_http/httpdate.c
@@ -5,13 +5,9 @@
 static const size_t buf_capa = sizeof("Thu, 01 Jan 1970 00:00:00 GMT");
 static VALUE buf;
 static char *buf_ptr;
-static const char *const week[] = {
-        "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
-};
-static const char *const months[] = {
-        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
-        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
-};
+static const char week[] = "Sun\0Mon\0Tue\0Wed\0Thu\0Fri\0Sat";
+static const char months[] = "Jan\0Feb\0Mar\0Apr\0May\0Jun\0"
+                             "Jul\0Aug\0Sep\0Oct\0Nov\0Dec";
 
 /* for people on wonky systems only */
 #ifndef HAVE_GMTIME_R
@@ -57,9 +53,9 @@ static VALUE httpdate(VALUE self)
         /* we can make this thread-safe later if our Ruby loses the GVL */
         snprintf(buf_ptr, buf_capa,
                  "%s, %02d %s %4d %02d:%02d:%02d GMT",
-                 week[tm.tm_wday],
+                 week + (tm.tm_wday * 4),
                  tm.tm_mday,
-                 months[tm.tm_mon],
+                 months + (tm.tm_mon * 4),
                  tm.tm_year + 1900,
                  tm.tm_hour,
                  tm.tm_min,