Changeset

3554:1770f8aaf04a

util.logger: Remove my precious premature optimisation :(
author Matthew Wild <mwild1@gmail.com>
date Thu, 04 Nov 2010 08:37:39 +0000
parents 3553:1f0af8572f15
children 3555:6938b6153890
files util/logger.lua
diffstat 1 files changed, 2 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- 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)