hg: lambda/lambda/jdk: - ensure null values are retained

Remi Forax forax at univ-mlv.fr
Tue Dec 4 06:12:21 PST 2012


On 12/04/2012 03:00 PM, Peter Levart wrote:
> Hi Remi, Paul,
>
> What about vice-versa:

Hi Peter,
good idea !
we still need a if (t==null) in accept() and not use Objects.equals 
because we want the VM to profile the null in accept() and not in 
Objects.equals().

Rémi

>
> Like this:
>
>         private static final Object NONE = new Object();
>         ...
>
>         return new Sink.ChainedReference<T>(sink) {
>             private Object lastSeen;
>
>             @Override
>             public void begin(long size) {
>                 lastSeen = NONE;            // not needed if end() is 
> called in a finally ?
>                 downstream.begin(-1);
>             }
>
>             @Override
>             public void end() {
>                 lastSeen = NONE;
>                 downstream.end();
>             }
>
>             @Override
>             public void accept(T t) {
>                 if (!Objects.equals(t, lastSeen)) {
>                     lastSeen = t;
>                     downstream.accept(t);
>                 }
>             }
>         };
>
>
> On 12/04/2012 02:26 PM, Remi Forax wrote:
>> I was thinking to something like this:
>>
>>               return new Sink.ChainedReference<T>(sink) {
>>                   private Object lastSeen;
>>
>>                   @Override
>>                   public void begin(long size) {
>>                       lastSeen = null;            // not needed if 
>> end() is called in a finally ?
>>                       downstream.begin(-1);
>>                   }
>>
>>                   @Override
>>                   public void end() {
>>                       lastSeen = null;
>>                       downstream.end();
>>                   }
>>
>>                   @Override
>>                   public void accept(T t) {
>>                       if (t == null) {
>>                           if (lastSeen != NULL_OBJECT) {
>>                               lastSeen = NULL_OBJECT
>>                               downstream.accept(null);
>>                           }
>>                       } else if (lastSeen == null || 
>> !t.equals(lastSeen)) {
>>                           lastSeen = t;
>>                           downstream.accept((T)t);
>>                       }
>>                   }
>>               };
>
>



More information about the lambda-dev mailing list