Author: aadamchik
Date: Wed Feb 22 11:22:36 2012
New Revision: 1292240

URL: http://svn.apache.org/viewvc?rev=1292240&view=rev
Log:
CAY-1667 Expression parser performance optimization

reusing a shared instance of internal IOException that indicates end of stream

Modified:
    
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/JavaCharStream.java

Modified: 
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/JavaCharStream.java
URL: 
http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/JavaCharStream.java?rev=1292240&r1=1292239&r2=1292240&view=diff
==============================================================================
--- 
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/JavaCharStream.java
 (original)
+++ 
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/JavaCharStream.java
 Wed Feb 22 11:22:36 2012
@@ -22,6 +22,8 @@
 
 package org.apache.cayenne.exp.parser;
 
+import java.io.IOException;
+
 /**
  * An implementation of interface CharStream, where the stream is assumed to
  * contain only ASCII characters (with java-like unicode escape processing).
@@ -29,6 +31,18 @@ package org.apache.cayenne.exp.parser;
 
 public class JavaCharStream
 {
+
+    // optimizing internal Exception by reusing the exception per CAY-1667. 
This exception
+    // never reaches the end user, so we can suppress stack trace creation and 
make it
+    // efficient
+    private static final IOException END_OF_STREAM_EXCEPTION = new 
IOException() {
+
+        @Override
+        public synchronized Throwable fillInStackTrace() {
+            return this;
+        };
+    };
+    
 /** Whether parser is static. */
   public static final boolean staticFlag = false;
   static final int hexval(char c) throws java.io.IOException {
@@ -163,7 +177,7 @@ public class JavaCharStream
                                             4096 - maxNextCharInd)) == -1)
         {
            inputStream.close();
-           throw new java.io.IOException();
+           throw END_OF_STREAM_EXCEPTION;
         }
         else
            maxNextCharInd += i;


Reply via email to