From 2ce70947b62d97926d4aa16c2cdae9c756772ab3 Mon Sep 17 00:00:00 2001 From: Jeremy Woertink Date: Tue, 5 Sep 2023 19:02:43 -0700 Subject: [PATCH] small performance improvement when generating a route url. Ref #1827 --- src/lucky/routable.cr | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/lucky/routable.cr b/src/lucky/routable.cr index e984869df..728a0d142 100644 --- a/src/lucky/routable.cr +++ b/src/lucky/routable.cr @@ -338,7 +338,6 @@ module Lucky::Routable \{% end %} end - private def self.path_from_parts( {% for param in path_params %} {{ param.gsub(/:/, "").id }}, @@ -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