codenoble / cache-crispies

Speedy Rails JSON serialization with built-in caching
MIT License
156 stars 14 forks source link

Optimization: Prefer Enumerable#flat_map #26

Closed the-spectator closed 4 years ago

the-spectator commented 4 years ago

We can avoid extra iterations by using Enumerable#flat_map

Before:

attribute_names.flatten.map { |att| att&.to_sym }.map { ... }

After:

attribute_names.flat_map do |att|
  att = att&.to_sym
  ...
end
codeclimate[bot] commented 4 years ago

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

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

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

View more on Code Climate.

adamcrown commented 4 years ago

Good catch. Thank you!