ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1795693 - in /webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer: ASCIICompatibleXmlWriter.java AbstractXmlWriter.java Latin1XmlWriter.java UTF8XmlWriter.java
Date Sun, 21 May 2017 11:50:48 GMT
Author: veithen
Date: Sun May 21 11:50:47 2017
New Revision: 1795693

URL: http://svn.apache.org/viewvc?rev=1795693&view=rev
Log:
More aggressively optimize outputting ASCII characters.

Added:
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java
      - copied, changed from r1795692, webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/AbstractXmlWriter.java
Removed:
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/AbstractXmlWriter.java
Modified:
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/Latin1XmlWriter.java
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/UTF8XmlWriter.java

Copied: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java
(from r1795692, webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/AbstractXmlWriter.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?p2=webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java&p1=webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/AbstractXmlWriter.java&r1=1795692&r2=1795693&rev=1795693&view=diff
==============================================================================
--- webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/AbstractXmlWriter.java
(original)
+++ webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/ASCIICompatibleXmlWriter.java
Sun May 21 11:50:47 2017
@@ -21,17 +21,17 @@ package org.apache.axiom.core.stream.ser
 import java.io.IOException;
 import java.io.OutputStream;
 
-abstract class AbstractXmlWriter extends XmlWriter {
+abstract class ASCIICompatibleXmlWriter extends XmlWriter {
     private final OutputStream out;
     private final byte[] buffer = new byte[4096];
     private int len;
     private char highSurrogate;
     
-    AbstractXmlWriter(OutputStream out) {
+    ASCIICompatibleXmlWriter(OutputStream out) {
         this.out = out;
     }
 
-    protected abstract void writeCharacter(int codePoint) throws IOException;
+    protected abstract void writeNonASCIICharacter(int codePoint) throws IOException;
 
     protected final void writeByte(byte b) throws IOException {
         if (len == buffer.length) {
@@ -42,6 +42,17 @@ abstract class AbstractXmlWriter extends
 
     @Override
     public final void write(char c) throws IOException {
+        if (c < 128 && highSurrogate == 0) {
+            if (len == buffer.length) {
+                flushBuffer();
+            }
+            buffer[len++] = (byte)c;
+        } else {
+            internalWrite(c);
+        }
+    }
+
+    private final void internalWrite(char c) throws IOException {
         if (highSurrogate != 0) {
             if (Character.isLowSurrogate(c)) {
                 int codePoint = Character.toCodePoint(highSurrogate, c);
@@ -49,7 +60,7 @@ abstract class AbstractXmlWriter extends
                 // may be unmappable, resulting in a character reference being written
                 // (which means that this method must be reentrant).
                 highSurrogate = 0;
-                writeCharacter(codePoint);
+                writeNonASCIICharacter(codePoint);
             } else {
                 throw new IOException("Invalid surrogate pair");
             }
@@ -58,21 +69,37 @@ abstract class AbstractXmlWriter extends
         } else if (Character.isLowSurrogate(c)) {
             throw new IOException("Invalid surrogate pair");
         } else {
-            writeCharacter(c);
+            writeNonASCIICharacter(c);
         }
     }
 
     @Override
     public final void write(String s) throws IOException {
-        for (int i=0, len=s.length(); i<len; i++) {
-            write(s.charAt(i));
+        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();
+                }
+                buffer[len++] = (byte)c;
+            } else {
+                internalWrite(c);
+            }
         }
     }
 
     @Override
     public final void write(char[] chars, int start, int length) throws IOException {
         for (int i=0; i<length; i++) {
-            write(chars[start+i]);
+            char c = chars[start+i];
+            if (c < 128 && highSurrogate == 0) {
+                if (len == buffer.length) {
+                    flushBuffer();
+                }
+                buffer[len++] = (byte)c;
+            } else {
+                internalWrite(c);
+            }
         }
     }
 

Modified: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/Latin1XmlWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/Latin1XmlWriter.java?rev=1795693&r1=1795692&r2=1795693&view=diff
==============================================================================
--- webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/Latin1XmlWriter.java
(original)
+++ webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/Latin1XmlWriter.java
Sun May 21 11:50:47 2017
@@ -21,7 +21,7 @@ package org.apache.axiom.core.stream.ser
 import java.io.IOException;
 import java.io.OutputStream;
 
-final class Latin1XmlWriter extends AbstractXmlWriter {
+final class Latin1XmlWriter extends ASCIICompatibleXmlWriter {
     private final int maxChar;
     private UnmappableCharacterHandler unmappableCharacterHandler = UnmappableCharacterHandler.THROW_EXCEPTION;
 
@@ -36,7 +36,7 @@ final class Latin1XmlWriter extends Abst
     }
 
     @Override
-    protected void writeCharacter(int codePoint) throws IOException {
+    protected void writeNonASCIICharacter(int codePoint) throws IOException {
         if (codePoint > maxChar) {
             unmappableCharacterHandler.processUnmappableCharacter(codePoint, this);
         } else {

Modified: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/UTF8XmlWriter.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/UTF8XmlWriter.java?rev=1795693&r1=1795692&r2=1795693&view=diff
==============================================================================
--- webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/UTF8XmlWriter.java
(original)
+++ webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/serializer/writer/UTF8XmlWriter.java
Sun May 21 11:50:47 2017
@@ -21,7 +21,7 @@ package org.apache.axiom.core.stream.ser
 import java.io.IOException;
 import java.io.OutputStream;
 
-final class UTF8XmlWriter extends AbstractXmlWriter {
+final class UTF8XmlWriter extends ASCIICompatibleXmlWriter {
     UTF8XmlWriter(OutputStream out) {
         super(out);
     }
@@ -32,10 +32,8 @@ final class UTF8XmlWriter extends Abstra
     }
 
     @Override
-    protected void writeCharacter(int codePoint) throws IOException {
-        if (codePoint < 0x80) {
-            writeByte((byte)codePoint);
-        } else if (codePoint < 0x800) {
+    protected void writeNonASCIICharacter(int codePoint) throws IOException {
+        if (codePoint < 0x800) {
             writeByte((byte)(0xc0 + (codePoint >> 6)));
             writeByte((byte)(0x80 + (codePoint & 0x3f)));
         } else if (codePoint < 0x10000) {



Mime
View raw message