Author: vgritsenko
Date: Sun Sep  2 03:52:38 2007
New Revision: 571949

URL: http://svn.apache.org/viewvc?rev=571949&view=rev
Log:
avoid getData()

Modified:
    
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/MemValueIndexer.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java
    xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/MemValueIndexer.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/MemValueIndexer.java?rev=571949&r1=571948&r2=571949&view=diff
==============================================================================
--- 
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/MemValueIndexer.java 
(original)
+++ 
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/MemValueIndexer.java 
Sun Sep  2 03:52:38 2007
@@ -269,7 +269,7 @@
                         for (; aLocatorIterator.hasNext(); ++aResultIndex) {
                             ValueLocator aLocator = (ValueLocator) 
aLocatorIterator.next();
                             aResult[aResultIndex] = new IndexMatch(
-                                    new Key(aLocator.getKey()), 
aLocator.getPosition(), aLocator.getLength(), aLocator.getElementID(), 
aLocator.getAttributeID());
+                                    aLocator.getKey(), aLocator.getPosition(), 
aLocator.getLength(), aLocator.getElementID(), aLocator.getAttributeID());
                         }
                     }
                 } else {
@@ -288,7 +288,7 @@
                             for (; aLocatorIterator.hasNext(); ++aResultIndex) 
{
                                 ValueLocator aLocator = (ValueLocator) 
aLocatorIterator.next();
                                 aResult[aResultIndex] = new IndexMatch(
-                                        new Key(aLocator.getKey()), 
aLocator.getPosition(), aLocator.getLength(), aLocator.getElementID(), 
aLocator.getAttributeID());
+                                        aLocator.getKey(), 
aLocator.getPosition(), aLocator.getLength(), aLocator.getElementID(), 
aLocator.getAttributeID());
                             }
                         }
                     }
@@ -1157,7 +1157,7 @@
             for (; aLocatorIterator.hasNext(); ++theStartIndex) {
                 ValueLocator aLocator = (ValueLocator) aLocatorIterator.next();
                 theArray[theStartIndex] = new IndexMatch(
-                        new Key(aLocator.getKey()), aLocator.getPosition(), 
aLocator.getLength(), aLocator.getElementID(), aLocator.getAttributeID());
+                        aLocator.getKey(), aLocator.getPosition(), 
aLocator.getLength(), aLocator.getElementID(), aLocator.getAttributeID());
             }
         }
 
@@ -1182,7 +1182,7 @@
         for (; aLocatorIterator.hasNext(); ++theStartIndex) {
             ValueLocator aLocator = (ValueLocator) aLocatorIterator.next();
             theArray[theStartIndex] = new IndexMatch(
-                    new Key(aLocator.getKey()), aLocator.getPosition(), 
aLocator.getLength(), aLocator.getElementID(), aLocator.getAttributeID());
+                    aLocator.getKey(), aLocator.getPosition(), 
aLocator.getLength(), aLocator.getElementID(), aLocator.getAttributeID());
         }
         return theStartIndex;
     }
@@ -1225,9 +1225,11 @@
          * @return true if this object is equal to theCompareTo Object, false 
otherwise
          */
         public boolean equals(Object theCompareTo) {
+            //noinspection SimplifiableIfStatement
             if (theCompareTo instanceof EmptyValue) {
                 return true;
             }
+
             return theCompareTo.toString().length() == 0;
         }
 
