mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
486795d951
commit
a773539d3a
2 changed files with 20 additions and 10 deletions
|
@ -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.
|
||||
|
|
26
time.c
26
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue