On Apr 14, 5:09 pm, mooman <[email protected]> wrote:
> > +      if cond.responds_to?(:empty?) && cond.empty?
> > +        clone
> > +      else
>
> how about more of an "optimistic" test like:
>
> if (cond.empty? rescue false)
>   clone
> end

"Blind rescue missions" should only be used in extreme cases, IMO.

> dont know how pretty that is, but should generally be faster than
> checking if the receiver responds to a method then call it, and should
> work the same, right?

I'm not sure.  You could benchmark it.  Unused rescues still have some
overhead I think, though I'm not sure how they compare to respond_to?

> the only place where it would be much slower is if your cond really
> doesn't respond to empty?, but how likely is it that cond responds to
> "size" (the first line of that method), but not to "empty?". Then
> again, i dont know much of Sequel's inner-workings.

cond will always respond to size as the _filter method uses the *cond
as the second argument.  Unless you undefine Array#size, and I think
Sequel will be the least of your problems if you do that.

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to