aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/extend/pathname.rb
diff options
context:
space:
mode:
authorJack Nagel2013-04-14 21:50:57 -0500
committerJack Nagel2013-04-14 21:56:04 -0500
commit5e9cfec8b8d3d5b33c14e1f9167adee5fd478c51 (patch)
treef006c7acabc4e8830189d72f3447010895ad9504 /Library/Homebrew/extend/pathname.rb
parent1bad199776c5225cf685cd5443041cb8c303ef0c (diff)
downloadbrew-5e9cfec8b8d3d5b33c14e1f9167adee5fd478c51.tar.bz2
Performance fix for Pathname#chop_basename
This is an internal method, but is called a bunch of times in performance-critical codepaths, and is ultra slow because the constant is interpoplated into the Regexp each time the method is called. Alas, this has been fixed in Ruby 1.9+.
Diffstat (limited to 'Library/Homebrew/extend/pathname.rb')
-rw-r--r--Library/Homebrew/extend/pathname.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb
index 1f384db73..1f6d6695d 100644
--- a/Library/Homebrew/extend/pathname.rb
+++ b/Library/Homebrew/extend/pathname.rb
@@ -386,6 +386,18 @@ class Pathname
end
end
+ if RUBY_VERSION <= "1.8.7"
+ alias_method :old_chop_basename, :chop_basename
+ def chop_basename(path)
+ base = File.basename(path)
+ if /\A#{Pathname::SEPARATOR_PAT}?\z/o =~ base
+ return nil
+ else
+ return path[0, path.rindex(base)], base
+ end
+ end
+ private :chop_basename
+ end
end
# sets $n and $d so you can observe creation of stuff