From 5f85fcc11f9e1e06139af2794b23df4169dc86a1 Mon Sep 17 00:00:00 2001 From: drbrain Date: Fri, 1 Jun 2012 22:05:46 +0000 Subject: [PATCH] * 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 --- ChangeLog | 6 ++++++ doc/re.rdoc | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 257f3a802b..401dd3a590 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sat Jun 2 07:04:48 2012 Eric Hodel + + * 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 * doc/re.rdoc (Performance): Removed useless sample output from final diff --git a/doc/re.rdoc b/doc/re.rdoc index a357d5c323..5f49ae228d 100644 --- a/doc/re.rdoc +++ b/doc/re.rdoc @@ -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 optional matches can succeed, but this fact unfortunately eludes Ruby. -One approach for improving performance is to anchor the match to the -beginning of the string, thus significantly reducing the amount of -backtracking needed. +The best way to improve performance is to significantly reduce the amount of +backtracking needed. For this case, instead of individually matching 29 +optional as, a range of optional as can be matched all at once +with a{0,29}: - Regexp.new('\A' 'a?' * 29 + 'a' * 29) =~ 'a' * 29 + Regexp.new('a{0,29}' + 'a' * 29) =~ 'a' * 29