summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-12 09:27:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-12 09:27:12 +0000
commita773539d3af48a8e95960fa1c98d0be790a6e529 (patch)
tree5940596b182d005613dce3b8dcef9b9e0cd9904f /time.c
parent486795d95124c8d2bdaf4ae84a282e3879cb367c (diff)
downloadruby-a773539d3af48a8e95960fa1c98d0be790a6e529.tar.gz
time.c: st_update
* time.c (zone_str): lookup or insert by using st_update() at once. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/time.c b/time.c
index c8aedd88ce..29565be6e2 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;
}