summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-03 11:02:53 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-07-03 11:02:53 +0000
commit9d22a06ea06e9bec5030fd6e2c8481958fcd30d9 (patch)
tree58b15b4dc85acca1c806388ff3848a3c85fd0ebf /string.c
parenta11ab83884c47f729a8630ab5ef21c7522b48386 (diff)
* array.c (rb_values_at): extract common procedure from
rb_ary_values_at. follow DRY principle. * re.c (match_values_at): values_at should understand ranges. * struct.c (rb_struct_values_at): ditto. * struct.c (inspect_struct): inspect format changed; add "struct " at the top. * sprintf.c (rb_f_sprintf): "%p" specifier for inspect output. (RCR#68) * eval.c (rb_mod_undef_method): allow "undef_method" to accept multiple arguments. (RCR#146) * lib/timeout.rb: put timeout in Timeout module. (RCR#121) [ruby-talk:61028] * re.c (match_groups): new method added. (RCR#139) * variable.c (rb_mod_const_of): should exclude constant defined in Object, unless retrieving constants of Object. * string.c (rb_str_new4): do not allocate new string if original is frozen or already have copy-on-write entry. [ruby-talk:74940] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4031 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/string.c b/string.c
index 25b325f0ec..692a158c09 100644
--- a/string.c
+++ b/string.c
@@ -157,14 +157,17 @@ rb_str_new4(orig)
{
VALUE klass, str;
+ if (OBJ_FROZEN(orig)) return orig;
klass = rb_obj_class(orig);
if (FL_TEST(orig, ELTS_SHARED) && RSTRING(orig)->aux.shared) {
long ofs;
str = RSTRING(orig)->aux.shared;
ofs = RSTRING(str)->len - RSTRING(orig)->len;
- str = str_new3(klass, str);
- RSTRING(str)->ptr += ofs;
- RSTRING(str)->len -= ofs;
+ if (ofs > 0) {
+ str = str_new3(klass, str);
+ RSTRING(str)->ptr += ofs;
+ RSTRING(str)->len -= ofs;
+ }
}
else if (FL_TEST(orig, STR_ASSOC)) {
str = str_new(klass, RSTRING(orig)->ptr, RSTRING(orig)->len);