roda 3.46.0 → 3.47.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5fd9ea4a9be8072ffc96e5bab91a845e99cc9a9d6641571167badd4146c93318
4
- data.tar.gz: ed062be1d4b922ba39456f3868e599e3c6134fecfedaa3bfc780667bfec5c5f2
3
+ metadata.gz: 7cad702e3b962a1e1b64e631ef77ea1ccca4eb1c630f1ac2e73b5c169b505744
4
+ data.tar.gz: f6576f0bd8b1a921435121ce9043a04f04f5560eca7a2eb93f5f39500a62dc1b
5
5
  SHA512:
6
- metadata.gz: 59e5677db771776107744f2438505b467363b410d6b2c8d19b1b11e802bfd15b22974997b20185e9ba3a1c9a7b8721bb5e3dbc1481a575f0812300c9c3241cac
7
- data.tar.gz: 6233ec5251cfbeeaabdb44a7cba75d4831910215ae8239ec19873f58a62f14722bb6b57059f0814ae07e7ccc50977e3a2fbf74bb3b423a253b7dace5773c6887
6
+ metadata.gz: 7def8965cb5ce9b12c96d16f2edb4e4428b41367b91ebfb20132332b87b04fceba29fdb537ea91c25eda7cc72d07ba3d329d12c073746309b125275d8cc616ad
7
+ data.tar.gz: 7acab06b22c80a697e4e250b857544aa337fcdf9a1c2065adae61cac4d1d17171ea374300104855e192fc4700d39d5c8fb9ebe7e8ee2ebc5d00fd6776c7a9f64
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ = 3.47.0 (2021-08-13)
2
+
3
+ * Automatically optimize remaining r.on calls with a single argument (jeremyevans)
4
+
1
5
  = 3.46.0 (2021-07-12)
2
6
 
3
7
  * Automatically optimize r.on/r.is/r.get/r.post methods with a single string, String, Integer, or regexp argument (jeremyevans)
@@ -0,0 +1,13 @@
1
+ = Improvements
2
+
3
+ * The r.on optimization added in 3.46.0 has been extended to optimize
4
+ all single argument calls. This results in the following speedups
5
+ based on argument type:
6
+
7
+ * Hash matching: 10%
8
+ * Array/Symbol/Class matching: 15%
9
+ * Proc matching: 25%
10
+ * true matching: 45%
11
+ * false/nil matching: 65%
12
+
13
+ * Other minor performance improvements have been made.
data/lib/roda.rb CHANGED
@@ -213,7 +213,7 @@ class Roda
213
213
  plugin :direct_call
214
214
  end
215
215
 
216
- if ([:on, :is, :_verb, :_match_class_String, :_match_class_Integer, :_match_string, :_match_regexp, :empty_path?]).all?{|m| self::RodaRequest.instance_method(m).owner == RequestMethods}
216
+ if ([:on, :is, :_verb, :_match_class_String, :_match_class_Integer, :_match_string, :_match_regexp, :empty_path?, :if_match, :match, :_match_class]).all?{|m| self::RodaRequest.instance_method(m).owner == RequestMethods}
217
217
  plugin :_optimized_matching
218
218
  end
219
219
  end
@@ -52,20 +52,60 @@ class Roda
52
52
  end
53
53
  end
54
54
  elsif matcher == Integer
55
- if matchdata = @remaining_path.match(/\A\/(\d+)(?=\/|\z)/)
55
+ if matchdata = /\A\/(\d+)(?=\/|\z)/.match(@remaining_path)
56
56
  @remaining_path = matchdata.post_match
57
57
  always{yield(matchdata[1].to_i)}
58
58
  end
59
59
  else
60
- if_match(args, &block)
60
+ path = @remaining_path
61
+ captures = @captures.clear
62
+ meth = :"_match_class_#{matcher}"
63
+ if respond_to?(meth, true)
64
+ # Allow calling private methods, as match methods are generally private
65
+ if send(meth, &block)
66
+ block_result(yield(*captures))
67
+ throw :halt, response.finish
68
+ else
69
+ @remaining_path = path
70
+ false
71
+ end
72
+ else
73
+ unsupported_matcher(matcher)
74
+ end
61
75
  end
62
76
  when Regexp
63
- if matchdata = @remaining_path.match(self.class.cached_matcher(matcher){matcher})
77
+ if matchdata = self.class.cached_matcher(matcher){matcher}.match(@remaining_path)
64
78
  @remaining_path = matchdata.post_match
