diff options
| author | Xu Cheng | 2015-12-30 16:27:15 +0800 |
|---|---|---|
| committer | Xu Cheng | 2015-12-30 16:27:15 +0800 |
| commit | 24224dc8968e00fb48f2721ab480492da0668fd2 (patch) | |
| tree | 93b584378ada6881db9d1cdf962dbbec6dc018a5 /Library/Homebrew/extend/pathname.rb | |
| parent | 482481d24c7d66cdc2a6fdfb9933cf6fb7b429c9 (diff) | |
| download | brew-24224dc8968e00fb48f2721ab480492da0668fd2.tar.bz2 | |
pathname: improve compute_disk_usage
* Avoid parallel assignment.
* Use Pathname#size instead of File#size
* Use Pathname#directory? instead of File#directory?
* Use basename to check `.DS_Store`. Original regex has poor
performance, and may match with incorrect file.
Diffstat (limited to 'Library/Homebrew/extend/pathname.rb')
| -rw-r--r-- | Library/Homebrew/extend/pathname.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 7bdeb2188..0b54fdcf1 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -27,11 +27,12 @@ module DiskUsageExtension def compute_disk_usage if self.directory? - @file_count, @disk_usage = [0, 0] + @file_count = 0 + @disk_usage = 0 self.find do |f| - if !File.directory?(f) and !f.to_s.match(/\.DS_Store/) + if !f.directory? && f.basename.to_s != ".DS_Store" @file_count += 1 - @disk_usage += File.size(f) + @disk_usage += f.size end end else |
