public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Eliminate excess Regexp creation due to capture counting
jeremy (author)
Mon Nov 10 19:53:53 -0800 2008
commit  278b6cd9529f33286449a9be18f1903687814d3f
tree    7ecff6aeef0e2b9b956e8d2b9902cc21aa872183
parent  5db9f9b3ad47fadf0b3f12ada1c2ea7b9c15ded5
...
219
220
221
222
 
223
224
225
...
219
220
221
 
222
223
224
225
0
@@ -219,7 +219,7 @@ module ActionController
0
           next_capture = 1
0
           extraction = segments.collect do |segment|
0
             x = segment.match_extraction(next_capture)
0
-            next_capture += Regexp.new(segment.regexp_chunk).number_of_captures
0
+            next_capture += segment.number_of_captures
0
             x
0
           end
0
           extraction.compact
...
13
14
15
 
 
 
 
16
17
18
...
84
85
86
 
 
 
 
87
88
89
...
194
195
196
 
 
 
 
 
 
 
 
197
198
199
200
 
201
202
203
...
230
231
232
 
 
 
 
233
234
235
...
275
276
277
 
 
 
 
278
279
280
...
13
14
15
16
17
18
19
20
21
22
...
88
89
90
91
92
93
94
95
96
97
...
202
203
204
205
206
207
208
209
210
211
212
213
 
 
 
214
215
216
217
...
244
245
246
247
248
249
250
251
252
253
...
293
294
295
296
297
298
299
300
301
302
0
@@ -13,6 +13,10 @@ module ActionController
0
         @is_optional = false
0
       end
0
 
0
+      def number_of_captures
0
+        Regexp.new(regexp_chunk).number_of_captures
0
+      end
0
+
0
       def extraction_code
0
         nil
0
       end
0
@@ -84,6 +88,10 @@ module ActionController
0
         optional? ? Regexp.optionalize(chunk) : chunk
0
       end
0
 
0
+      def number_of_captures
0
+        0
0
+      end
0
+
0
       def build_pattern(pattern)
0
         escaped = Regexp.escape(value)
0
         if optional? && ! pattern.empty?
0
@@ -194,10 +202,16 @@ module ActionController
0
         end
0
       end
0
 
0
+      def number_of_captures
0
+        if regexp
0
+          regexp.number_of_captures + 1
0
+        else
0
+          1
0
+        end
0
+      end
0
+
0
       def build_pattern(pattern)
0
-        chunk = regexp_chunk
0
-        chunk = "(#{chunk})" if Regexp.new(chunk).number_of_captures == 0
0
-        pattern = "#{chunk}#{pattern}"
0
+        pattern = "#{regexp_chunk}#{pattern}"
0
         optional? ? Regexp.optionalize(pattern) : pattern
0
       end
0
 
0
@@ -230,6 +244,10 @@ module ActionController
0
         "(?i-:(#{(regexp || Regexp.union(*possible_names)).source}))"
0
       end
0
 
0
+      def number_of_captures
0
+        1
0
+      end
0
+
0
       # Don't URI.escape the controller name since it may contain slashes.
0
       def interpolation_chunk(value_code = local_name)
0
         "\#{#{value_code}.to_s}"
0
@@ -275,6 +293,10 @@ module ActionController
0
         regexp || "(.*)"
0
       end
0
 
0
+      def number_of_captures
0
+        regexp ? regexp.number_of_captures : 1
0
+      end
0
+
0
       def optionality_implied?
0
         true
0
       end

Comments