summaryrefslogtreecommitdiffstats
path: root/transcode.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-14 17:37:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-14 17:37:35 +0000
commit030d9e240c8cc42d170d0290bb3a478072b9f6b5 (patch)
tree3c7e0a3937b2e778057ae7c0e7be99089112e86f /transcode.c
parent8bd9cec4f65e4806912b74ab13e46dd1c46d72e3 (diff)
downloadruby-030d9e240c8cc42d170d0290bb3a478072b9f6b5.tar.gz
ruby-030d9e240c8cc42d170d0290bb3a478072b9f6b5.tar.xz
ruby-030d9e240c8cc42d170d0290bb3a478072b9f6b5.zip
* transcode.c (str_encode): returns duplicated string if nothing
changed. [ruby-core:18578] git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@19349 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'transcode.c')
-rw-r--r--transcode.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/transcode.c b/transcode.c
index 4d1107ddc..1c1126fcc 100644
--- a/transcode.c
+++ b/transcode.c
@@ -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);
}