From 3ef703179891fa3f6f9d03f2ae58d289c691738e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 19 Feb 2013 11:36:18 +0000 Subject: httpdate: minor size reduction in DSO 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 --- ext/unicorn_http/httpdate.c | 14 +++++--------- 1 file 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, -- cgit v1.2.3-24-ge0c7