From: Daniel Kolesa Date: Thu, 16 Feb 2017 15:06:56 +0000 (+0100) Subject: docgen: cache class retrievals for performance X-Git-Tag: upstream/1.20.0~1974 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b9090529e5e573499138fd1ad90982300abf77fd;p=platform%2Fupstream%2Fefl.git docgen: cache class retrievals for performance --- diff --git a/src/scripts/elua/apps/docgen/doctree.lua b/src/scripts/elua/apps/docgen/doctree.lua index 042dcab..7b48808 100644 --- a/src/scripts/elua/apps/docgen/doctree.lua +++ b/src/scripts/elua/apps/docgen/doctree.lua @@ -10,6 +10,16 @@ local writer local M = {} +local get_cache = function(o, nm) + local ret = o[nm] + if not ret then + ret = {} + o[nm] = ret + return ret, false + end + return ret, true +end + M.Node = util.Object:clone { scope = { UNKNOWN = eolian.object_scope.UNKNOWN, @@ -256,25 +266,41 @@ M.Class = Node:clone { -- static getters by_name_get = function(name) + local stor = get_cache(M.Class, "_cache_bn") + local ret = stor[name] + if ret then + return ret + end local v = eolian.class_get_by_name(name) if not v then return nil end - return M.Class(v) + ret = M.Class(v) + stor[name] = ret + return ret end, by_file_get = function(name) + local stor = get_cache(M.Class, "_cache_bf") + local ret = stor[name] + if ret then + return ret + end local v = eolian.class_get_by_file(name) if not v then return nil end - return M.Class(v) + ret = M.Class(v) + stor[name] = ret + return ret end, all_get = function() - local ret = {} - for cl in eolian.all_classes_get() do - ret[#ret + 1] = M.Class(cl) + local ret, had = get_cache(M.Class, "_cache_all") + if not had then + for cl in eolian.all_classes_get() do + ret[#ret + 1] = M.Class(cl) + end end return ret end