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 --- re.c | 74 +++++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 32 deletions(-) (limited to 're.c') diff --git a/re.c b/re.c index 92e0420f50..bd8f34a173 100644 --- a/re.c +++ b/re.c @@ -224,51 +224,51 @@ rb_reg_expr_str(str, s, len) p++; } if (!need_escape) { - rb_str_cat(str, s, len); + rb_str_buf_cat(str, s, len); } else { p = s; while (pptr->options & RE_OPTION_POSIXLINE) == RE_OPTION_POSIXLINE) - rb_str_cat2(str, "p"); + rb_str_buf_cat2(str, "p"); else if (RREGEXP(re)->ptr->options & RE_OPTION_MULTILINE) - rb_str_cat2(str, "m"); + rb_str_buf_cat2(str, "m"); if (RREGEXP(re)->ptr->options & RE_OPTION_IGNORECASE) - rb_str_cat2(str, "i"); + rb_str_buf_cat2(str, "i"); if (RREGEXP(re)->ptr->options & RE_OPTION_EXTENDED) - rb_str_cat2(str, "x"); + rb_str_buf_cat2(str, "x"); if (FL_TEST(re, KCODE_FIXED)) { switch ((RBASIC(re)->flags & KCODE_MASK)) { case KCODE_NONE: - rb_str_cat2(str, "n"); + rb_str_buf_cat2(str, "n"); break; case KCODE_EUC: - rb_str_cat2(str, "e"); + rb_str_buf_cat2(str, "e"); break; case KCODE_SJIS: - rb_str_cat2(str, "s"); + rb_str_buf_cat2(str, "s"); break; case KCODE_UTF8: - rb_str_cat2(str, "u"); + rb_str_buf_cat2(str, "u"); break; } } @@ -1171,8 +1171,13 @@ rb_reg_regsub(str, src, regs) } if (c != '\\' || s == e) continue; - if (!val) val = rb_str_new(p, ss-p); - else rb_str_cat(val, p, ss-p); + if (!val) { + val = rb_str_buf_new(ss-p); + rb_str_buf_cat(val, p, ss-p); + } + else { + rb_str_buf_cat(val, p, ss-p); + } c = *s++; p = s; @@ -1186,11 +1191,11 @@ rb_reg_regsub(str, src, regs) break; case '`': - rb_str_cat(val, RSTRING(src)->ptr, BEG(0)); + rb_str_buf_cat(val, RSTRING(src)->ptr, BEG(0)); continue; case '\'': - rb_str_cat(val, RSTRING(src)->ptr+END(0), RSTRING(src)->len-END(0)); + rb_str_buf_cat(val, RSTRING(src)->ptr+END(0), RSTRING(src)->len-END(0)); continue; case '+': @@ -1200,24 +1205,29 @@ rb_reg_regsub(str, src, regs) break; case '\\': - rb_str_cat(val, s-1, 1); + rb_str_buf_cat(val, s-1, 1); continue; default: - rb_str_cat(val, s-2, 2); + rb_str_buf_cat(val, s-2, 2); continue; } if (no >= 0) { if (no >= regs->num_regs) continue; if (BEG(no) == -1) continue; - rb_str_cat(val, RSTRING(src)->ptr+BEG(no), END(no)-BEG(no)); + rb_str_buf_cat(val, RSTRING(src)->ptr+BEG(no), END(no)-BEG(no)); } } if (p < e) { - if (!val) val = rb_str_new(p, e-p); - else rb_str_cat(val, p, e-p); + if (!val) { + val = rb_str_buf_new(e-p); + rb_str_buf_cat(val, p, e-p); + } + else { + rb_str_buf_cat(val, p, e-p); + } } if (!val) return str; -- cgit v1.2.3