ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [07/10] ignite git commit: IGNITE-1770: Refactoring.
Date Tue, 27 Oct 2015 09:01:02 GMT
IGNITE-1770: Refactoring.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7854eba2
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7854eba2
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7854eba2

Branch: refs/heads/ignite-1770
Commit: 7854eba2ab03d9f76a45d8eed5dcfd161db20b78
Parents: bce06ae
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Tue Oct 27 11:47:54 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Tue Oct 27 11:47:54 2015 +0300

----------------------------------------------------------------------
 .../portable/builder/PortableBuilderImpl.java   | 46 +++++++++++++-------
 1 file changed, 31 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/7854eba2/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
index c59fbc1..06f15f5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderImpl.java
@@ -25,6 +25,7 @@ import org.apache.ignite.internal.portable.PortableUtils;
 import org.apache.ignite.internal.portable.PortableWriterExImpl;
 import org.apache.ignite.internal.processors.cache.portable.CacheObjectPortableProcessorImpl;
 import org.apache.ignite.internal.util.GridArgumentCheck;
+import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.portable.PortableBuilder;
@@ -390,7 +391,35 @@ public class PortableBuilderImpl implements PortableBuilder {
     }
 
     /**
+     * Get field position and length.
      *
+     * @param footerPos Field position inside the footer (absolute).
+     * @param footerEnd Footer end (absolute).
+     * @param rawPos Raw data position (absolute).
+     * @return Tuple with field position and length.
+     */
+    private IgniteBiTuple<Integer, Integer> fieldPositionAndLength(int footerPos, int
footerEnd, int rawPos) {
+        int fieldOffset = reader.readIntPositioned(footerPos + 4);
+        int fieldPos = start + fieldOffset + 8; // TODO: 8 is to be removed.
+
+        // Get field length.
+        int fieldLen;
+
+        if (footerPos + 8 == footerEnd)
+            // This is the last field, compare to raw offset.
+            fieldLen = rawPos - fieldPos;
+        else {
+            // Field is somewhere in the middle, get difference with the next offset.
+            int nextFieldOffset = reader.readIntPositioned(footerPos + 8 + 4);
+
+            fieldLen = nextFieldOffset - fieldOffset - 8; // TODO: 8 is to be removed.
+        }
+
+        return F.t(fieldPos, fieldLen);
+    }
+
+    /**
+     * Initialize read cache if needed.
      */
     private void ensureReadCacheInit() {
         if (readCache == null) {
@@ -405,23 +434,10 @@ public class PortableBuilderImpl implements PortableBuilder {
 
             while (footerPos < footerEnd) {
                 int fieldId = reader.readIntPositioned(footerPos);
-                int fieldOffset = reader.readIntPositioned(footerPos + 4);
-                int fieldPos = start + fieldOffset + 8; // TODO: 8 is to be removed.
-
-                // Get field length.
-                int len;
 
-                if (footerPos + 8 == footerEnd)
-                    // This is the last field, compare to raw offset.
-                    len = rawPos - fieldPos;
-                else {
-                    // Field is somewhere in the middle, get difference with the next offset.
-                    int nextFieldOffset = reader.readIntPositioned(footerPos + 8 + 4);
-
-                    len = nextFieldOffset - fieldOffset - 8; // TODO: 8 is to be removed.
-                }
+                IgniteBiTuple<Integer, Integer> posAndLen = fieldPositionAndLength(footerPos,
footerEnd, rawPos);
 
-                Object val = reader.getValueQuickly(fieldPos, len);
+                Object val = reader.getValueQuickly(posAndLen.get1(), posAndLen.get2());
 
                 readCache.put(fieldId, val);
 


Mime
View raw message