Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* for simple cases like User.last and User.order('name desc').last no need to perform Array#join operation. * Instead of performing String#blank? do Array#empty? * no need to create variable relation
- Loading branch information
1 parent
e3d6434
commit fbd1d30
Showing
1 changed file
with
9 additions
and
10 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
fbd1d30
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.
Just a question, why removing
gsub!
andconcat
inreverse_sql_order
?fbd1d30
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.
so that code like "created_at, updated_at" works with User.last. Note that the whole thing is a string. Hence we need to split by a comma.
fbd1d30
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.
Yeah sure Neeraj, but I believe it'd be possible to return the
s
variable inside thecollect
, keeping the methods that changes the actual string, would not?fbd1d30
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.
Not sure if I am following you exactly. Can you post a gist or something?
fbd1d30
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.
Sure, here we go: http://gist.github.com/599566.
I also thought about some other possibilities to see what you think (didn't actually tested it), please take a look.
fbd1d30
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.
How about doing "Lazy gsub!": http://gist.github.com/599605?
fbd1d30
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 think I like the "lazy gsub!" . In all other cases first a regex check is being done and then gsub is being invoked. The "lazy gsub!" totally removes the need to do any regex check.
fbd1d30
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.
Yeah agreed, nice one!
fbd1d30
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.
Although the underlying assumption here is that gusb! is faster than regex. Unless there is benchmarking data I don't really know. May be someone from ruby core ( Aaron Patterson) might be able to tell which one is faster.
If regex turns out to be faster than gsub! then we should stick with regex approach. Otherwise switch to gsub! .
fbd1d30
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'd probably guess lazy gsub! to be slightly faster. I've also updated the gist (http://gist.github.com/599605) with a slightly better regexps, so somebody should run a bench and whip up a patch.
fbd1d30
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 have run a benchmark at http://gist.github.com/600385
It looks like the lazy gsub! is faster.
fbd1d30
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'm blown away by the result. That's significant perf improvement.