* transcode.c (str_encode): returns duplicated string if nothing

changed.  [ruby-core:18578]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19349 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2008-09-14 17:37:35 +00:00
parent ca36233e55
commit 2f67b43aec
3 changed files with 17 additions and 1 deletions

View file

@ -2570,7 +2570,12 @@ str_encode(int argc, VALUE *argv, VALUE str)
int encidx = str_transcode(argc, argv, &newstr);
if (encidx < 0) return rb_str_dup(str);
RBASIC(newstr)->klass = rb_obj_class(str);
if (newstr == str) {
newstr = rb_str_dup(str);
}
else {
RBASIC(newstr)->klass = rb_obj_class(str);
}
return str_encode_associate(newstr, encidx);
}