You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// does not need to be volatile, visibility piggy-backs on volatile read of `supplier`
49
-
privateTvalue;
54
+
privateTvalue; // will behave as a volatile in reality, because a supplier volatile read will update all fields (see https://www.cs.umd.edu/~pugh/java/memoryModel/jsr-133-faq.html#volatile)
50
55
51
56
// should not be called directly
52
57
privateLazy(Supplier<? extendsT> supplier) {
@@ -135,16 +140,13 @@ public Option<T> filter(Predicate<? super T> predicate) {
135
140
*/
136
141
@Override
137
142
publicTget() {
138
-
// using a local var speeds up the double-check idiom by 25%, see Effective Java, Item 71
139
-
Supplier<? extendsT> tmp = supplier;
140
-
if (tmp != null) {
141
-
synchronized (this) {
142
-
tmp = supplier;
143
-
if (tmp != null) {
144
-
value = tmp.get();
145
-
supplier = null; // free mem
146
-
}
147
-
}
143
+
return (supplier == null) ? value : computeValue();
0 commit comments