Skip to content

Commit

Permalink
AnnotationModel.cleanup() uses inefficient iteration over map, take 2
Browse files Browse the repository at this point in the history
AnnotationModel.cleanup() will lock on the map while iterating over map
and iterate via forEach() instead to iterate over keys if possible.

This halves iteration time spent in cleanup() on huge annotation models.

Fixes #892
  • Loading branch information
iloveeclipse committed Aug 1, 2023
1 parent 1bd79e4 commit a4eb7b8
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -640,13 +640,25 @@ 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);
if (p == null || p.isDeleted())
deleted.add(a);
Object mapLock = annotations.getLockObject();

if (mapLock == null) {
Iterator<Annotation> e= annotations.keySetIterator();
while (e.hasNext()) {
Annotation a= e.next();
Position p= annotations.get(a);
if (p == null || p.isDeleted())
deleted.add(a);
}
} else {
synchronized (mapLock) {
annotations.forEach((a, p) -> {
if (p == null || p.isDeleted()) {
deleted.add(a);
}
});
}
}

if (fireModelChanged && forkNotification) {
Expand Down

0 comments on commit a4eb7b8

Please sign in to comment.