hg: lambda/lambda/jdk: - ensure null values are retained
Remi Forax
forax at univ-mlv.fr
Tue Dec 4 05:26:03 PST 2012
On 12/04/2012 11:44 AM, Paul Sandoz wrote:
> Hi Remi,
>
> Many thanks, that is just the kind of VM-perspective advice i was looking for. I was assuming that the VM would be able to somehow inline the hot path to the else block.
yes, but you don't need a supplementary field for that.
>
> So you are suggesting something like this:
>
> T _t = (T) maskNull(t);
> if (lastSeen == null || !lastSeen.equals(_t)) {
> lastSeen = _t;
> downstream.accept(t);
> }
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);
}
}
};
>
> rather than:
>
> if (t == null) {
> if (!seenNull) {
> seenNull = true;
> downstream.accept(lastSeen = null);
> }
> } else if (lastSeen == null || !t.equals(lastSeen)) {
> downstream.accept(lastSeen = t);
> }
>
> Paul.
Rémi
More information about the lambda-dev
mailing list