You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2012/07/11 19:10:37 UTC

svn commit: r1360299 - in /incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings: FnCodepointEqualEvaluatorFactory.java FnCompareEvaluatorFactory.java

Author: prestonc
Date: Wed Jul 11 17:10:36 2012
New Revision: 1360299

URL: http://svn.apache.org/viewvc?rev=1360299&view=rev
Log:
The code has been simplified by removing the character iterator to use the compareTo function that exists with the UTF8StringPointable.

Modified:
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointEqualEvaluatorFactory.java
    incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCompareEvaluatorFactory.java

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointEqualEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointEqualEvaluatorFactory.java?rev=1360299&r1=1360298&r2=1360299&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointEqualEvaluatorFactory.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCodepointEqualEvaluatorFactory.java Wed Jul 11 17:10:36 2012
@@ -26,8 +26,6 @@ public class FnCodepointEqualEvaluatorFa
             throws AlgebricksException {
         final UTF8StringPointable stringp1 = new UTF8StringPointable();
         final UTF8StringPointable stringp2 = new UTF8StringPointable();
-        final ICharacterIterator charIterator1 = new UTF8StringCharacterIterator(stringp1);
-        final ICharacterIterator charIterator2 = new UTF8StringCharacterIterator(stringp2);
 
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
@@ -49,23 +47,9 @@ public class FnCodepointEqualEvaluatorFa
                 }
                 tvp1.getValue(stringp1);
                 tvp2.getValue(stringp2);
-                charIterator1.reset();
-                charIterator2.reset();
-
-                int c1;
-                int c2;
-                while (true) {
-                    c1 = charIterator1.next();
-                    c2 = charIterator2.next();
-                    if (ICharacterIterator.EOS_CHAR == c1 && ICharacterIterator.EOS_CHAR == c2) {
-                        // Checked the full length of search string.
-                        booleanResult[1] = 1;
-                        break;
-                    }
-                    if (c1 != c2) {
-                        // Characters do not match
-                        break;
-                    }
+                
+                if (stringp1.compareTo(stringp2) == 0) {
+                    booleanResult[1] = 1;
                 }
 
                 result.set(booleanResult, 0, 2);

Modified: incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCompareEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCompareEvaluatorFactory.java?rev=1360299&r1=1360298&r2=1360299&view=diff
==============================================================================
--- incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCompareEvaluatorFactory.java (original)
+++ incubator/vxquery/branches/vxquery_algebricks/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/strings/FnCompareEvaluatorFactory.java Wed Jul 11 17:10:36 2012
@@ -28,16 +28,11 @@ public class FnCompareEvaluatorFactory e
         final UTF8StringPointable stringp1 = new UTF8StringPointable();
         final UTF8StringPointable stringp2 = new UTF8StringPointable();
         final UTF8StringPointable stringp3 = new UTF8StringPointable();
-        final ICharacterIterator charIterator1 = new UTF8StringCharacterIterator(stringp1);
-        final ICharacterIterator charIterator2 = new UTF8StringCharacterIterator(stringp2);
         final byte[] integerResult = new byte[LongPointable.TYPE_TRAITS.getFixedLength() + 1];
 
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
             protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                // Default result is false.
-                int intResult;
-
                 TaggedValuePointable tvp1 = args[0];
                 TaggedValuePointable tvp2 = args[1];
 
@@ -50,8 +45,6 @@ public class FnCompareEvaluatorFactory e
                 }
                 tvp1.getValue(stringp1);
                 tvp2.getValue(stringp2);
-                charIterator1.reset();
-                charIterator2.reset();
 
                 // Third parameter is optional.
                 if (args.length > 2) {
@@ -63,30 +56,8 @@ public class FnCompareEvaluatorFactory e
                 }
                 // TODO use the third value as collation
 
-                int c1;
-                int c2;
-                while (true) {
-                    c1 = charIterator1.next();
-                    c2 = charIterator2.next();
-                    if (ICharacterIterator.EOS_CHAR == c1 && ICharacterIterator.EOS_CHAR == c2) {
-                        // Checked the full length of search string.
-                        intResult = 0;
-                        break;
-                    }
-                    if (c1 > c2) {
-                        // Character in string one is larger.
-                        intResult = -1;
-                        break;
-                    }
-                    if (c1 < c2) {
-                        // Character in string two is larger.
-                        intResult = 1;
-                        break;
-                    }
-                }
-
                 integerResult[0] = ValueTag.XS_INTEGER_TAG;
-                LongPointable.setLong(integerResult, 1, (long) intResult);
+                LongPointable.setLong(integerResult, 1, (long) stringp1.compareTo(stringp2));
                 result.set(integerResult, 0, LongPointable.TYPE_TRAITS.getFixedLength() + 1);
             }
         };