Skip to content

Instantly share code, notes, and snippets.

@kzk
Created October 3, 2011 17:32
Show Gist options
  • Save kzk/1259689 to your computer and use it in GitHub Desktop.
Save kzk/1259689 to your computer and use it in GitHub Desktop.
match_cache.diff
diff --git a/lib/fluent/engine.rb b/lib/fluent/engine.rb
index 10e747c..6af8278 100644
--- a/lib/fluent/engine.rb
+++ b/lib/fluent/engine.rb
@@ -22,6 +22,7 @@ class EngineClass
def initialize
@matches = []
@sources = []
+ @match_cache = {}
end
def init
@@ -106,8 +107,12 @@ class EngineClass
end
def emit_stream(tag, es)
- if match = @matches.find {|m| m.match(tag) }
+ if @match_cache.has_key?(tag)
+ match = @match_cache[tag]
match.emit(tag, es)
+ elsif match = @matches.find {|m| m.match(tag) }
+ match.emit(tag, es)
+ @match_cache[tag] = match
else
$log.on_trace { $log.trace "no pattern matched", :tag=>tag }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment