Permalink
Browse files

Use any instead of length

  • Loading branch information...
1 parent 3c81fc3 commit 1756629835d39f60ef4c96aff81ac503c71b98b7 @rahul100885 rahul100885 committed Nov 27, 2011
Showing with 1 addition and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -1239,7 +1239,7 @@ def extract_pg_identifier_from_name(name)
if match_data
rest = name[match_data[0].length, name.length]
rest = rest[1, rest.length] if rest.start_with? "."
- [match_data[1], (rest.length > 0 ? rest : nil)]
+ [match_data[1], (rest.any? ? rest : nil)]
end
end

5 comments on commit 1756629

Is it faster with :any? or only more readable?

Contributor

rahul100885 replied Nov 28, 2011

It is faster and and also readable. It is faster since it avoid a two different calls.

Do you have any benchmarks? I write some benchmark https://gist.github.com/1399594 but I don't know if it is proper for this case?

Member

josevalim replied Nov 28, 2011

any? is slower because Ruby adds a block that does { |object| object }, this is easy to prove if you do this:

[nil, nil, nil].any?

So if this was motivated on performance, it was the wrong motivation. Although performance barely makes a difference here, both options are fast enough. For me, it is more readable (and that is it).

Contributor

rahul100885 replied Nov 28, 2011

@fxn, @josevalim, @seban thanks for really teaching me and also letting me to think on those line which I have never tried. #3779 (comment)

Please sign in to comment.