ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1795697 - in /webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer: Serializer.java writer/ASCIICompatibleXmlWriter.java
Date Sun, 21 May 2017 12:50:18 GMT
Author: veithen
Date: Sun May 21 12:50:18 2017
New Revision: 1795697

URL: http://svn.apache.org/viewvc?rev=1795697&view=rev
Log:
More optimizations.

Modified:
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/Serializer.java
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java

Modified: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/Serializer.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/Serializer.java?rev=1795697&r1=1795696&r2=1795697&view=diff
==============================================================================
--- webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/Serializer.java
(original)
+++ webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/Serializer.java
Sun May 21 12:50:18 2017
@@ -330,6 +330,9 @@ public final class Serializer implements
         if (length == 0)
             return;
         
+        final XmlWriter writer = this.writer;
+        final int context = this.context;
+        
         String illegalCharacterSequence = illegalCharacterSequences[context];
         if (illegalCharacterSequence != null) {
             int matchedIllegalCharacters = this.matchedIllegalCharacters;
@@ -376,7 +379,7 @@ public final class Serializer implements
             final int end = start + length;
             int lastDirtyCharProcessed = start - 1; // last non-clean character that was
processed
 													// that was processed
-
+            int squareBrackets = this.squareBrackets;
             for (i = start; i < end; i++) {
                 char ch = chars[i];
                 String replacement = null;
@@ -471,6 +474,7 @@ public final class Serializer implements
                 int lengthClean = i - startClean;
                 writer.write(chars, startClean, lengthClean);
             }
+            this.squareBrackets = squareBrackets;
         } catch (IOException ex) {
             throw new StreamException(ex);
         }

Modified: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java?rev=1795697&r1=1795696&r2=1795697&view=diff
==============================================================================
--- webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java
(original)
+++ webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java
Sun May 21 12:50:18 2017
@@ -24,7 +24,7 @@ import java.io.OutputStream;
 abstract class ASCIICompatibleXmlWriter extends XmlWriter {
     private final OutputStream out;
     private final byte[] buffer = new byte[4096];
-    private int len;
+    private int bufferPosition;
     private char highSurrogate;
     
     ASCIICompatibleXmlWriter(OutputStream out) {
@@ -34,19 +34,19 @@ abstract class ASCIICompatibleXmlWriter
     protected abstract void writeNonASCIICharacter(int codePoint) throws IOException;
 
     protected final void writeByte(byte b) throws IOException {
-        if (len == buffer.length) {
+        if (bufferPosition == buffer.length) {
             flushBuffer();
         }
-        buffer[len++] = b;
+        buffer[bufferPosition++] = b;
     }
 
     @Override
     public final void write(char c) throws IOException {
         if (c < 128 && highSurrogate == 0) {
-            if (len == buffer.length) {
+            if (bufferPosition == buffer.length) {
                 flushBuffer();
             }
-            buffer[len++] = (byte)c;
+            buffer[bufferPosition++] = (byte)c;
         } else {
             internalWrite(c);
         }
@@ -75,37 +75,55 @@ abstract class ASCIICompatibleXmlWriter
 
     @Override
     public final void write(String s) throws IOException {
+        final byte[] buffer = this.buffer;
+        final int bufferLength = buffer.length;
+        int bufferPosition = this.bufferPosition;
+        int highSurrogate = this.highSurrogate;
         for (int i=0, length=s.length(); i<length; i++) {
             char c = s.charAt(i);
             if (c < 128 && highSurrogate == 0) {
-                if (len == buffer.length) {
-                    flushBuffer();
+                if (bufferPosition == bufferLength) {
+                    out.write(buffer, 0, bufferLength);
+                    bufferPosition = 0;
                 }
-                buffer[len++] = (byte)c;
+                buffer[bufferPosition++] = (byte)c;
             } else {
+                this.bufferPosition = bufferPosition;
                 internalWrite(c);
+                bufferPosition = this.bufferPosition;
+                highSurrogate = this.highSurrogate;
             }
         }
+        this.bufferPosition = bufferPosition;
     }
 
     @Override
     public final void write(char[] chars, int start, int length) throws IOException {
+        final byte[] buffer = this.buffer;
+        final int bufferLength = buffer.length;
+        int bufferPosition = this.bufferPosition;
+        int highSurrogate = this.highSurrogate;
         for (int i=0; i<length; i++) {
             char c = chars[start+i];
             if (c < 128 && highSurrogate == 0) {
-                if (len == buffer.length) {
-                    flushBuffer();
+                if (bufferPosition == bufferLength) {
+                    out.write(buffer, 0, bufferLength);
+                    bufferPosition = 0;
                 }
-                buffer[len++] = (byte)c;
+                buffer[bufferPosition++] = (byte)c;
             } else {
+                this.bufferPosition = bufferPosition;
                 internalWrite(c);
+                bufferPosition = this.bufferPosition;
+                highSurrogate = this.highSurrogate;
             }
         }
+        this.bufferPosition = bufferPosition;
     }
 
     @Override
     public final void flushBuffer() throws IOException {
-        out.write(buffer, 0, len);
-        len = 0;
+        out.write(buffer, 0, bufferPosition);
+        bufferPosition = 0;
     }
 }



Mime
View raw message