Skip to content

Commit

Permalink
[BEAM-XXX] Make KVCoder more efficient by removing unnecessary nesting
Browse files Browse the repository at this point in the history
See [BEAM-469] for more information about why this is
correct.
  • Loading branch information
dhalperi committed Dec 21, 2016
1 parent 57d9bbd commit 621e825
Showing 1 changed file with 8 additions and 14 deletions.
Expand Up @@ -83,17 +83,15 @@ public void encode(KV<K, V> kv, OutputStream outStream, Context context)
if (kv == null) {
throw new CoderException("cannot encode a null KV");
}
Context nestedContext = context.nested();
keyCoder.encode(kv.getKey(), outStream, nestedContext);
valueCoder.encode(kv.getValue(), outStream, nestedContext);
keyCoder.encode(kv.getKey(), outStream, context.nested());
valueCoder.encode(kv.getValue(), outStream, context);
}

@Override
public KV<K, V> decode(InputStream inStream, Context context)
throws IOException, CoderException {
Context nestedContext = context.nested();
K key = keyCoder.decode(inStream, nestedContext);
V value = valueCoder.decode(inStream, nestedContext);
K key = keyCoder.decode(inStream, context.nested());
V value = valueCoder.decode(inStream, context);
return KV.of(key, value);
}

Expand Down Expand Up @@ -135,10 +133,8 @@ public CloudObject asCloudObject() {
*/
@Override
public boolean isRegisterByteSizeObserverCheap(KV<K, V> kv, Context context) {
return keyCoder.isRegisterByteSizeObserverCheap(kv.getKey(),
context.nested())
&& valueCoder.isRegisterByteSizeObserverCheap(kv.getValue(),
context.nested());
return keyCoder.isRegisterByteSizeObserverCheap(kv.getKey(), context.nested())
&& valueCoder.isRegisterByteSizeObserverCheap(kv.getValue(), context);
}

/**
Expand All @@ -152,9 +148,7 @@ public void registerByteSizeObserver(
if (kv == null) {
throw new CoderException("cannot encode a null KV");
}
keyCoder.registerByteSizeObserver(
kv.getKey(), observer, context.nested());
valueCoder.registerByteSizeObserver(
kv.getValue(), observer, context.nested());
keyCoder.registerByteSizeObserver(kv.getKey(), observer, context.nested());
valueCoder.registerByteSizeObserver(kv.getValue(), observer, context);
}
}

0 comments on commit 621e825

Please sign in to comment.