diff options
author | charliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-03-25 23:46:05 +0000 |
---|---|---|
committer | charliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-03-25 23:46:05 +0000 |
commit | a77206582e9372d748db3bbc85c9c3ab0c6681db (patch) | |
tree | 1610591c9696fb751b8d31eec1e24b985cf68d59 /re.c | |
parent | ebd9f1d0e485972ef778f5c7251b0e52694f3979 (diff) |
Stop allocating backref strings within gsub's search loop
* internal.h: add prototype for rb_reg_search0
* re.c: rename rb_reg_search to rb_reg_search0, add set_backref_str
argument to allow callers to indicate that they don't require the
backref string to be allocated
* string.c: don't allocate backref str if replacement string is provided
Closes GH-578. [Bug #9676] [ruby-core:61682]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45414 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 're.c')
-rw-r--r-- | re.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -1375,7 +1375,7 @@ rb_reg_adjust_startpos(VALUE re, VALUE str, long pos, int reverse) /* returns byte offset */ long -rb_reg_search(VALUE re, VALUE str, long pos, int reverse) +rb_reg_search0(VALUE re, VALUE str, long pos, int reverse, int set_backref_str) { long result; VALUE match; @@ -1450,17 +1450,26 @@ rb_reg_search(VALUE re, VALUE str, long pos, int reverse) FL_UNSET(match, FL_TAINT); } - RMATCH(match)->str = rb_str_new4(str); + if (set_backref_str) { + RMATCH(match)->str = rb_str_new4(str); + OBJ_INFECT(match, str); + } + RMATCH(match)->regexp = re; RMATCH(match)->rmatch->char_offset_updated = 0; rb_backref_set(match); OBJ_INFECT(match, re); - OBJ_INFECT(match, str); return result; } +long +rb_reg_search(VALUE re, VALUE str, long pos, int reverse) +{ + return rb_reg_search0(re, str, pos, reverse, 1); +} + VALUE rb_reg_nth_defined(int nth, VALUE match) { |