diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-02-25 19:13:44 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-02-25 19:13:44 +0900 |
| commit | 501f7ab25dfcffd56a648e65098fae9c82480834 (patch) | |
| tree | 7552539a82e87368113cbda737f2699227959803 | |
| parent | ebd976be842c0c16be855e7f9d7cea71a95311f0 (diff) | |
| parent | 96c24b0a37d55dad37a80f408c466dfb2285faaf (diff) | |
| download | mruby-501f7ab25dfcffd56a648e65098fae9c82480834.tar.gz mruby-501f7ab25dfcffd56a648e65098fae9c82480834.zip | |
Merge pull request #1738 from cubicdaiya/issues/optim_mrb_time_zone
small-optimization for mrb_time_zone
| -rw-r--r-- | mrbgems/mruby-time/src/time.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/mrbgems/mruby-time/src/time.c b/mrbgems/mruby-time/src/time.c index 8bea2cb5b..a13af790b 100644 --- a/mrbgems/mruby-time/src/time.c +++ b/mrbgems/mruby-time/src/time.c @@ -93,11 +93,16 @@ enum mrb_timezone { MRB_TIMEZONE_LAST = 3 }; -static const char *timezone_names[] = { - "none", - "UTC", - "LOCAL", - NULL +typedef struct mrb_timezone_name { + const char *name; + size_t len; +} mrb_timezone_name; + +static mrb_timezone_name timezone_names[] = { + { "none", sizeof("none") - 1 }, + { "UTC", sizeof("UTC") - 1 }, + { "LOCAL", sizeof("LOCAL") - 1 }, + { NULL, 0 } }; static const char *mon_names[] = { @@ -401,7 +406,9 @@ mrb_time_zone(mrb_state *mrb, mrb_value self) tm = DATA_GET_PTR(mrb, self, &mrb_time_type, struct mrb_time); if (tm->timezone <= MRB_TIMEZONE_NONE) return mrb_nil_value(); if (tm->timezone >= MRB_TIMEZONE_LAST) return mrb_nil_value(); - return mrb_str_new_cstr(mrb, timezone_names[tm->timezone]); + return mrb_str_new_static(mrb, + timezone_names[tm->timezone].name, + timezone_names[tm->timezone].len); } /* 15.2.19.7.4 */ |
