diff options
| author | Jack Nagel | 2013-04-14 21:50:57 -0500 |
|---|---|---|
| committer | Jack Nagel | 2013-04-14 21:56:04 -0500 |
| commit | 05a456c231dc6da7cb0f7c70cb21feaf9a0d803c (patch) | |
| tree | 14435232356124def593c8eef932f799395c4b5f /Library | |
| parent | 0bb33f8b10886277845d1193f7139307cdceed57 (diff) | |
| download | homebrew-05a456c231dc6da7cb0f7c70cb21feaf9a0d803c.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')
| -rw-r--r-- | Library/Homebrew/extend/pathname.rb | 12 |
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 |
