Skip to content

Commit

Permalink
small-optimization for mrb_time_zone
Browse files Browse the repository at this point in the history
Using mrb_str_new instead of mrb_str_new_cstr
  • Loading branch information
cubicdaiya committed Feb 25, 2014
1 parent ebd976b commit 985e489
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions mrbgems/mruby-time/src/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 985e489

Please sign in to comment.