1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* doc/re.rdoc (Performance): Replaced incorrect example of reducing

backtracking through anchoring with reduced backtracking through a
  range.  [ruby-trunk - Bug #6525]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2012-06-01 22:05:46 +00:00
parent 5c56ae7f81
commit 5f85fcc11f
2 changed files with 11 additions and 4 deletions

View file

@ -1,3 +1,9 @@
Sat Jun 2 07:04:48 2012 Eric Hodel <drbrain@segment7.net>
* doc/re.rdoc (Performance): Replaced incorrect example of reducing
backtracking through anchoring with reduced backtracking through a
range. [ruby-trunk - Bug #6525]
Sat Jun 2 06:34:15 2012 Eric Hodel <drbrain@segment7.net> Sat Jun 2 06:34:15 2012 Eric Hodel <drbrain@segment7.net>
* doc/re.rdoc (Performance): Removed useless sample output from final * doc/re.rdoc (Performance): Removed useless sample output from final

View file

@ -640,9 +640,10 @@ repeatedly so as to satisfy as many of the optional matches as it can
while still matching the mandatory 29. It is plain to us that none of the while still matching the mandatory 29. It is plain to us that none of the
optional matches can succeed, but this fact unfortunately eludes Ruby. optional matches can succeed, but this fact unfortunately eludes Ruby.
One approach for improving performance is to anchor the match to the The best way to improve performance is to significantly reduce the amount of
beginning of the string, thus significantly reducing the amount of backtracking needed. For this case, instead of individually matching 29
backtracking needed. optional <i>a</i>s, a range of optional <i>a</i>s can be matched all at once
with <i>a{0,29}</i>:
Regexp.new('\A' 'a?' * 29 + 'a' * 29) =~ 'a' * 29 Regexp.new('a{0,29}' + 'a' * 29) =~ 'a' * 29