db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r360412 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/util/StringUtil.java impl/sql/compile/StringSlicer.java impl/sql/compile/sqlgrammar.jj
Date Sat, 31 Dec 2005 19:06:46 GMT
Author: djd
Date: Sat Dec 31 11:06:43 2005
New Revision: 360412

URL: http://svn.apache.org/viewcvs?rev=360412&view=rev
Log:
DERBY-731 Replace the inefficient StringSlicer class with a simple utility slice method in
StringUtil.

Removed:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/StringSlicer.java
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/StringUtil.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/StringUtil.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/StringUtil.java?rev=360412&r1=360411&r2=360412&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/StringUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/util/StringUtil.java Sat Dec 31
11:06:43 2005
@@ -129,6 +129,28 @@
 			value = value.substring(0, length);
 		return value;
 	}
+	
+	/**
+	 * Return a slice (substring) of the passed in value, optionally trimmed.
+	 * WARNING - endOffset is inclusive for historical reasons, unlike
+	 * String.substring() which has an exclusive ending offset.
+	 * @param value Value to slice, must be non-null.
+	 * @param beginOffset Inclusive start character
+	 * @param endOffset Inclusive end character
+	 * @param trim To trim or not to trim
+	 * @return Sliceed value.
+	 */
+	public static String slice(String value,
+			int beginOffset, int endOffset,
+			boolean trim)
+	{
+		String retval = value.substring(beginOffset, endOffset + 1);
+		
+		if (trim)
+			retval = retval.trim();
+		
+		return retval;
+	}
 
 
 	private static char[] hex_table = {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj?rev=360412&r1=360411&r2=360412&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/sqlgrammar.jj Sat Dec
31 11:06:43 2005
@@ -100,7 +100,6 @@
 import org.apache.derby.impl.sql.compile.DDLStatementNode;
 import org.apache.derby.impl.sql.compile.AlterTableNode;
 
-import org.apache.derby.impl.sql.compile.StringSlicer;
 import org.apache.derby.impl.sql.compile.ParseException;
 import org.apache.derby.impl.sql.compile.Token;
 import org.apache.derby.impl.sql.compile.TokenMgrError;
@@ -202,7 +201,6 @@
     private static final int INTERSECT_OP = 5;
     private static final int INTERSECT_ALL_OP = 6;
 
-	private StringSlicer				stringSlicer;
 	private Object[]					paramDefaults;
 	private String						statementSQLText;
 	private NodeFactory					nodeFactory;
@@ -476,15 +474,6 @@
 		return cm;
 	}
 
-	private StringSlicer	getStringSlicer()
-	{
-		if ( stringSlicer == null )
-		{
-			stringSlicer = new StringSlicer( statementSQLText);
-		}
-		return	stringSlicer;
-	}
-
 	/*
 	** Compress 2 adjacent (single or double) quotes into a single (s or d) quote when
 	** found in the middle of a String.
@@ -1651,8 +1640,7 @@
     {
         /* Do per-statement initialization here */
         parameterNumber = 0;
-        stringSlicer = null;
-        this.statementSQLText = statementSQLText;
+       this.statementSQLText = statementSQLText;
         this.paramDefaults = paramDefaults;
         nodeFactory = getNodeFactory();
         initUnnamedParameterList();
@@ -9551,7 +9539,7 @@
 								resultColumns, 
 								queryExpression,
 								ReuseFactory.getInteger(checkOptionType),
-								getStringSlicer().slice(
+								StringUtil.slice(statementSQLText,
 												beginToken.beginOffset,
 												endToken.endOffset,false),
 								getContextManager());
@@ -9639,7 +9627,7 @@
 								ReuseFactory.getInteger(0),
 											// when clause begin offset
 								actionNode,
-								getStringSlicer().slice(
+								StringUtil.slice(statementSQLText,
 									actionBegin,
 									actionEnd,false),
 								ReuseFactory.getInteger(actionBegin),
@@ -9889,7 +9877,7 @@
 		value = (ValueNode) nodeFactory.getNode(
 								C_NodeTypes.DEFAULT_NODE,
 								value,
-								getStringSlicer().slice(
+								StringUtil.slice(statementSQLText,
 									beginToken.beginOffset + 7,
 									endToken.endOffset,true),
 								getContextManager()
@@ -10346,7 +10334,7 @@
 					rclList,
 					null,
 					value,
-					getStringSlicer().slice(
+					StringUtil.slice(statementSQLText,
 						beginToken.beginOffset,
 						endToken.endOffset,true),
 					getContextManager()



Mime
View raw message