cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1294609 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser: ExpressionParser.java JavaCharStream.java
Date Tue, 28 Feb 2012 12:10:45 GMT
Author: aadamchik
Date: Tue Feb 28 12:10:45 2012
New Revision: 1294609

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

removing ReInit methods to underscore parser throwaway nature
preventing Reader from throwing IOException repetedly when called on a closed Reader - checking
closed status explicitly

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ExpressionParser.java
    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/ExpressionParser.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ExpressionParser.java?rev=1294609&r1=1294608&r2=1294609&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ExpressionParser.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/parser/ExpressionParser.java
Tue Feb 28 12:10:45 2012
@@ -21,10 +21,7 @@
 
 package org.apache.cayenne.exp.parser;
 
-import java.io.*;
-import java.util.*;
-import java.math.*;
-import org.apache.cayenne.exp.*;
+import org.apache.cayenne.exp.Expression;
 
 /**
   * Parser of Cayenne Expressions. 
@@ -1375,21 +1372,6 @@ public class ExpressionParser/*@bgen(jjt
     for (int i = 0; i < 25; i++) jj_la1[i] = -1;
   }
 
-  /** Reinitialise. */
-  public void ReInit(java.io.InputStream stream) {
-     ReInit(stream, null);
-  }
-  /** Reinitialise. */
-  public void ReInit(java.io.InputStream stream, String encoding) {
-    try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException
e) { throw new RuntimeException(e); }
-    token_source.ReInit(jj_input_stream);
-    token = new Token();
-    jj_ntk = -1;
-    jjtree.reset();
-    jj_gen = 0;
-    for (int i = 0; i < 25; i++) jj_la1[i] = -1;
-  }
-
   /** Constructor. */
   public ExpressionParser(java.io.Reader stream) {
     jj_input_stream = new JavaCharStream(stream, 1, 1);
@@ -1400,16 +1382,7 @@ public class ExpressionParser/*@bgen(jjt
     for (int i = 0; i < 25; i++) jj_la1[i] = -1;
   }
 
-  /** Reinitialise. */
-  public void ReInit(java.io.Reader stream) {
-    jj_input_stream.ReInit(stream, 1, 1);
-    token_source.ReInit(jj_input_stream);
-    token = new Token();
-    jj_ntk = -1;
-    jjtree.reset();
-    jj_gen = 0;
-    for (int i = 0; i < 25; i++) jj_la1[i] = -1;
-  }
+ 
 
   /** Constructor with generated Token Manager. */
   public ExpressionParser(ExpressionParserTokenManager tm) {
@@ -1420,15 +1393,7 @@ public class ExpressionParser/*@bgen(jjt
     for (int i = 0; i < 25; i++) jj_la1[i] = -1;
   }
 
-  /** Reinitialise. */
-  public void ReInit(ExpressionParserTokenManager tm) {
-    token_source = tm;
-    token = new Token();
-    jj_ntk = -1;
-    jjtree.reset();
-    jj_gen = 0;
-    for (int i = 0; i < 25; i++) jj_la1[i] = -1;
-  }
+ 
 
   private Token jj_consume_token(int kind) throws ParseException {
     Token oldToken;

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=1294609&r1=1294608&r2=1294609&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
Tue Feb 28 12:10:45 2012
@@ -114,6 +114,7 @@ public class JavaCharStream
   protected int nextCharInd = -1;
   protected int inBuf = 0;
   protected int tabSize = 8;
+  private boolean closed;
 
   protected void setTabSize(int i) { tabSize = i; }
   protected int getTabSize(int i) { return tabSize; }
@@ -173,10 +174,13 @@ public class JavaCharStream
         maxNextCharInd = nextCharInd = 0;
 
      try {
-        if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
+        // check for closed status to prevent the underlying Reader from 
+        // throwing IOException that causes performance degradation
+        if (closed || (i = inputStream.read(nextCharBuf, maxNextCharInd,
                 nextCharBuf.length - maxNextCharInd)) == -1)
         {
            inputStream.close();
+           closed = true;
            throw END_OF_STREAM_EXCEPTION;
         }
         else
@@ -450,39 +454,7 @@ public class JavaCharStream
   {
      this(dstream, 1, 1, 4096);
   }
-/** Reinitialise. */
-  public void ReInit(java.io.Reader dstream,
-                 int startline, int startcolumn, int buffersize)
-  {
-    inputStream = dstream;
-    line = startline;
-    column = startcolumn - 1;
-
-    if (buffer == null || buffersize != buffer.length)
-    {
-      available = bufsize = buffersize;
-      buffer = new char[buffersize];
-      bufline = new int[buffersize];
-      bufcolumn = new int[buffersize];
-      nextCharBuf = new char[buffersize];
-    }
-    prevCharIsLF = prevCharIsCR = false;
-    tokenBegin = inBuf = maxNextCharInd = 0;
-    nextCharInd = bufpos = -1;
-  }
 
-/** Reinitialise. */
-  public void ReInit(java.io.Reader dstream,
-                                        int startline, int startcolumn)
-  {
-     ReInit(dstream, startline, startcolumn, 4096);
-  }
-
-/** Reinitialise. */
-  public void ReInit(java.io.Reader dstream)
-  {
-     ReInit(dstream, 1, 1, 4096);
-  }
 /** Constructor. */
   public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
   int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
@@ -523,42 +495,8 @@ public class JavaCharStream
      this(dstream, 1, 1, 4096);
   }
 
-/** Reinitialise. */
-  public void ReInit(java.io.InputStream dstream, String encoding, int startline,
-  int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
-  {
-     ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream,
encoding), startline, startcolumn, buffersize);
-  }
 
-/** Reinitialise. */
-  public void ReInit(java.io.InputStream dstream, int startline,
-  int startcolumn, int buffersize)
-  {
-     ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
-  }
-/** Reinitialise. */
-  public void ReInit(java.io.InputStream dstream, String encoding, int startline,
-                     int startcolumn) throws java.io.UnsupportedEncodingException
-  {
-     ReInit(dstream, encoding, startline, startcolumn, 4096);
-  }
-/** Reinitialise. */
-  public void ReInit(java.io.InputStream dstream, int startline,
-                     int startcolumn)
-  {
-     ReInit(dstream, startline, startcolumn, 4096);
-  }
-/** Reinitialise. */
-  public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
-  {
-     ReInit(dstream, encoding, 1, 1, 4096);
-  }
 
-/** Reinitialise. */
-  public void ReInit(java.io.InputStream dstream)
-  {
-     ReInit(dstream, 1, 1, 4096);
-  }
 
   /** @return token image as String */
   public String GetImage()



Mime
View raw message