summaryrefslogtreecommitdiff
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
commit2f67b43aeca4530842db1324983a0e7a563917cc (patch)
tree3c7e0a3937b2e778057ae7c0e7be99089112e86f /transcode.c
parentca36233e55625b6653e68e27e37cd9e30d11b491 (diff)
* 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
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 4d1107ddc4..1c1126fcce 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);
}