I agree we should not introduce a condition here. this extra branch is totally unnecessary.
simon On Wed, Sep 7, 2011 at 3:49 PM, Uwe Schindler <[email protected]> wrote: > ...but slower, as you have to check the return value millions of times. For > this type of early exit conditions, exceptions are better, as they only > change control flow if they are throwed. If you preallocate the exception, > the time for fill-in stack trace is minimized. With Java 7 throwable has new > ctor to prevent this without reusing. > -- > Uwe Schindler > H.-H.-Meier-Allee 63, 28213 Bremen > http://www.thetaphi.de > > > > Martijn v Groningen <[email protected]> schrieb: >> >> I think that a boolean or enum as return value is neater (api wise) than >> throwing an expection. >> >> On 7 September 2011 15:34, Anne Veling <[email protected]> wrote: >>> >>> Yes, I saw that. I would expect that to be slower. It also would not >>> always work as expected if the collector would be combined in a booleanquery >>> I guess. >>> Anne n >>> >>> On Wed, Sep 7, 2011 at 15:29, Robert Muir <[email protected]> wrote: >>>> >>>> On Wed, Sep 7, 2011 at 9:09 AM, Anne Veling <[email protected]> >>>> wrote: >>>> > Ah thanks. I will make the change, ensure all tests are succeeding, >>>> > add some >>>> > tests of my own, and commit a patch. Would be great to get a feeling >>>> > of the >>>> > performance impact. >>>> > The change I'm making is changing the Collector interface from >>>> > public void collect(int doc) to >>>> > public boolean collect(int doc) >>>> > With a default "false" return code. If a collector returns "true" the >>>> > caller >>>> > may stop collecting. So all normal collectors would simply return >>>> > "false". >>>> > This could introduce some performance overhead of adding a return >>>> > value to >>>> > the call stack, and some checking in the calling code. >>>> > However, for some other use cases, like >>>> > >>>> >>>> usually the trick here to stop collecting is to throw a >>>> runtimeexception (your own subclass that you can catch), like >>>> timelimitingcollector. >>>> >>>> -- >>>> lucidimagination.com >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: [email protected] >>>> For additional commands, e-mail: [email protected] >>>> >>> >>> >>> >>> -- >>> Anne Veling >>> BeyondTrees.com >>> +31 6 50 969 170 >>> @anneveling >>> >> >> >> >> -- >> Met vriendelijke groet, >> >> Martijn van Groningen > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
