# HG changeset patch # User Matthew Wild # Date 1288859859 0 # Node ID 1770f8aaf04af2c5fd3d98f0e7f8bedcb5c4fcf3 # Parent 1f0af8572f153364dc7109d2fd7c4306e4f3a0e9 util.logger: Remove my precious premature optimisation :( diff -r 1f0af8572f15 -r 1770f8aaf04a util/logger.lua --- a/util/logger.lua Tue Nov 02 22:23:07 2010 +0500 +++ b/util/logger.lua Thu Nov 04 08:37:39 2010 +0000 @@ -16,9 +16,6 @@ local name_sinks, level_sinks = {}, {}; local name_patterns = {}; --- Weak-keyed so that loggers are collected -local modify_hooks = setmetatable({}, { __mode = "k" }); - local make_logger; local outfunction = nil; @@ -54,26 +51,20 @@ local source_handlers = name_sinks[source_name]; - -- All your premature optimisation is belong to me! - local num_level_handlers, num_source_handlers = #level_handlers, source_handlers and #source_handlers; - local logger = function (message, ...) if source_handlers then - for i = 1,num_source_handlers do + for i = 1,#source_handlers do if source_handlers[i](source_name, level, message, ...) == false then return; end end end - for i = 1,num_level_handlers do + for i = 1,#level_handlers do level_handlers[i](source_name, level, message, ...); end end - -- To make sure our cached lengths stay in sync with reality - modify_hooks[logger] = function () num_level_handlers, num_source_handlers = #level_handlers, source_handlers and #source_handlers; end; - return logger; end @@ -97,10 +88,6 @@ end end for k in pairs(name_patterns) do name_patterns[k] = nil; end - - for _, modify_hook in pairs(modify_hooks) do - modify_hook(); - end end function add_level_sink(level, sink_function) @@ -109,10 +96,6 @@ else level_sinks[level][#level_sinks[level] + 1 ] = sink_function; end - - for _, modify_hook in pairs(modify_hooks) do - modify_hook(); - end end function add_name_sink(name, sink_function, exclusive) @@ -121,10 +104,6 @@ else name_sinks[name][#name_sinks[name] + 1] = sink_function; end - - for _, modify_hook in pairs(modify_hooks) do - modify_hook(); - end end function add_name_pattern_sink(name_pattern, sink_function, exclusive)