db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r710033 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java
Date Mon, 03 Nov 2008 10:25:44 GMT
Author: kristwaa
Date: Mon Nov  3 02:25:43 2008
New Revision: 710033

URL: http://svn.apache.org/viewvc?rev=710033&view=rev
Log:
DERBY-3825: StoreStreamClob.getReader(charPos) performs poorly.
Made the repositioning logic easier to read.
Patch file: derby-3825-3a-simplification.diff

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java?rev=710033&r1=710032&r2=710033&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/UTF8Reader.java Mon Nov  3
02:25:43 2008
@@ -621,25 +621,22 @@
             SanityManager.ASSERT(this.positionedIn != null);
             SanityManager.ASSERT(requestedCharPos > 0);
         }
-        // See if we can continue reading, or do nothing at all, to get to the
-        // right position.
-        if (requestedCharPos > readerCharCount) {
-            // The second part corrects for the internal buffer position.
-            long toSkip = (requestedCharPos - readerCharCount) +
-                    (charactersInBuffer - readPositionInBuffer) -1;
-            persistentSkip(toSkip);
+        if (requestedCharPos <= readerCharCount - charactersInBuffer) {
+            // The stream must be reset, because the requested position is
+            // before the current lower buffer boundary.
+            resetUTF8Reader();
+        }
+
+        long currentCharPos =
+            readerCharCount - charactersInBuffer + readPositionInBuffer;
+        long difference = (requestedCharPos - 1) - currentCharPos;
+
+        if (difference <= 0) {
+            // Move back in the buffer.
+            readPositionInBuffer += difference;
         } else {
-            // See if the requested position is within the current buffer.
-            long lowerBufferBorder = readerCharCount - charactersInBuffer;
-            if (requestedCharPos <= lowerBufferBorder) {
-                // Have to reset and start from scratch.
-                resetUTF8Reader();
-                persistentSkip(requestedCharPos -1);
-            } else {
-                // We have the requested position in the buffer already.
-                readPositionInBuffer =
-                        (int)(requestedCharPos - lowerBufferBorder -1);
-            }
+            // Skip forward.
+            persistentSkip(difference);
         }
     }
 



Mime
View raw message