// synchronized
sclass MoreEfficientCopyOnWriteList extends NotifyingList {
bool hasIterator;
*() { this(new L); }
// Note: uses list as the inner list!
*(L list) { super(list); }
public synchronized Iterator iterator() {
set hasIterator;
ret super.iterator();
}
public synchronized Spliterator spliterator() {
set hasIterator;
ret super.spliterator();
}
public synchronized ListIterator listIterator() {
set hasIterator;
ret super.listIterator();
}
public synchronized ListIterator listIterator(int index) {
set hasIterator;
ret super.listIterator(index);
}
@Override
// This is called in synchronized block
void beforeChange {
if (hasIterator) {
setInnerList(cloneList(list));
hasIterator = false;
}
}
void change {}
}