diff --git a/platform/platform-api/src/com/intellij/openapi/editor/LazyRangeMarkerFactory.java b/platform/platform-api/src/com/intellij/openapi/editor/LazyRangeMarkerFactory.java index ea7beabfed99..d9a9b532eaab 100644 --- a/platform/platform-api/src/com/intellij/openapi/editor/LazyRangeMarkerFactory.java +++ b/platform/platform-api/src/com/intellij/openapi/editor/LazyRangeMarkerFactory.java @@ -27,7 +27,8 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.WeakList; import org.jetbrains.annotations.NotNull; -import java.util.Iterator; +import java.util.ArrayList; +import java.util.List; /** * Date: Mar 17, 2009 @@ -39,14 +40,16 @@ public class LazyRangeMarkerFactory extends AbstractProjectComponent { super(project); EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new DocumentAdapter() { public void beforeDocumentChange(DocumentEvent e) { - for (Iterator it = myMarkers.iterator(); it.hasNext();) { - final LazyMarker marker = it.next(); + List markers = myMarkers.toStrongList(); + List markersToRemove = new ArrayList(); + for (final LazyMarker marker : markers) { final VirtualFile docFile = fileDocumentManager.getFile(e.getDocument()); if (marker.getFile() == docFile) { marker.ensureDelegate(); - it.remove(); + markersToRemove.add(marker); } } + myMarkers.removeAll(markersToRemove); } }, project); } diff --git a/platform/util/src/com/intellij/util/containers/WeakList.java b/platform/util/src/com/intellij/util/containers/WeakList.java index 0691a02d68b2..3bb72781c520 100644 --- a/platform/util/src/com/intellij/util/containers/WeakList.java +++ b/platform/util/src/com/intellij/util/containers/WeakList.java @@ -76,6 +76,13 @@ public class WeakList extends AbstractList { } } + @Override + public boolean removeAll(Collection c) { + synchronized (myArray) { + return super.removeAll(c); + } + } + public Iterator iterator() { return new MyIterator(); } @@ -88,7 +95,7 @@ public class WeakList extends AbstractList { public List toStrongList() { synchronized (myArray) { - List result = new ArrayList(); + List result = new ArrayList(myArray.size()); myArray.toStrongCollection(result); return result; }