@@ -1323,6 +1325,32 @@
      * the Collection.
      */
     private class ValueLocator implements Comparable {
+
+        /**
+         * the key of the Document containing the value
+         */
+        private Key itsKey;
+
+        /**
+         * the value's position in the document stream
+         */
+        private final int itsPosition;
+
+        /**
+         * the value's length
+         */
+        private final int itsLength;
+
+        /**
+         * the ID of the Element containing the value
+         */
+        private final short itsElementID;
+
+        /**
+         * the ID of the Attribute containing the value
+         */
+        private final short itsAttributeID;
+
         /**
          * Creates a new object.
          *
@@ -1337,7 +1365,7 @@
          *       instead of as a separate member.
          */
         public ValueLocator(Key theKey, int thePosition, int theLength, short 
theElementID, short theAttributeID) {
-            itsKey = theKey.getData();
+            itsKey = theKey;
             itsPosition = thePosition;
             itsLength = theLength;
             itsElementID = theElementID;
@@ -1349,7 +1377,7 @@
          *
          * @return the key of the Document containing the value
          */
-        public byte[] getKey() {
+        public Key getKey() {
             return itsKey;
         }
 
@@ -1429,24 +1457,9 @@
             ValueLocator aCompareTo = (ValueLocator) theObject;
 
             // compare keys
-            byte[] aCompareToKey = aCompareTo.itsKey;
-
-            int aMaxLength = itsKey.length > aCompareToKey.length ? 
aCompareToKey.length : itsKey.length;
-
-            for (int anIndex = 0; anIndex < aMaxLength; ++anIndex) {
-                byte aByteThis = itsKey[anIndex];
-                byte aByteThat = aCompareToKey[anIndex];
-
-                // compare bytes
-                if (aByteThis != aByteThat) {
-                    return aByteThis > aByteThat ? 1 : -1;
-                }
-            }
-
-            // comparison done if keys are not of equal length but initial
-            // substrings are equal
-            if (itsKey.length != aCompareToKey.length) {
-                return itsKey.length > aCompareToKey.length ? 1 : -1;
+            int result = itsKey.compareTo(aCompareTo.itsKey);
+            if (result != 0) {
+                return result;
             }
 
             // compare position
@@ -1472,30 +1485,5 @@
             // equal
             return 0;
         }
-
-        /**
-         * the key of the Document containing the value
-         */
-        private byte[] itsKey;
-
-        /**
-         * the value's position in the document stream
-         */
-        private final int itsPosition;
-
-        /**
-         * the value's length
-         */
-        private final int itsLength;
-
-        /**
-         * the ID of the Element containing the value
-         */
-        private final short itsElementID;
-
-        /**
-         * the ID of the Attribute containing the value
-         */
-        private final short itsAttributeID;
     }
 }

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java?rev=571949&r1=571948&r2=571949&view=diff
==============================================================================
--- xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java 
(original)
+++ xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/NameIndexer.java 
Sun Sep  2 03:52:38 2007
@@ -143,12 +143,10 @@
     }
 
     private IndexMatch getIndexMatch(Value v) {
-        byte[] b = v.getData();
-        int l = b.length - 5;
-        Key key = new Key(b, 0, l);
-
-        short elemID = (short) ((b[l + 1] << 8) | b[l + 2]);
-        short attrID = (short) ((b[l + 3] << 8) | b[l + 4]);
+        int l = v.getLength() - 5;
+        Key key = v.keyAt(0, l);
+        short elemID = v.shortAt(l + 1);
+        short attrID = v.shortAt(l + 3);
 
         return new IndexMatch(key, elemID, attrID);
     }

Modified: 
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java
URL: 
http://svn.apache.org/viewvc/xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java?rev=571949&r1=571948&r2=571949&view=diff
==============================================================================
--- 
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java 
(original)
+++ 
xml/xindice/trunk/java/src/org/apache/xindice/core/indexer/ValueIndexer.java 
Sun Sep  2 03:52:38 2007
@@ -380,14 +380,13 @@
     }
 
     private IndexMatch getIndexMatch(Value v) {
-        byte[] b = v.getData();
-        int l = b.length - 13;
-        Key key = new Key(b, 0, l);
+        int l = v.getLength() - 13;
 
-        int pos = ((b[l + 1] << 24) | (b[l + 2] << 16) | (b[l + 3] << 8) | b[l 
+ 4]);
-        int len = ((b[l + 5] << 24) | (b[l + 6] << 16) | (b[l + 7] << 8) | b[l 
+ 8]);
-        short elemID = (short) ((b[l + 9] << 8) | b[l + 10]);
-        short attrID = (short) ((b[l + 11] << 8) | b[l + 12]);
+        Key key = v.keyAt(0, l);
+        int pos = v.intAt(l + 1);
+        int len = v.intAt(l + 5);
+        short elemID = v.shortAt(l + 9);
+        short attrID = v.shortAt(l + 11);
 
         return new IndexMatch(key, pos, len, elemID, attrID);
     }


Reply via email to