diff options
| author | Jack Nagel | 2013-04-14 22:27:11 -0500 |
|---|---|---|
| committer | Jack Nagel | 2013-04-14 22:38:18 -0500 |
| commit | a78ae63153da85b4490c833a296b4c2009225e09 (patch) | |
| tree | d2211220f028b931b4763e6af3434812b951d006 /Library | |
| parent | 5e9cfec8b8d3d5b33c14e1f9167adee5fd478c51 (diff) | |
| download | brew-a78ae63153da85b4490c833a296b4c2009225e09.tar.bz2 | |
Performance fix for Pathname#prepend_prefix
See 05a456c231dc6da7cb0f7c70cb21feaf9a0d803c; same story.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/extend/pathname.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 1f6d6695d..07526f0a2 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -386,6 +386,9 @@ class Pathname end end + # We redefine these private methods in order to add the /o modifier to + # the Regexp literals, which forces string interpolation to happen only + # once instead of each time the method is called. This is fixed in 1.9+. if RUBY_VERSION <= "1.8.7" alias_method :old_chop_basename, :chop_basename def chop_basename(path) @@ -397,6 +400,20 @@ class Pathname end end private :chop_basename + + alias_method :old_prepend_prefix, :prepend_prefix + def prepend_prefix(prefix, relpath) + if relpath.empty? + File.dirname(prefix) + elsif /#{SEPARATOR_PAT}/o =~ prefix + prefix = File.dirname(prefix) + prefix = File.join(prefix, "") if File.basename(prefix + 'a') != 'a' + prefix + relpath + else + prefix + relpath + end + end + private :prepend_prefix end end |
