From e59b9e9e43881a818f21a2a5cf6a702d42142c75 Mon Sep 17 00:00:00 2001 From: naruse Date: Thu, 2 Dec 2010 19:19:47 +0000 Subject: [PATCH] * encoding.c (enc_alias_internal): use st_insert2 and change return value to int. * encoding.c (enc_alias): follow enc_alias_internal. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30060 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ encoding.c | 14 +++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7268671b42..20b6e7ddff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Fri Dec 3 04:08:59 2010 NARUSE, Yui + + * encoding.c (enc_alias_internal): use st_insert2 and change return + value to int. + + * encoding.c (enc_alias): follow enc_alias_internal. + Fri Dec 3 01:52:43 2010 NARUSE, Yui * encoding.c (enc_alias_internal): use xfree instead of free. diff --git a/encoding.c b/encoding.c index 70cc65ba3b..ac0e1ba842 100644 --- a/encoding.c +++ b/encoding.c @@ -440,23 +440,19 @@ rb_enc_unicode_p(rb_encoding *enc) * Returns copied alias name when the key is added for st_table, * else returns NULL. */ -static const char * +static int enc_alias_internal(const char *alias, int idx) { - char *name = strdup(alias); - if (st_insert(enc_table.names, (st_data_t)name, (st_data_t)idx)) { - xfree(name); - return NULL; - } - return name; + return st_insert2(enc_table.names, (st_data_t)alias, (st_data_t)idx, + (st_data_t(*)(st_data_t))strdup); } static int enc_alias(const char *alias, int idx) { if (!valid_encoding_name_p(alias)) return -1; - alias = enc_alias_internal(alias, idx); - if (alias) set_encoding_const(alias, rb_enc_from_index(idx)); + if (!enc_alias_internal(alias, idx)) + set_encoding_const(alias, rb_enc_from_index(idx)); return idx; }