summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-17 03:50:59 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-02-17 03:50:59 +0000
commitc9524768d4e6770721cee6aaab571861b2c658df (patch)
tree8ea639d7c980d114ae83f83de605dcce4f4ebba2 /string.c
parent1fb1fb2b88ff35ff45a7f6b8a0a832260008993d (diff)
* string.c (rb_str_shared_replace): no need for
str_make_independent. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@22368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/string.c b/string.c
index a69972198f..ddaa6922b3 100644
--- a/string.c
+++ b/string.c
@@ -264,13 +264,14 @@ rb_str_to_str(str)
return rb_convert_type(str, T_STRING, "String", "to_str");
}
+static inline void str_discard _((VALUE str));
+
static void
rb_str_shared_replace(str, str2)
VALUE str, str2;
{
if (str == str2) return;
- rb_str_modify(str);
- if (!FL_TEST(str, ELTS_SHARED)) free(RSTRING(str)->ptr);
+ str_discard(str);
if (NIL_P(str2)) {
RSTRING(str)->ptr = 0;
RSTRING(str)->len = 0;
@@ -512,6 +513,16 @@ rb_str_modify(str)
str_make_independent(str);
}
+static inline void
+str_discard(VALUE str)
+{
+ if (str_independent(str)) {
+ xfree(RSTRING_PTR(str));
+ RSTRING(str)->ptr = 0;
+ RSTRING(str)->len = 0;
+ }
+}
+
void
rb_str_associate(str, add)
VALUE str, add;
@@ -2212,9 +2223,7 @@ str_gsub(argc, argv, str, bang)
*bp = '\0';
rb_str_unlocktmp(dest);
if (bang) {
- if (str_independent(str)) {
- free(RSTRING(str)->ptr);
- }
+ str_discard(str);
FL_UNSET(str, STR_NOCAPA);
RSTRING(str)->ptr = buf;
RSTRING(str)->aux.capa = blen;
@@ -2312,9 +2321,7 @@ rb_str_replace(str, str2)
StringValue(str2);
if (FL_TEST(str2, ELTS_SHARED)) {
- if (str_independent(str)) {
- free(RSTRING(str)->ptr);
- }
+ str_discard(str);
RSTRING(str)->len = RSTRING(str2)->len;
RSTRING(str)->ptr = RSTRING(str2)->ptr;
FL_SET(str, ELTS_SHARED);