mxcl/homebrew — pull request #19216 by jacknagel (2013-04-15 17:04:12+00:00)
Title: Avoid Pathname concatenation when possible

I spent some time profiling Homebrew yesterday using `brew readall`, and I discovered that we were spending *well* over 50% of the time concatenating Pathnames.

If you think about all of the places we do this, and then look at the method that is ultimately responsible, you'll understand why:

https://github.com/ruby/ruby/blob/582ba0a57c40be0dcda5f66fa18d28188d6d66f1/ext/pathname/lib/pathname.rb#L334

Here is a comparison of different methods of building up pathnames: https://gist.github.com/jacknagel/5386023

Notice that interpolating existing Pathnames into a string and then creating a new Pathname from that string is much, much faster than joining or concatenating them. Now, `join` and `+` handle cases other than simple concatenation, like concatenating ".." and returning the parent, but we never do this, so we can just interpolate everything and save a bunch of cycles.

The stuff I pushed yesterday plus these patches eliminates all calls to `Pathname#+`, either directly or indirectly, and reduces the time it takes to run `brew readall` by **~56%**.

The upshot is that we should never concatenate pathnames in core code (it's fine to continue doing it in formulae install methods).