mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (str_gsub): move rb_enc_get(str) to out of loop.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4e4d4331ca
commit
3e2fe4a1eb
2 changed files with 10 additions and 4 deletions
|
@ -1,3 +1,7 @@
|
|||
Mon Jan 7 18:10:33 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* string.c (str_gsub): move rb_enc_get(str) to out of loop.
|
||||
|
||||
Mon Jan 7 15:52:10 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* include/ruby/oniguruma.h (OnigEncodingType): new member
|
||||
|
|
10
string.c
10
string.c
|
@ -2684,6 +2684,7 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
|
|||
int iter = 0;
|
||||
char *sp, *cp;
|
||||
int tainted = 0;
|
||||
rb_encoding *str_enc;
|
||||
|
||||
switch (argc) {
|
||||
case 1:
|
||||
|
@ -2712,6 +2713,7 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
|
|||
sp = RSTRING_PTR(str);
|
||||
slen = RSTRING_LEN(str);
|
||||
cp = sp;
|
||||
str_enc = rb_enc_get(str);
|
||||
|
||||
do {
|
||||
n++;
|
||||
|
@ -2734,7 +2736,7 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
|
|||
if (OBJ_TAINTED(val)) tainted = 1;
|
||||
|
||||
len = beg - offset; /* copy pre-match substr */
|
||||
rb_enc_str_buf_cat(dest, cp, len, rb_enc_get(str));
|
||||
rb_enc_str_buf_cat(dest, cp, len, str_enc);
|
||||
|
||||
rb_enc_str_buf_cat(dest, RSTRING_PTR(val), RSTRING_LEN(val), rb_enc_get(val));
|
||||
RB_GC_GUARD(val);
|
||||
|
@ -2746,8 +2748,8 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
|
|||
* in order to prevent infinite loops.
|
||||
*/
|
||||
if (RSTRING_LEN(str) <= END(0)) break;
|
||||
len = rb_enc_mbclen(RSTRING_PTR(str)+END(0), RSTRING_END(str), rb_enc_get(str));
|
||||
rb_enc_str_buf_cat(dest, RSTRING_PTR(str)+END(0), len, rb_enc_get(str));
|
||||
len = rb_enc_mbclen(RSTRING_PTR(str)+END(0), RSTRING_END(str), str_enc);
|
||||
rb_enc_str_buf_cat(dest, RSTRING_PTR(str)+END(0), len, str_enc);
|
||||
offset = END(0) + len;
|
||||
}
|
||||
cp = RSTRING_PTR(str) + offset;
|
||||
|
@ -2755,7 +2757,7 @@ str_gsub(int argc, VALUE *argv, VALUE str, int bang)
|
|||
beg = rb_reg_search(pat, str, offset, 0);
|
||||
} while (beg >= 0);
|
||||
if (RSTRING_LEN(str) > offset) {
|
||||
rb_enc_str_buf_cat(dest, cp, RSTRING_LEN(str) - offset, rb_enc_get(str));
|
||||
rb_enc_str_buf_cat(dest, cp, RSTRING_LEN(str) - offset, str_enc);
|
||||
}
|
||||
rb_backref_set(match);
|
||||
if (bang) {
|
||||
|
|
Loading…
Add table
Reference in a new issue