From abfaac7a6cbdbfad9e7c05bc5ebcb4df57906fcb Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 30 May 2001 09:12:34 +0000 Subject: * ruby.c (proc_options): unexpected SecurityError happens when -T4. * regex.c (re_compile_pattern): * \1 .. \9 should be backreferences always. * regex.c (re_match): backreferences corresponding to unclosed/unmatched parentheses should fail always. * string.c (rb_str_cat): use rb_str_buf_cat() if possible. [new] * string.c (rb_str_append): ditto. * string.c (rb_str_buf_cat): remove unnecessary check (type, taint, modify) to gain performance. * string.c (rb_str_buf_append): ditto. * string.c (rb_str_buf_new): buffering string function. [new] * string.c (rb_str_buf_append): ditto. * string.c (rb_str_buf_cat): ditto. * time.c (make_time_t): local time adjustment revised. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- array.c | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) (limited to 'array.c') diff --git a/array.c b/array.c index 1d63a9fa2b..010afd9a39 100644 --- a/array.c +++ b/array.c @@ -739,26 +739,11 @@ inspect_join(ary, arg) return rb_ary_join(arg[0], arg[1]); } -static long -str_cpy(str, idx, str2) - VALUE str; - long idx; - VALUE str2; -{ - long len = idx + RSTRING(str2)->len; - - if (RSTRING(str)->len < len) { - rb_str_resize(str, len); - } - memcpy(RSTRING(str)->ptr+idx, RSTRING(str2)->ptr, RSTRING(str2)->len); - return len; -} - VALUE rb_ary_join(ary, sep) VALUE ary, sep; { - long len, i, j; + long len, i; int taint = 0; VALUE result, tmp; @@ -778,9 +763,8 @@ rb_ary_join(ary, sep) if (!NIL_P(sep) && TYPE(sep) == T_STRING) { len += RSTRING(sep)->len * RARRAY(ary)->len - 1; } - result = rb_str_new(0, len); - - for (i=0, j=0; ilen; i++) { + result = rb_str_buf_new(len); + for (i=0; ilen; i++) { tmp = RARRAY(ary)->ptr[i]; switch (TYPE(tmp)) { case T_STRING: @@ -800,11 +784,11 @@ rb_ary_join(ary, sep) default: tmp = rb_obj_as_string(tmp); } - if (i > 0 && !NIL_P(sep)) j = str_cpy(result, j, sep); - j = str_cpy(result, j, tmp); + if (i > 0 && !NIL_P(sep)) + rb_str_buf_append(result, sep); + rb_str_buf_append(result, tmp); if (OBJ_TAINTED(tmp)) taint = 1; } - rb_str_resize(result, j); if (taint) OBJ_TAINT(result); return result; @@ -909,16 +893,14 @@ inspect_ary(ary) long i = 0; VALUE s, str; - str = rb_str_new2("["); - + str = rb_str_buf_new2("["); for (i=0; ilen; i++) { s = rb_inspect(RARRAY(ary)->ptr[i]); - tainted = OBJ_TAINTED(s); - if (i > 0) rb_str_cat2(str, ", "); - rb_str_append(str, s); + if (OBJ_TAINTED(s)) tainted = 1; + if (i > 0) rb_str_buf_cat2(str, ", "); + rb_str_buf_append(str, s); } - rb_str_cat(str, "]", 1); - + rb_str_buf_cat2(str, "]"); if (tainted) OBJ_TAINT(str); return str; } -- cgit v1.2.3