From 545f83595445ffd1212cbe7f23e76f906b1ff4b4 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Mon, 5 Dec 2016 11:33:09 +0100 Subject: [PATCH] Decorating the model themselves (and not the class) makes more sense as it allows to decorate only some models or parts of models, which may be desirable sometimes. --- profiler.lua | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/profiler.lua b/profiler.lua index 6f63861..b95d750 100644 --- a/profiler.lua +++ b/profiler.lua @@ -48,22 +48,11 @@ function profiler.decor(model, functionsToDecorate) for _, name in pairs(functionsToDecorate) do model.accTime = {} - local functionTable = model - - -- We decorate the function where it is defined in the class - -- hierarchy, so we have to go up the metatables until we find - -- it with rawget - - while functionTable and not rawget(functionTable, name) do - functionTable = getmetatable(functionTable) - end - local nameOrig = name .. '__orig' - if functionTable[name] and not functionTable[nameOrig] then - print('Profiler decoring ' .. functionTable.__typename .. '.' .. name) - functionTable[nameOrig] = functionTable[name] - functionTable[name] = function(self, ...) + if model[name] and not model[nameOrig] then + model[nameOrig] = model[name] + model[name] = function(self, ...) local startTime = sys.clock() local result = { self[nameOrig](self, unpack({...})) } local endTime = sys.clock() -- 2.20.1