Permalink
Browse files

removing ternary

  • Loading branch information...
tenderlove committed Nov 24, 2010
1 parent 1aaa8ed commit 0687b21de879d53157e52a2b688e34a1bd1e31f0
Showing with 1 addition and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/associations/has_many_association.rb
@@ -42,7 +42,7 @@ def count_records
# documented side-effect of the method that may avoid an extra SELECT.
@target ||= [] and loaded if count == 0
- @reflection.options[:limit] ? [@reflection.options[:limit], count].min : count
+ [@reflection.options[:limit], count].compact.min
end
def has_cached_counter?

5 comments on commit 0687b21

@parndt

This comment has been minimized.

Show comment Hide comment
@parndt

parndt Nov 24, 2010

Contributor

hah nice.

Contributor

parndt replied Nov 24, 2010

hah nice.

@gucki

This comment has been minimized.

Show comment Hide comment
@gucki

gucki Nov 24, 2010

I wonder that this should really be faster?

I wonder that this should really be faster?

@spastorino

This comment has been minimized.

Show comment Hide comment
@spastorino

spastorino Nov 24, 2010

Owner

One cool way could be

[@reflection.options[:limit] || count, count].min

but I think is a bit less readable

Owner

spastorino replied Nov 24, 2010

One cool way could be

[@reflection.options[:limit] || count, count].min

but I think is a bit less readable

@drogus

This comment has been minimized.

Show comment Hide comment
@drogus

drogus Nov 24, 2010

Member

From my simple benchmark, compact is a bit slower than ternary if @reflection.options[:limit] exists and 5 times slower if it does not exist.

Member

drogus replied Nov 24, 2010

From my simple benchmark, compact is a bit slower than ternary if @reflection.options[:limit] exists and 5 times slower if it does not exist.

@tjwallace

This comment has been minimized.

Show comment Hide comment
@tjwallace

tjwallace Nov 25, 2010

Just to follow up with the benchmark (I had a little time on my hands): https://gist.github.com/714786

Just to follow up with the benchmark (I had a little time on my hands): https://gist.github.com/714786

Please sign in to comment.