diff --git a/ChangeLog b/ChangeLog index bd184a141b..76a67e531a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sat Feb 5 09:38:08 2011 Nobuyoshi Nakada + + * transcode.c (encoded_dup): extract. + Sat Feb 5 03:37:47 2011 Nobuyoshi Nakada * lib/fileutils.rb (FileUtils::LowMethods): make low level methods diff --git a/transcode.c b/transcode.c index e7f09a434e..d64fe80fc8 100644 --- a/transcode.c +++ b/transcode.c @@ -2757,6 +2757,8 @@ str_encode_bang(int argc, VALUE *argv, VALUE str) return str_encode_associate(str, encidx); } +static VALUE encoded_dup(VALUE newstr, VALUE str, int encidx); + /* * call-seq: * str.encode(encoding [, options] ) -> str @@ -2816,15 +2818,7 @@ str_encode(int argc, VALUE *argv, VALUE str) { VALUE newstr = str; int encidx = str_transcode(argc, argv, &newstr); - - if (encidx < 0) return rb_str_dup(str); - if (newstr == str) { - newstr = rb_str_dup(str); - } - else { - RBASIC(newstr)->klass = rb_obj_class(str); - } - return str_encode_associate(newstr, encidx); + return encoded_dup(newstr, str, encidx); } VALUE @@ -2834,7 +2828,12 @@ rb_str_encode(VALUE str, VALUE to, int ecflags, VALUE ecopts) VALUE *argv = &to; VALUE newstr = str; int encidx = str_transcode0(argc, argv, &newstr, ecflags, ecopts); + return encoded_dup(newstr, str, encidx); +} +static VALUE +encoded_dup(VALUE newstr, VALUE str, int encidx) +{ if (encidx < 0) return rb_str_dup(str); if (newstr == str) { newstr = rb_str_dup(str);