You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by David Causse <dc...@spotter.com> on 2011/12/14 12:29:59 UTC

Payload instance and byte buffer instance re-use

Hi,

Is it safe to reuse a Payload instance within a TokenStream/Filter? I 
think about something like this :

public final boolean incrementToken() throws IOException {
     [...]
     if(payloadAttribute.getPayload() == null) {
         payloadAttribute.setPayload(new Payload());
     }
     payloadAttribute.getPayload().setData(myWorkingBuffer, 0, 
myWorkingBufferLength);
     return true;
}

Before, I always passed a new Payload instance with a fresh byte[] copy, 
I'm testing this optimization and my first tests are successful. As I'm 
not aware of all indexing scenarios I'm afraid of some cases where 
payload instance or data could be buffered and then overwritten by 
myself while building the next token.

Thanks for your help.

-- 
David Causse
Spotter
http://www.spotter.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org