Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2019-08-16 10:59:49 -0400
committerPaul Pazderski2019-08-19 03:25:05 -0400
commitcbc3f41c5bbaeefe42ee458c5b8c50acb01085ba (patch)
tree3487490db227de722a88ad99ff2a9e757ab91180
parentc0daf761389a45a439c0cf3c2af1c68b22894308 (diff)
downloadeclipse.platform.text-I20190819-2355.tar.gz
eclipse.platform.text-I20190819-2355.tar.xz
eclipse.platform.text-I20190819-2355.zip
with copy-on-write approach For the old implementation when change forwarding is disabled the whole document content is copied and the line tracking information rebuild even if the document is not changed but only read. The new approach only copies the document if a change happens. Change-Id: I396a142d70268e33017117e9e99535ae37463b72 Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultDocumentAdapter.java53
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentClone.java40
2 files changed, 46 insertions, 47 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultDocumentAdapter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultDocumentAdapter.java
index cf417ce4d..769590535 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultDocumentAdapter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultDocumentAdapter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,6 +10,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Paul Pazderski - Bug 545252 - improve stop/resumeForwarding with copy-on-write approach
*******************************************************************************/
package org.eclipse.jface.text;
@@ -36,12 +37,17 @@ class DefaultDocumentAdapter implements IDocumentAdapter, IDocumentListener, IDo
/** The adapted document. */
private IDocument fDocument;
- /** The document clone for the non-forwarding case. */
- private IDocument fDocumentClone;
- /** The original content */
- private String fOriginalContent;
- /** The original line delimiters */
- private String[] fOriginalLineDelimiters;
+ /**
+ * The document to be used to read stuff. Most of the time this is equal to {@link #fDocument}.
+ * Only if non-forwarding is enabled and {@link #fDocument} was changed while non-forwarding
+ * {@link #fActiveDocument} points to a read-only copy of {@link #fDocument} with the content it
+ * had when change forwarding was disabled. I.e. this reference must always expected to be
+ * read-only.
+ *
+ * @see IDocumentAdapterExtension
+ * @see #fIsForwarding
+ */
+ private IDocument fActiveDocument;
/** The registered text change listeners */
private List<TextChangeListener> fTextChangeListeners= new ArrayList<>(1);
/**
@@ -92,19 +98,9 @@ class DefaultDocumentAdapter implements IDocumentAdapter, IDocumentListener, IDo
fDocument.removePrenotifiedDocumentListener(this);
fDocument= document;
+ fActiveDocument= fDocument;
fLineDelimiter= null;
- if (!fIsForwarding) {
- fDocumentClone= null;
- if (fDocument != null) {
- fOriginalContent= fDocument.get();
- fOriginalLineDelimiters= fDocument.getLegalLineDelimiters();
- } else {
- fOriginalContent= null;
- fOriginalLineDelimiters= null;
- }
- }
-
if (fDocument != null)
fDocument.addPrenotifiedDocumentListener(this);
}
@@ -151,16 +147,7 @@ class DefaultDocumentAdapter implements IDocumentAdapter, IDocumentListener, IDo
}
private IDocument getDocumentForRead() {
- if (!fIsForwarding) {
- if (fDocumentClone == null) {
- String content= fOriginalContent == null ? "" : fOriginalContent; //$NON-NLS-1$
- String[] delims= fOriginalLineDelimiters == null ? DefaultLineTracker.DELIMITERS : fOriginalLineDelimiters;
- fDocumentClone= new DocumentClone(content, delims);
- }
- return fDocumentClone;
- }
-
- return fDocument;
+ return fActiveDocument;
}
@Override
@@ -274,6 +261,9 @@ class DefaultDocumentAdapter implements IDocumentAdapter, IDocumentListener, IDo
@Override
public void documentAboutToBeChanged(DocumentEvent event) {
+ if (!fIsForwarding && fDocument == fActiveDocument) {
+ fActiveDocument= new DocumentClone(fActiveDocument.get(), fActiveDocument.getLegalLineDelimiters());
+ }
fRememberedLengthOfDocument= fDocument.getLength();
try {
@@ -377,17 +367,12 @@ class DefaultDocumentAdapter implements IDocumentAdapter, IDocumentListener, IDo
@Override
public void resumeForwardingDocumentChanges() {
fIsForwarding= true;
- fDocumentClone= null;
- fOriginalContent= null;
- fOriginalLineDelimiters= null;
+ fActiveDocument= fDocument;
fireTextSet();
}
@Override
public void stopForwardingDocumentChanges() {
- fDocumentClone= null;
- fOriginalContent= fDocument.get();
- fOriginalLineDelimiters= fDocument.getLegalLineDelimiters();
fIsForwarding= false;
}
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentClone.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentClone.java
index 84493304b..5dc45ba02 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentClone.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentClone.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * Copyright (c) 2000, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -10,9 +10,12 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Paul Pazderski - Bug 545252: cloned document was only partial read-only
*******************************************************************************/
package org.eclipse.jface.text;
+import java.util.Arrays;
+
import org.eclipse.core.runtime.Assert;
@@ -54,12 +57,13 @@ class DocumentClone extends AbstractDocument {
@Override
public void replace(int offset, int length, String text) {
+ // not allowed
}
@Override
public void set(String text) {
+ // not allowed
}
-
}
/**
@@ -72,20 +76,30 @@ class DocumentClone extends AbstractDocument {
super();
setTextStore(new StringTextStore(content));
- boolean hasDefaultDelims= lineDelimiters == null;
- if (!hasDefaultDelims && DefaultLineTracker.DELIMITERS.length == lineDelimiters.length) {
- hasDefaultDelims= true;
- for (int i= 0; i < lineDelimiters.length; i++) {
- if (DefaultLineTracker.DELIMITERS[i] != lineDelimiters[i]) {
- hasDefaultDelims= false;
- break;
- }
- }
- }
-
+ boolean hasDefaultDelims= Arrays.equals(lineDelimiters, DefaultLineTracker.DELIMITERS);
ILineTracker tracker= hasDefaultDelims ? new DefaultLineTracker() : new ConfigurableLineTracker(lineDelimiters);
setLineTracker(tracker);
getTracker().set(content);
completeInitialization();
}
+
+ @Override
+ public void replace(int pos, int length, String text) throws BadLocationException {
+ // not allowed
+ }
+
+ @Override
+ public void replace(int pos, int length, String text, long modificationStamp) throws BadLocationException {
+ // not allowed
+ }
+
+ @Override
+ public void set(String text) {
+ // not allowed
+ }
+
+ @Override
+ public void set(String text, long modificationStamp) {
+ //not allowed
+ }
}

Back to the top