- // Helpers split out of codecMember to aid its inlining
- private Object loadKey(final AtomicReferenceFieldUpdater<CodecDataObject<?>, Object> updater,
- final IdentifiableItemCodec codec) {
- verify(data instanceof MapEntryNode, "Unsupported value %s", data);
- return updateCache(updater, codec.deserialize(((MapEntryNode) data).getIdentifier()).getKey());
+ // Helper split out of codecKey to aid its inlining
+ private @NonNull Object loadKey(final VarHandle handle) {
+ if (!(data instanceof MapEntryNode mapEntry)) {
+ throw new VerifyException("Unsupported value " + data);
+ }
+ if (!(context instanceof MapCodecContext<?, ?> listContext)) {
+ throw new VerifyException("Unexpected context " + context);
+ }
+
+ final Object obj = listContext.deserialize(mapEntry.name());
+ // key is known to be non-null, no need to mask it
+ final Object witness = handle.compareAndExchangeRelease(this, null, obj);
+ return witness == null ? obj : witness;