Skip to content

Commit 4a90c7a

Browse files
committed
Check constraints exist before call #any?
This short circuits `#any?`, which shows up as ~2-3% of the benchmark even though the `constraints` are empty.
1 parent 81f1ca2 commit 4a90c7a

File tree

1 file changed

+17
-15
lines changed
  • actionpack/lib/action_dispatch/journey

1 file changed

+17
-15
lines changed

actionpack/lib/action_dispatch/journey/route.rb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,23 @@ def dispatcher?
167167
end
168168

169169
def matches?(request)
170-
@request_method_match.call(request) &&
171-
constraints.all? { |method, value|
172-
case value
173-
when Regexp, String
174-
value === request.send(method).to_s
175-
when Array
176-
value.include?(request.send(method))
177-
when TrueClass
178-
request.send(method).present?
179-
when FalseClass
180-
request.send(method).blank?
181-
else
182-
value === request.send(method)
183-
end
184-
}
170+
@request_method_match.call(request) && (
171+
constraints.empty? ||
172+
constraints.all? { |method, value|
173+
case value
174+
when Regexp, String
175+
value === request.send(method).to_s
176+
when Array
177+
value.include?(request.send(method))
178+
when TrueClass
179+
request.send(method).present?
180+
when FalseClass
181+
request.send(method).blank?
182+
else
183+
value === request.send(method)
184+
end
185+
}
186+
)
185187
end
186188

187189
def ip

0 commit comments

Comments
 (0)