Skip to content

Commit

Permalink
small performance improvement when generating a route url. Ref #1827 (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoertink authored Sep 15, 2023
1 parent ab0db6a commit 0bcc91f
Showing 1 changed file with 7 additions and 10 deletions.
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

0 comments on commit 0bcc91f

Please sign in to comment.