From 4ee4b66135bba66101ceaed703f1a9d34a5682e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20Kadir=20Ak=C4=B1n?= Date: Sun, 6 Mar 2016 22:29:23 +0200 Subject: [PATCH] Make the param getters lazy to improve performance --- src/kemal/param_parser.cr | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/kemal/param_parser.cr b/src/kemal/param_parser.cr index c383689..69459cc 100644 --- a/src/kemal/param_parser.cr +++ b/src/kemal/param_parser.cr @@ -9,26 +9,19 @@ class Kemal::ParamParser URL_ENCODED_FORM = "application/x-www-form-urlencoded" APPLICATION_JSON = "application/json" - getter url - getter query - getter body - getter json - def initialize(@request) @url = {} of String => String @query = {} of String => String @body = {} of String => String @json = {} of String => AllParamTypes - - parse_request end - def parse_request - parse_query - parse_body - parse_json - parse_url_params + {% for method in %w(url query body json) %} + def {{method.id}} + parse_{{method.id}} + @{{method.id}} end + {% end %} def parse_body return if (@request.headers["Content-Type"]? =~ /#{URL_ENCODED_FORM}/).nil? @@ -39,7 +32,7 @@ class Kemal::ParamParser @query = parse_part(@request.query) end - def parse_url_params + def parse_url if params = @request.url_params params.each do |key, value| @url[key as String] = value as String