Skip to content
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

small performance improvement when generating a route url. #1829

Merged
merged 1 commit into from
Sep 15, 2023
Merged
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
17 changes: 7 additions & 10 deletions src/lucky/routable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ module Lucky::Routable
\{% end %}
end


private def self.path_from_parts(
{% for param in path_params %}
{{ param.gsub(/:/, "").id }},
Expand All @@ -351,22 +350,20 @@ module Lucky::Routable
{% for part in path_parts %}
{% if part.starts_with?("?:") %}
if {{ part.gsub(/^\?:/, "").id }}
path << "/"
path << URI.encode_www_form({{ part.gsub(/^\?:/, "").id }}.to_param)
path << '/'
URI.encode_www_form({{ part.gsub(/^\?:/, "").id }}.to_param, path)
end
{% elsif part.starts_with?(':') %}
path << "/"
path << URI.encode_www_form({{ part.gsub(/:/, "").id }}.to_param)
path << '/'
URI.encode_www_form({{ part.gsub(/:/, "").id }}.to_param, path)
{% else %}
path << "/"
path << URI.encode_www_form({{ part }})
path << '/'
URI.encode_www_form({{ part }}, path)
{% end %}
{% end %}
end

is_root_path = path == ""
path = "/" if is_root_path
path
path.presence || "/"
end
end

Expand Down
Loading