From 8a80d148cc1843c934474e77189bece212979fa8 Mon Sep 17 00:00:00 2001 From: Martin Jobst Date: Fri, 22 Nov 2024 07:15:20 +0100 Subject: [PATCH] Avoid unnecessary lock on UI thread with no model listeners #3251 Avoid unnecessarily aquiring a lock on the UI thread if there are no model listeners in the Xtext document. Signed-off-by: Martin Jobst --- .../src/org/eclipse/xtext/ui/editor/model/XtextDocument.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/model/XtextDocument.java b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/model/XtextDocument.java index 312b83b85c6..3559142a43e 100755 --- a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/model/XtextDocument.java +++ b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/editor/model/XtextDocument.java @@ -563,6 +563,11 @@ protected T internalReadOnly(IUnitOfWork work, boolean isC * changing while they run. To achieve this, we run the {@link IXtextModelListener}s on the UI thread. */ private void notifyModelListenersOnUiThread() { + synchronized (modelListeners) { + if (modelListeners.isEmpty()) { + return; + } + } Display display = PlatformUI.getWorkbench().getDisplay(); if (Thread.currentThread() == display.getThread()) { // We are already running on the display thread. Run the listeners immediately.