...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 <martijn.v.gronin...@gmail.com> 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 <a...@beyondtrees.com> 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 <rcm...@gmail.com> wrote: On Wed, Sep 7, 2011 at 9:09 AM, Anne Veling <a...@beyondtrees.com> 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: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org -- Anne Veling BeyondTrees.com +31 6 50 969 170 @anneveling -- Met vriendelijke groet, Martijn van Groningen