Added XPath::Compiler.compile_with_cache

This commit is contained in:
Yorick Peterse committed 2015-08-19 20:14:20 +02:00
1 parent 6d01adafc7
commit 3300a6df49
2 files changed
+38 -4

No files matched your search

+12
View File
@@ -9,9 +9,21 @@ module Oga
# recompiling the same expression over and over again.
#
class Compiler
# @return [Oga::LRU]
CACHE = LRU.new
# Wildcard for node names/namespace prefixes.
STAR = '*'
##
# Compiles and caches an AST.
#
# @see [#compile]
#
def self.compile_with_cache(ast)
CACHE.get_or_set(ast) { new.compile(ast) }
end
##
# Compiles an XPath AST into a Ruby Proc.
#