summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-07 12:32:54 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-07 12:32:54 (GMT)
commit89dde224d4c46ec0fdd2cb1f44e77044b81d7a41 (patch)
treea0b9b19fdad6336c7b912f1a82c2ae3421dc6df1 /string.c
parent2c31c3b45ed5ef3c2c0a2308957fb98334367cf4 (diff)
string.c: str_duplicate
* string.c (str_duplicate): move from rb_str_resurrect to short circuit initialization. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52074 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/string.c b/string.c
index c2668d1..13f4ce4 100644
--- a/string.c
+++ b/string.c
@@ -1236,20 +1236,6 @@ str_replace(VALUE str, VALUE str2)
static VALUE
str_duplicate(VALUE klass, VALUE str)
{
- VALUE dup = str_alloc(klass);
- str_replace(dup, str);
- return dup;
-}
-
-VALUE
-rb_str_dup(VALUE str)
-{
- return str_duplicate(rb_obj_class(str), str);
-}
-
-VALUE
-rb_str_resurrect(VALUE str)
-{
enum {embed_size = RSTRING_EMBED_LEN_MAX + 1};
const VALUE flag_mask =
RSTRING_NOEMBED | RSTRING_EMBED_LEN_MASK |
@@ -1257,18 +1243,12 @@ rb_str_resurrect(VALUE str)
FL_TAINT | FL_FREEZE
;
VALUE flags = FL_TEST_RAW(str, flag_mask);
- VALUE dup;
-
- if (RUBY_DTRACE_STRING_CREATE_ENABLED()) {
- RUBY_DTRACE_STRING_CREATE(RSTRING_LEN(str),
- rb_sourcefile(), rb_sourceline());
- }
- dup = str_alloc(rb_cString);
+ VALUE dup = str_alloc(klass);
MEMCPY(RSTRING(dup)->as.ary, RSTRING(str)->as.ary,
char, embed_size);
if (flags & STR_NOEMBED) {
if (UNLIKELY(!(flags & FL_FREEZE))) {
- str = str_new_frozen(rb_cString, str);
+ str = str_new_frozen(klass, str);
FL_SET_RAW(str, flags & FL_TAINT);
flags = FL_TEST_RAW(str, flag_mask);
}
@@ -1285,6 +1265,22 @@ rb_str_resurrect(VALUE str)
return dup;
}
+VALUE
+rb_str_dup(VALUE str)
+{
+ return str_duplicate(rb_obj_class(str), str);
+}
+
+VALUE
+rb_str_resurrect(VALUE str)
+{
+ if (RUBY_DTRACE_STRING_CREATE_ENABLED()) {
+ RUBY_DTRACE_STRING_CREATE(RSTRING_LEN(str),
+ rb_sourcefile(), rb_sourceline());
+ }
+ return str_duplicate(rb_cString, str);
+}
+
/*
* call-seq:
* String.new(str="") -> new_str