diff options
| author | cubicdaiya <[email protected]> | 2014-02-25 15:03:35 +0900 |
|---|---|---|
| committer | cubicdaiya <[email protected]> | 2014-02-25 15:03:35 +0900 |
| commit | 985e4892cfcad52168af55b3b2ebc2c7e6a3b414 (patch) | |
| tree | a8572120945225e46780d023e0ce4eb1ba35649a | |
| parent | ebd976be842c0c16be855e7f9d7cea71a95311f0 (diff) | |
| download | mruby-985e4892cfcad52168af55b3b2ebc2c7e6a3b414.tar.gz mruby-985e4892cfcad52168af55b3b2ebc2c7e6a3b414.zip | |
small-optimization for mrb_time_zone
Using mrb_str_new instead of mrb_str_new_cstr
| -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..7f513624f 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(mrb, + timezone_names[tm->timezone].name, + timezone_names[tm->timezone].len); } /* 15.2.19.7.4 */ |
