Add memoization to lazy param parsing
This commit is contained in:
parent
4ee4b66135
commit
043d1c8aa2
2 changed files with 5 additions and 3 deletions
|
@ -2,7 +2,6 @@
|
||||||
# information such as params, content_type e.g
|
# information such as params, content_type e.g
|
||||||
class HTTP::Server
|
class HTTP::Server
|
||||||
class Context
|
class Context
|
||||||
|
|
||||||
def params
|
def params
|
||||||
@request.url_params = route_lookup.params
|
@request.url_params = route_lookup.params
|
||||||
@params ||= Kemal::ParamParser.new(@request)
|
@params ||= Kemal::ParamParser.new(@request)
|
||||||
|
|
|
@ -18,7 +18,12 @@ class Kemal::ParamParser
|
||||||
|
|
||||||
{% for method in %w(url query body json) %}
|
{% for method in %w(url query body json) %}
|
||||||
def {{method.id}}
|
def {{method.id}}
|
||||||
|
# check memoization
|
||||||
|
return @{{method.id}} if @{{method.id}}_parsed
|
||||||
|
|
||||||
parse_{{method.id}}
|
parse_{{method.id}}
|
||||||
|
# memoize
|
||||||
|
@{{method.id}}_parsed = true
|
||||||
@{{method.id}}
|
@{{method.id}}
|
||||||
end
|
end
|
||||||
{% end %}
|
{% end %}
|
||||||
|
@ -67,6 +72,4 @@ class Kemal::ParamParser
|
||||||
end
|
end
|
||||||
part_params
|
part_params
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue