[前][次][番号順一覧][スレッド一覧]

ruby-changes:26292

From: nobu <ko1@a...>
Date: Wed, 12 Dec 2012 18:27:24 +0900 (JST)
Subject: [ruby-changes:26292] nobu:r38343 (trunk): time.c: st_update

nobu	2012-12-12 18:27:12 +0900 (Wed, 12 Dec 2012)

  New Revision: 38343

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38343

  Log:
    time.c: st_update
    
    * time.c (zone_str): lookup or insert by using st_update() at once.

  Modified files:
    trunk/ChangeLog
    trunk/time.c

Index: time.c
===================================================================
--- time.c	(revision 38342)
+++ time.c	(revision 38343)
@@ -1023,22 +1023,28 @@ timegmw_noleapsecond(struct vtm *vtm) https://github.com/ruby/ruby/blob/trunk/time.c#L1023
 
 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;
 }
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38342)
+++ ChangeLog	(revision 38343)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Dec 12 18:27:09 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* time.c (zone_str): lookup or insert by using st_update() at once.
+
 Wed Dec 12 15:30:11 2012  NARUSE, Yui  <naruse@r...>
 
 	* configure.in: add -fno-omit-frame-pointer if libexecinfo is used.

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]