Libraryless. Click here for Pure Java version (5279L/29K).
1 | // synchronized |
2 | sclass MoreEfficientCopyOnWriteList<A> extends NotifyingList<A> { |
3 | bool hasIterator; |
4 | |
5 | *() { this(new L); } |
6 | |
7 | // Note: uses list as the inner list! |
8 | *(L<A> list) { super(list); } |
9 | |
10 | public synchronized Iterator<A> iterator() { |
11 | set hasIterator; |
12 | ret super.iterator(); |
13 | } |
14 | |
15 | public synchronized Spliterator<A> spliterator() { |
16 | set hasIterator; |
17 | ret super.spliterator(); |
18 | } |
19 | |
20 | public synchronized ListIterator<A> listIterator() { |
21 | set hasIterator; |
22 | ret super.listIterator(); |
23 | } |
24 | |
25 | public synchronized ListIterator<A> listIterator(int index) { |
26 | set hasIterator; |
27 | ret super.listIterator(index); |
28 | } |
29 | |
30 | @Override |
31 | // This is called in synchronized block |
32 | void beforeChange { |
33 | if (hasIterator) { |
34 | setInnerList(cloneList(list)); |
35 | hasIterator = false; |
36 | } |
37 | } |
38 | |
39 | void change {} |
40 | } |
Began life as a copy of #1033756
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034557 |
Snippet name: | MoreEfficientCopyOnWriteList - a better CopyOnWriteArrayList that only makes a copy when there is no iterator |
Eternal ID of this version: | #1034557/11 |
Text MD5: | 05fa41388e2bc75b3ee99446c138a4ac |
Transpilation MD5: | 1b0b301c141a41022c8c1cc3f0f3298c |
Author: | stefan |
Category: | javax / collections |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-13 18:40:34 |
Source code size: | 888 bytes / 40 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 144 / 254 |
Version history: | 10 change(s) |
Referenced in: | [show references] |