Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce array allocations via ary.each_with_object #1916

Conversation

ashmaroli
Copy link
Contributor

What problem is this PR intended to solve?

Unnecessary object allocations:

  • array.map duplicates given Array array
  • Array#[] generates a new Array instance.

Therefore, Hash[array.map { |e| [e, foo] }] generates multiple interim arrays on each call and iteration.

Have you included adequate test coverage?

Not necessary since this is just refactoring existing implementation.

Does this change affect the C or the Java implementations?

Does not affect C or Java code

@codeclimate
Copy link

codeclimate bot commented Jul 26, 2019

Code Climate has analyzed commit 7888150 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (80% is the threshold).

This pull request will bring the total coverage in the repository to 93.8% (0.0% change).

View more on Code Climate.

flavorjones added a commit that referenced this pull request Nov 26, 2019
@flavorjones
Copy link
Member

Merged manually! Thank you!

@flavorjones
Copy link
Member

(see 63c2b74)

@flavorjones flavorjones added this to the v1.11.0 milestone Nov 26, 2019
@ashmaroli ashmaroli deleted the optimize-with-each-with-object branch November 26, 2019 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants