From eccd4f15ff05f44e2ca0670ef656da1eff560b28 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 6 Aug 2001 15:05:50 +0000 Subject: a problem about `associated' String and `str_buf'. * pack.c (pack_unpack): associates p/P strings once at last(reverted to 1.26). * string.c (rb_str_associate): associates an Array at once, not but a String. realloc's when str_buf. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@1672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'string.c') diff --git a/string.c b/string.c index 326b9626b..ec1a31362 100644 --- a/string.c +++ b/string.c @@ -203,13 +203,22 @@ rb_str_associate(str, add) VALUE str, add; { if (FL_TEST(str, STR_NO_ORIG|STR_ASSOC) != (STR_NO_ORIG|STR_ASSOC)) { - if (RSTRING(str)->orig) { + if (FL_TEST(str, STR_NO_ORIG)) { + /* str_buf */ + if (FIX2LONG(RSTRING(str)->orig) != RSTRING(str)->len) { + REALLOC_N(RSTRING(str)->ptr, char, RSTRING(str)->len + 1); + } + } + else if (RSTRING(str)->orig) { rb_str_modify(str); } - RSTRING(str)->orig = rb_ary_new(); + RSTRING(str)->orig = add; FL_SET(str, STR_NO_ORIG|STR_ASSOC); } - rb_ary_push(RSTRING(str)->orig, add); + else { + /* already associated */ + rb_ary_concat(RSTRING(str)->orig, add); + } } VALUE -- cgit