summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-23 01:16:46 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-07-23 01:16:46 +0000
commit33f5edd5f339c03e51cbdf00dbb384df58781c24 (patch)
treeced74b0d6bbf58718944ba4838b22d6fc2ef2ed9 /string.c
parent7c413b55455193be7dd00368128fe30b972dde52 (diff)
downloadruby-33f5edd5f339c03e51cbdf00dbb384df58781c24.tar.gz
string.c: str_shared_replace
* string.c (str_shared_replace): split from rb_str_shared_replace without argument check. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/string.c b/string.c
index 110d11199e..f6d305c7ff 100644
--- a/string.c
+++ b/string.c
@@ -1105,13 +1105,21 @@ rb_str_to_str(VALUE str)
}
static inline void str_discard(VALUE str);
+static void str_shared_replace(VALUE str, VALUE str2);
void
rb_str_shared_replace(VALUE str, VALUE str2)
{
+ if (str != str2) str_shared_replace(str, str2);
+}
+
+static void
+str_shared_replace(VALUE str, VALUE str2)
+{
rb_encoding *enc;
int cr;
- if (str == str2) return;
+
+ ASSUME(str2 != str);
enc = STR_ENC_GET(str2);
cr = ENC_CODERANGE(str2);
str_discard(str);
@@ -4477,7 +4485,7 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
}
rb_pat_search(pat, str, last, 1);
if (bang) {
- rb_str_shared_replace(str, dest);
+ str_shared_replace(str, dest);
}
else {
RBASIC_SET_CLASS(dest, rb_obj_class(str));
@@ -4872,7 +4880,7 @@ rb_str_reverse_bang(VALUE str)
}
}
else {
- rb_str_shared_replace(str, rb_str_reverse(str));
+ str_shared_replace(str, rb_str_reverse(str));
}
}
else {