提交 69ea2e49 authored 作者: noelgrandin@gmail.com's avatar noelgrandin@gmail.com

avoid unnecessary store operation

上级 6c89887a
...@@ -89,11 +89,11 @@ public final class ImmutableArray2<K> implements Iterable<K> { ...@@ -89,11 +89,11 @@ public final class ImmutableArray2<K> implements Iterable<K> {
boolean extendable; boolean extendable;
if (index == len - 1) { if (index == len - 1) {
AtomicBoolean x = canExtend; AtomicBoolean x = canExtend;
// can set it to null early - we anyway if (x != null) {
// reset the flag, so it is no longer useful // can set it to null early - we anyway
canExtend = null; // reset the flag, so it is no longer useful
if (array.length > index && x != null) { canExtend = null;
if (x.getAndSet(false)) { if (array.length > index && x.getAndSet(false)) {
array[index] = obj; array[index] = obj;
return new ImmutableArray2<K>(array, len, true); return new ImmutableArray2<K>(array, len, true);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论