Skip to content

Commit

Permalink
AnnotationModel uses inefficient iteration over map (Fixes #21)
Browse files Browse the repository at this point in the history
AnnotationModel.cleanup(boolean, boolean) iterates over map with keyset
iterator and does lookup for every value from iterator. With ~10_000
annotations this is not fun anymore. Similar code in other places. That
can be improved by using entryset iterator.

See https://github.com/eclipse-platform/eclipse.platform.text/issues/21
  • Loading branch information
iloveeclipse committed May 6, 2022
1 parent 3e6937a commit db6a3b4
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -640,13 +640,13 @@ private void cleanup(boolean fireModelChanged, boolean forkNotification) {
fDocumentChanged= false;

ArrayList<Annotation> deleted= new ArrayList<>();
Iterator<Annotation> e= getAnnotationMap().keySetIterator();
IAnnotationMap annotations= getAnnotationMap();
while (e.hasNext()) {
Annotation a= e.next();
Position p= annotations.get(a);
Iterator<Entry<Annotation, Position>> iterator = annotations.entrySet().iterator();
while (iterator.hasNext()) {
Entry<Annotation, Position> entry= iterator.next();
Position p= entry.getValue();
if (p == null || p.isDeleted())
deleted.add(a);
deleted.add(entry.getKey());
}

if (fireModelChanged && forkNotification) {
Expand Down Expand Up @@ -789,10 +789,11 @@ public void removeAllAnnotations() {
protected void removeAllAnnotations(boolean fireModelChanged) {
IAnnotationMap annotations= getAnnotationMap();
if (fDocument != null) {
Iterator<Annotation> e= getAnnotationMap().keySetIterator();
Iterator<Entry<Annotation, Position>> e= getAnnotationMap().entrySet().iterator();
while (e.hasNext()) {
Annotation a= e.next();
Position p= annotations.get(a);
Entry<Annotation, Position> entry= e.next();
Annotation a= entry.getKey();
Position p= entry.getValue();
removePosition(fDocument, p);
// p.delete();
synchronized (getLockObject()) {
Expand Down

0 comments on commit db6a3b4

Please sign in to comment.