summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpelder2006-08-23 18:47:38 (EDT)
committer pelder2006-08-23 18:47:38 (EDT)
commitb3129cd0fbfa7a43d713703c840b4c831cd15ac1 (patch)
tree875e7d14360ece788a479dd14f4fafd981624780
parent119c859a7c7e1b9c0489073795e4e29386316603 (diff)
downloadorg.eclipse.jet-b3129cd0fbfa7a43d713703c840b4c831cd15ac1.zip
org.eclipse.jet-b3129cd0fbfa7a43d713703c840b4c831cd15ac1.tar.gz
org.eclipse.jet-b3129cd0fbfa7a43d713703c840b4c831cd15ac1.tar.bz2
[154932] Improve append performance on writer
-rw-r--r--plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java72
1 files changed, 69 insertions, 3 deletions
diff --git a/plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java b/plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java
index 3751bcc..530be94 100644
--- a/plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java
+++ b/plugins/org.eclipse.jet/src/org/eclipse/jet/BodyContentWriter.java
@@ -25,11 +25,13 @@ import java.util.Map;
import org.eclipse.jet.internal.InternalJET2Platform;
import org.eclipse.jet.taglib.JET2TagException;
+import org.eclipse.jface.text.AbstractDocument;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DefaultLineTracker;
import org.eclipse.jface.text.DefaultPositionUpdater;
-import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextStore;
import org.eclipse.jface.text.Position;
@@ -40,10 +42,74 @@ import org.eclipse.jface.text.Position;
public class BodyContentWriter implements JET2Writer
{
- // private StringBuffer buffer = new StringBuffer();
+ /**
+ * IDocument implementationt that is optimized for appending.
+ */
+ private static class StringBufferDocument extends AbstractDocument
+ {
+ public StringBufferDocument() {
+ super();
+ setTextStore(new StringBufferTextStore());
+ setLineTracker(new DefaultLineTracker());
+ completeInitialization();
+ }
+ }
+
+/**
+ * Simple text store optimized for appending
+ */
+ private static class StringBufferTextStore implements ITextStore
+ {
+
+ private final StringBuffer buffer = new StringBuffer();
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.ITextStore#get(int)
+ */
+ public char get(int offset)
+ {
+ return buffer.charAt(offset);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.ITextStore#get(int, int)
+ */
+ public String get(int offset, int length)
+ {
+ return buffer.substring(offset, offset + length);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.text.ITextStore#set(java.lang.String)
+ */
+ public void set(String text)
+ {
+ buffer.replace(0, buffer.length(), text);
+ }
+
+ public int getLength()
+ {
+ return buffer.length();
+ }
+
+ public void replace(int offset, int length, String text)
+ {
+ if(offset == buffer.length() && length == 0)
+ {
+ buffer.append(text);
+ }
+ else
+ {
+ buffer.replace(offset, offset + length, text);
+ }
+ }
+
+ }
+
+// private StringBuffer buffer = new StringBuffer();
private final BodyContentWriter parentWriter;
- private final IDocument document = new Document();
+ private final IDocument document = new StringBufferDocument();
private final Map listeners;