-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AnnotationModel uses inefficient iteration over map, take 2
Introduced new IAnnotationMap2 interface that overrides default forEach() to synchronize on lock object. This halves iteration time spent in cleanup() on huge annotation models. Fixes #892
- Loading branch information
1 parent
1bd79e4
commit 907bfa9
Showing
4 changed files
with
81 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
bundles/org.eclipse.text/src/org/eclipse/jface/text/source/IAnnotationMap2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2000, 2015 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jface.text.source; | ||
|
||
|
||
import java.util.function.BiConsumer; | ||
|
||
import org.eclipse.jface.text.Position; | ||
|
||
|
||
/** | ||
* An {@link IAnnotationMap} that synchronizes {@link #forEach(BiConsumer)} on the | ||
* {@link #getLockObject()}. | ||
* | ||
* @since 3.14 | ||
*/ | ||
public interface IAnnotationMap2 extends IAnnotationMap { | ||
|
||
/** | ||
* Overridden to synchronize iteration on {@link #getLockObject()} | ||
* <p> | ||
* {@inheritDoc} | ||
*/ | ||
@Override | ||
default void forEach(BiConsumer<? super Annotation, ? super Position> action) { | ||
Object lockObject = getLockObject(); | ||
if (lockObject != null) { | ||
synchronized (lockObject) { | ||
IAnnotationMap.super.forEach(action); | ||
} | ||
} else { | ||
IAnnotationMap.super.forEach(action); | ||
} | ||
} | ||
} |
I think this iteration must be under same lock as the
getAnnotationModelEvent
invocation. Otherwise a thread in between might already have submitted the event (theoretically).