-
-
Notifications
You must be signed in to change notification settings - Fork 92
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
speed up new router implementation #279
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -17,6 +17,7 @@ class Trie | |||
# @since 2.0.0 | ||||
def initialize | ||||
@root = Node.new | ||||
@segments_map = {} | ||||
end | ||||
|
||||
# @api private | ||||
|
@@ -47,15 +48,20 @@ 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) | ||||
if @segments_map[path] | ||||
@segments_map[path] | ||||
else | ||||
_, *segments = path.split(SEGMENT_SEPARATOR) | ||||
|
||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an empty line here that should be removed, and the contents of the |
||||
@segments_map[path] = segments | ||||
segments | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Hash assignment returns the value being assigned so I don't think this last line does anything |
||||
end | ||||
end | ||||
end | ||||
end | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change related? If the params are often not empty, then this check is slower than just merging the empty hash. If if it's often empty then it can be a useful optimization, but I think we should discuss that separately to decide if the tradeoff is worth it. I guess it might be negligible either way.