Skip to content

Commit 644e126

Browse files
stevenharmanrossta
authored andcommitted
Lazily detect the first matching path
NOTE: Requires Ruby >= 2.2
1 parent 05589e1 commit 644e126

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

lib/serviceworker/router.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ def any?
5151

5252
def match_route(env)
5353
path = env[PATH_INFO]
54-
@routes.each do |route|
55-
match = route.match(path) and return match
56-
end
57-
nil
54+
@routes.lazy.map { |route| route.match(path) }.detect(&:itself)
5855
end
5956
end
6057
end

0 commit comments

Comments
 (0)