Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
tab: use cache to avoid rereading the same files.
Browse files Browse the repository at this point in the history
Closes #46400.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
  • Loading branch information
MikeMcQuaid committed Nov 27, 2015
1 parent 24763f0 commit d6b3125
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Library/Homebrew/tab.rb
Expand Up @@ -9,6 +9,11 @@
# `Tab.create`.
class Tab < OpenStruct
FILENAME = "INSTALL_RECEIPT.json"
CACHE = {}

def self.clear_cache
CACHE.clear
end

def self.create(formula, compiler, stdlib, build)
attributes = {
Expand All @@ -32,7 +37,7 @@ def self.create(formula, compiler, stdlib, build)
end

def self.from_file(path)
from_file_content(File.read(path), path)
CACHE.fetch(path) { |p| CACHE[p] = from_file_content(File.read(p), p) }
end

def self.from_file_content(content, path)
Expand Down Expand Up @@ -217,6 +222,7 @@ def to_json
end

def write
CACHE[tabfile] = self
tabfile.atomic_write(to_json)
end

Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/test/test_formula_installer.rb
Expand Up @@ -20,10 +20,12 @@ def temporary_install(formula)
assert_predicate formula, :installed?

begin
Tab.clear_cache
refute_predicate Tab.for_keg(keg), :poured_from_bottle

yield formula
ensure
Tab.clear_cache
keg.unlink
keg.uninstall
formula.clear_cache
Expand Down

0 comments on commit d6b3125

Please sign in to comment.