Skip to content

Commit

Permalink
* encoding.c (enc_alias_internal): use st_insert2 and change return
Browse files Browse the repository at this point in the history
  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
  • Loading branch information
nurse committed Dec 2, 2010
1 parent 3010758 commit e59b9e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
@@ -1,3 +1,10 @@
Fri Dec 3 04:08:59 2010 NARUSE, Yui <naruse@ruby-lang.org>

* 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 <naruse@ruby-lang.org>

* encoding.c (enc_alias_internal): use xfree instead of free.
Expand Down
14 changes: 5 additions & 9 deletions encoding.c
Expand Up @@ -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;
}

Expand Down

0 comments on commit e59b9e9

Please sign in to comment.