From 5e9cfec8b8d3d5b33c14e1f9167adee5fd478c51 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Sun, 14 Apr 2013 21:50:57 -0500 Subject: [PATCH] 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+. --- Library/Homebrew/extend/pathname.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 1f384db734..1f6d6695da 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