-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use map and Hash[] instead of inject({})
- Loading branch information
Showing
1 changed file
with
1 addition
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a2b0b51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently this doesn't work in Ruby 1.8.6 (See #157)
a2b0b51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't even get the tests to run in 1.8.6. So is #157 still important?
a2b0b51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should totally revert it—the patch is faster in 1.8.7 but slower in 1.9
a2b0b51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just drop support for 1.8.6, but the regression in 1.9 (if for realz) seems like an issue. Maybe just do the old/boring new hash and assign keys rather than the one liner.
a2b0b51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any performance difference between the two versions is negligible. I am highly skeptical that this code is causing any bottlenecks.
Sure, we could drop support for Ruby 1.8.6, but issue #157 was created by a real person who is still using 1.8.6 and wants to use this gem and, apparently, reverting this change allows him to do so.
We, the people commenting on this commit, are all "edge riders" when it comes to upgrading software, but many newer users aren't using rvm and don't know how to upgrade Ruby on their system, which typically requires building from source. Keep in mind, Ruby 1.8.6 was the version that shipped with Mac OS X Leopard, so any non-upgrader with a two-year-old Mac is likely running 1.8.6 in development. I'm also pretty sure that 1.8.6 was the Ruby version that shipped with a number Linux distributions until recently.
If supporting 1.8.6 becomes a maintenance nightmare, I'd be the first to say we should drop it, but as long as the problems can be easily fixed and don't impose a significant burden on the existing codebase, I say we should make our best effort to support it.
a2b0b51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I misspoke when I said this commit makes the method slower under 1.9. This commit should be faster under 1.8.7 or 1.9.
In my 1.9 benchmark, using
inject
andmerge
takes about 50% longer thanmap
andHash[]
. Using[]=
in theinject
loop is about 10% faster thanmap
andHash[]
(thanks to optimizations toinject
in 1.9).a2b0b51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still can't fire up the ol' 1.8.6 tests but I can't imagine there being much wrong with plain vanilla
each
and[]=
:jnunemaker/twitter@b285705
a2b0b51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Laserlemon is correct—
each
and[]=
is most efficient in every Ruby implementation. It is also very clear.That's the pattern used in Rails.
Regarding 1.8.6, I was able to run the test suite successfully. Try modifying the gem dependencies to specify exactly
rack
version 1.1.0 (and not a newer version).