From c3eb09d60b372f067d701037badd649f066cddb9 Mon Sep 17 00:00:00 2001 From: Jack Xu Date: Mon, 14 Jul 2014 15:45:13 -0400 Subject: [PATCH] Use Newark Application class variables directly ## Use Newark Application class variables directly Currently, in a Newark app, three class variables `routes`, `before_hooks`, and `after_hooks` are used to store system-level variables. This PR is intended to leverage these class instance variables directly instead of creating a copy of these variables upon each request. The clear benefit is to presumably make it more efficient and smaller memory footprint. --- lib/newark/app.rb | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/newark/app.rb b/lib/newark/app.rb index 12f3fd2..ee6350d 100644 --- a/lib/newark/app.rb +++ b/lib/newark/app.rb @@ -46,13 +46,6 @@ def after(&block) attr_reader :request, :response - def initialize(*) - super - @before_hooks = self.class.instance_variable_get(:@before_hooks) - @after_hooks = self.class.instance_variable_get(:@after_hooks) - @routes = self.class.instance_variable_get(:@routes) - end - def call(env) dup._call(env) end @@ -94,7 +87,7 @@ def match_route end def routes - @routes[@request.request_method] + self.class.instance_variable_get(:@routes)[@request.request_method] end def exec(action) @@ -110,11 +103,11 @@ def exec_handler(handler) end def exec_before_hooks - exec_hooks @before_hooks + exec_hooks self.class.instance_variable_get(:@before_hooks) end def exec_after_hooks - exec_hooks @after_hooks + exec_hooks self.class.instance_variable_get(:@after_hooks) end def exec_hooks(hooks)