65
79
  always{yield(*matchdata.captures)}
66
80
  end
81
+ when true
82
+ always(&block)
83
+ when false, nil
84
+ # nothing
67
85
  else
68
- if_match(args, &block)
86
+ path = @remaining_path
87
+ captures = @captures.clear
88
+
89
+ matched = case matcher
90
+ when Array
91
+ _match_array(matcher)
92
+ when Hash
93
+ _match_hash(matcher)
94
+ when Symbol
95
+ _match_symbol(matcher)
96
+ when Proc
97
+ matcher.call
98
+ else
99
+ unsupported_matcher(matcher)
100
+ end
101
+
102
+ if matched
103
+ block_result(yield(*captures))
104
+ throw :halt, response.finish
105
+ else
106
+ @remaining_path = path
107
+ false
108
+ end
69
109
  end
70
110
  when 0
71
111
  always(&block)
@@ -111,7 +151,7 @@ class Roda
111
151
  always{yield rp[1, len]}
112
152
  end
113
153
  elsif matcher == Integer
114
- if matchdata = @remaining_path.match(/\A\/(\d+)\z/)
154
+ if matchdata = /\A\/(\d+)\z/.match(@remaining_path)
115
155
  @remaining_path = ''
116
156
  always{yield(matchdata[1].to_i)}
117
157
  end
@@ -119,7 +159,7 @@ class Roda
119
159
  if_match(args << TERM, &block)
120
160
  end
121
161
  when Regexp
122
- if (matchdata = @remaining_path.match(self.class.cached_matcher(matcher){matcher})) && (post_match = matchdata.post_match).empty?
162
+ if (matchdata = self.class.cached_matcher(matcher){matcher}.match(@remaining_path)) && matchdata.post_match.empty?
123
163
  @remaining_path = ''
124
164
  always{yield(*matchdata.captures)}
125
165
  end
@@ -566,7 +566,7 @@ class Roda
566
566
  end
567
567
  false
568
568
  when Regexp
569
- if md = content.match(val)
569
+ if md = val.match(content)
570
570
  @captures.concat(md.captures)
571
571
  end
572
572
  else
@@ -184,7 +184,7 @@ class Roda
184
184
  path = super
185
185
 
186
186
  if opts[:use_extension]
187
- if m = path.match(opts[:extension_regexp])
187
+ if m = opts[:extension_regexp].match(path)
188
188
  @type_routing_extension = @requested_type = m[2].to_sym
189
189
  path = m[1]
190
190
  end
data/lib/roda/request.rb CHANGED
@@ -517,7 +517,7 @@ class Roda
517
517
  # SCRIPT_NAME to include the matched path, removes the matched
518
518
  # path from PATH_INFO, and updates captures with any regex captures.
519
519
  def consume(pattern)
520
- if matchdata = @remaining_path.match(pattern)
520
+ if matchdata = pattern.match(@remaining_path)
521
521
  @remaining_path = matchdata.post_match
522
522
  captures = matchdata.captures
523
523
  captures = yield(*captures) if block_given?
data/lib/roda/version.rb CHANGED
@@ -4,7 +4,7 @@ class Roda
4
4
  RodaMajorVersion = 3
5
5
 
6
6
  # The minor version of Roda, updated for new feature releases of Roda.
7
- RodaMinorVersion = 46
7
+ RodaMinorVersion = 47
8
8
 
9
9
  # The patch version of Roda, updated only for bug fixes from the last
10
10
  # feature release.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.46.0
4
+ version: 3.47.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-12 00:00:00.000000000 Z
11
+ date: 2021-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -217,6 +217,7 @@ extra_rdoc_files:
217
217
  - doc/release_notes/3.44.0.txt
218
218
  - doc/release_notes/3.45.0.txt
219
219
  - doc/release_notes/3.46.0.txt
220
+ - doc/release_notes/3.47.0.txt
220
221
  - doc/release_notes/3.5.0.txt
221
222
  - doc/release_notes/3.6.0.txt
222
223
  - doc/release_notes/3.7.0.txt
@@ -270,6 +271,7 @@ files:
270
271
  - doc/release_notes/3.44.0.txt
271
272
  - doc/release_notes/3.45.0.txt
272
273
  - doc/release_notes/3.46.0.txt
274
+ - doc/release_notes/3.47.0.txt
273
275
  - doc/release_notes/3.5.0.txt
274
276
  - doc/release_notes/3.6.0.txt
275
277
  - doc/release_notes/3.7.0.txt