summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--time.c26
2 files changed, 20 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index bce4515..55104e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Wed Dec 12 18:27:09 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * time.c (zone_str): lookup or insert by using st_update() at once.
+
Wed Dec 12 15:30:11 2012 NARUSE, Yui <naruse@ruby-lang.org>
* configure.in: add -fno-omit-frame-pointer if libexecinfo is used.
diff --git a/time.c b/time.c
index c8aedd8..29565be 100644
--- a/time.c
+++ b/time.c
@@ -1023,22 +1023,28 @@ timegmw_noleapsecond(struct vtm *vtm)
static st_table *zone_table;
+static int
+zone_str_update(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
+{
+ const char *s = (const char *)*key;
+ const char **ret = (const char **)arg;
+
+ if (existing) {
+ *ret = (const char *)*value;
+ return ST_STOP;
+ }
+ *ret = s = strdup(s);
+ *key = *value = (st_data_t)s;
+ return ST_CONTINUE;
+}
+
static const char *
zone_str(const char *s)
{
- st_data_t k, v;
-
if (!zone_table)
zone_table = st_init_strtable();
- k = (st_data_t)s;
- if (st_lookup(zone_table, k, &v)) {
- return (const char *)v;
- }
- s = strdup(s);
- k = (st_data_t)s;
- st_add_direct(zone_table, k, k);
-
+ st_update(zone_table, (st_data_t)s, zone_str_update, (st_data_t)&s);
return s;
}