Skip to content

speed up new router implementation #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions lib/hanami/router/leaf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ class Leaf
#
# @api private
# @since 2.2.0
attr_reader :to, :params
attr_reader :to, :params, :matcher

# @api private
# @since 2.2.0
def initialize(route, to, constraints)
@route = route
@to = to
@constraints = constraints
@params = nil
@matcher = Mustermann.new(route, type: :rails, version: "5.0", capture: constraints)
end

# @api private
Expand All @@ -29,14 +28,6 @@ def match(path)

match
end

private

# @api private
# @since 2.2.0
def matcher
@matcher ||= Mustermann.new(@route, type: :rails, version: "5.0", capture: @constraints)
end
end
end
end
12 changes: 8 additions & 4 deletions lib/hanami/router/trie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Trie
# @since 2.0.0
def initialize
@root = Node.new
@segments_map = {}
end

# @api private
Expand Down Expand Up @@ -47,15 +48,18 @@ def find(path)

# @api private
# @since 2.0.0
SEGMENT_SEPARATOR = /\//
SEGMENT_SEPARATOR = "/"
private_constant :SEGMENT_SEPARATOR

# @api private
# @since 2.2.0
def segments_from(path)
_, *segments = path.split(SEGMENT_SEPARATOR)

segments
if @segments_map[path]
@segments_map[path]
else
_, *segments = path.split(SEGMENT_SEPARATOR)
@segments_map[path] = segments
end
end
end
end
Expand Down