Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Zarnekow2020-04-14 07:32:54 +0000
committerSebastian Zarnekow2020-04-14 07:32:54 +0000
commit2f7536d74aaf4c8f0e9e6718bf672bec6dc99bd4 (patch)
treedb996d0abf02a93bf5de48d441b1bf4daa50606d
parent7c2ce92e127de0823b2898ade7ee9074efde222b (diff)
downloadeclipse.platform.text-I20200415-0620.tar.gz
eclipse.platform.text-I20200415-0620.tar.xz
eclipse.platform.text-I20200415-0620.zip
Over the lifecycle of a document, many more document events are processed than modifications happen to the registered position updaters. Therefore it is beneficial to avoid a defensive copy on each read but use a CopyOnWriteArrayList instead to allow iteration while concurrently modifying the position updaters. The change does also contain a little bit of cleanup when working with the instance field fPositionUpdaters within AbstractDocument. Change-Id: Id09b72ef70c872530aab6dd01c5e64abc4fbfb6c Signed-off-by: Sebastian Zarnekow <sebastian.zarnekow@gmail.com>
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java24
1 files changed, 8 insertions, 16 deletions
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java b/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java
index b73f4b1ad..b94cc7e5e 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java
@@ -22,6 +22,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.regex.PatternSyntaxException;
import org.eclipse.core.runtime.Assert;
@@ -293,7 +294,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
fPositions= new HashMap<>();
fEndPositions= new HashMap<>();
- fPositionUpdaters= new ArrayList<>();
+ fPositionUpdaters= new CopyOnWriteArrayList<>();
fDocumentListeners= new ListenerList<>(ListenerList.IDENTITY);
fPrenotifiedDocumentListeners= new ListenerList<>(ListenerList.IDENTITY);
fDocumentPartitioningListeners= new ListenerList<>(ListenerList.IDENTITY);
@@ -951,9 +952,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
@Override
public IPositionUpdater[] getPositionUpdaters() {
- IPositionUpdater[] updaters= new IPositionUpdater[fPositionUpdaters.size()];
- fPositionUpdaters.toArray(updaters);
- return updaters;
+ return fPositionUpdaters.toArray(new IPositionUpdater[fPositionUpdaters.size()]);
}
@Override
@@ -971,16 +970,12 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
@Override
public void insertPositionUpdater(IPositionUpdater updater, int index) {
-
- for (int i= fPositionUpdaters.size() - 1; i >= 0; i--) {
- if (fPositionUpdaters.get(i) == updater)
+ for (IPositionUpdater u: fPositionUpdaters) {
+ if (u == updater) {
return;
+ }
}
-
- if (index == fPositionUpdaters.size())
- fPositionUpdaters.add(updater);
- else
- fPositionUpdaters.add(index, updater);
+ fPositionUpdaters.add(index, updater);
}
@Override
@@ -1154,10 +1149,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
* the positions
*/
protected void updatePositions(DocumentEvent event) {
- List<IPositionUpdater> list= new ArrayList<>(fPositionUpdaters);
- Iterator<IPositionUpdater> e= list.iterator();
- while (e.hasNext()) {
- IPositionUpdater u= e.next();
+ for(IPositionUpdater u: fPositionUpdaters) {
u.update(event);
}
}

Back to the top