mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Reuse match data
* string.c (rb_str_split_m): reuse occupied match data. [Bug #16024]
This commit is contained in:
parent
adf13625ae
commit
1d1f98d49c
3 changed files with 12 additions and 2 deletions
|
@ -2040,6 +2040,7 @@ long rb_reg_search0(VALUE, VALUE, long, int, int);
|
||||||
VALUE rb_reg_match_p(VALUE re, VALUE str, long pos);
|
VALUE rb_reg_match_p(VALUE re, VALUE str, long pos);
|
||||||
bool rb_reg_start_with_p(VALUE re, VALUE str);
|
bool rb_reg_start_with_p(VALUE re, VALUE str);
|
||||||
void rb_backref_set_string(VALUE string, long pos, long len);
|
void rb_backref_set_string(VALUE string, long pos, long len);
|
||||||
|
void rb_match_unbusy(VALUE);
|
||||||
int rb_match_count(VALUE match);
|
int rb_match_count(VALUE match);
|
||||||
int rb_match_nth_defined(int nth, VALUE match);
|
int rb_match_nth_defined(int nth, VALUE match);
|
||||||
VALUE rb_reg_new_ary(VALUE ary, int options);
|
VALUE rb_reg_new_ary(VALUE ary, int options);
|
||||||
|
|
6
re.c
6
re.c
|
@ -1292,6 +1292,12 @@ rb_match_busy(VALUE match)
|
||||||
FL_SET(match, MATCH_BUSY);
|
FL_SET(match, MATCH_BUSY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rb_match_unbusy(VALUE match)
|
||||||
|
{
|
||||||
|
FL_UNSET(match, MATCH_BUSY);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_match_count(VALUE match)
|
rb_match_count(VALUE match)
|
||||||
{
|
{
|
||||||
|
|
7
string.c
7
string.c
|
@ -8085,9 +8085,11 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
||||||
long idx;
|
long idx;
|
||||||
int last_null = 0;
|
int last_null = 0;
|
||||||
struct re_registers *regs;
|
struct re_registers *regs;
|
||||||
|
VALUE match = 0;
|
||||||
|
|
||||||
while ((end = rb_reg_search(spat, str, start, 0)) >= 0) {
|
for (; (end = rb_reg_search(spat, str, start, 0)) >= 0;
|
||||||
VALUE match = rb_backref_get();
|
(match ? (rb_match_unbusy(match), rb_backref_set(match)) : (void)0)) {
|
||||||
|
match = rb_backref_get();
|
||||||
if (!result) rb_match_busy(match);
|
if (!result) rb_match_busy(match);
|
||||||
regs = RMATCH_REGS(match);
|
regs = RMATCH_REGS(match);
|
||||||
if (start == end && BEG(0) == END(0)) {
|
if (start == end && BEG(0) == END(0)) {
|
||||||
|
@ -8120,6 +8122,7 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
||||||
}
|
}
|
||||||
if (!NIL_P(limit) && lim <= ++i) break;
|
if (!NIL_P(limit) && lim <= ++i) break;
|
||||||
}
|
}
|
||||||
|
if (match) rb_match_unbusy(match);
|
||||||
}
|
}
|
||||||
if (RSTRING_LEN(str) > 0 && (!NIL_P(limit) || RSTRING_LEN(str) > beg || lim < 0)) {
|
if (RSTRING_LEN(str) > 0 && (!NIL_P(limit) || RSTRING_LEN(str) > beg || lim < 0)) {
|
||||||
SPLIT_STR(beg, RSTRING_LEN(str)-beg);
|
SPLIT_STR(beg, RSTRING_LEN(str)-beg);
|
||||||
|
|
Loading…
Add table
Reference in a new issue