ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [48/50] [abbrv] ignite git commit: IGNITE-1917: Finalizing field reads: int.
Date Wed, 18 Nov 2015 13:40:22 GMT
IGNITE-1917: Finalizing field reads: int.


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

Branch: refs/heads/ignite-1917
Commit: ed2b1e7258fbb0492ac9eb334449f362e3c5baea
Parents: 47e0b87
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Wed Nov 18 16:27:08 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Wed Nov 18 16:27:08 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/BinaryFieldAccessor.java  |  4 +-
 .../internal/portable/BinaryReaderExImpl.java   | 72 +++++++++++---------
 2 files changed, 41 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ed2b1e72/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldAccessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldAccessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldAccessor.java
index f8b3dbc..2a9bb45 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldAccessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldAccessor.java
@@ -290,7 +290,7 @@ public abstract class BinaryFieldAccessor {
 
         /** {@inheritDoc} */
         @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException
{
-            int val = reader.readIntPrimitive(id);
+            int val = reader.readInt(id);
 
             UNSAFE.putInt(obj, offset, val);
         }
@@ -623,7 +623,7 @@ public abstract class BinaryFieldAccessor {
                     break;
 
                 case INT:
-                    val = reader.readInt(id);
+                    val = reader.readIntNullable(id);
 
                     break;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/ed2b1e72/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
index 72b83e2..0e080c2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
@@ -1019,41 +1019,27 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
 
     /** {@inheritDoc} */
     @Override public int readInt(String fieldName) throws BinaryObjectException {
-        if (findFieldByName(fieldName)) {
-            if (checkFlag(INT) == Flag.NULL)
-                return 0;
-
-            return in.readInt();
-        }
-        else
-            return 0;
+        return findFieldByName(fieldName) && checkFlagPrimitive(INT) == Flag.NORMAL
? in.readInt() : 0;
     }
 
     /**
      * @param fieldId Field ID.
      * @return Value.
-     * @throws BinaryObjectException In case of error.
+     * @throws BinaryObjectException If failed.
      */
-    @Nullable Integer readInt(int fieldId) throws BinaryObjectException {
-        if (findFieldById(fieldId)) {
-            if (checkFlag(INT) == Flag.NULL)
-                return null;
-
-            return in.readInt();
-        }
-        else
-            return null;
+    public int readInt(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagPrimitive(INT) == Flag.NORMAL ?
in.readInt() : 0;
     }
-    
+
     /**
      * @param fieldId Field ID.
      * @return Value.
-     * @throws BinaryObjectException If failed.
+     * @throws BinaryObjectException In case of error.
      */
-    int readIntPrimitive(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlag(INT) == Flag.NORMAL ? in.readInt()
: 0;
+    @Nullable Integer readIntNullable(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagPrimitive(INT) == Flag.NORMAL ?
in.readInt() : null;
     }
-
+    
     /** {@inheritDoc} */
     @Override public int readInt() throws BinaryObjectException {
         return in.readInt();
@@ -1478,27 +1464,47 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx,
Obje
     }
 
     /**
-     * Ensure that type flag is either null or contains expected value.
+     * Ensure that type flag is either null, handle or contains expected value.
      *
      * @param expFlag Expected value.
-     * @return Flag.
-     * @throws BinaryObjectException If flag is neither null, nor expected.
+     * @return Flag mode.
+     * @throws BinaryObjectException If flag is neither null, nor handle or expected.
      */
     private Flag checkFlag(byte expFlag) {
         byte flag = in.readByte();
 
-        if (flag == NULL)
+        if (flag == expFlag)
+            return Flag.NORMAL;
+        else if (flag == NULL)
             return Flag.NULL;
         else if (flag == HANDLE)
             return Flag.HANDLE;
-        else if (flag != expFlag) {
-            int pos = in.position() - 1;
 
-            throw new BinaryObjectException("Unexpected flag value [pos=" + pos + ", expected="
+ expFlag +
-                ", actual=" + flag + ']');
-        }
+        int pos = in.position() - 1;
+
+        throw new BinaryObjectException("Unexpected flag value [pos=" + pos + ", expected="
+ expFlag +
+            ", actual=" + flag + ']');
+    }
+
+    /**
+     * Ensure that type flag is either null or contains expected value.
+     *
+     * @param expFlag Expected value.
+     * @return Flag mode.
+     * @throws BinaryObjectException If flag is neither null, nor expected.
+     */
+    private Flag checkFlagPrimitive(byte expFlag) {
+        byte flag = in.readByte();
+
+        if (flag == expFlag)
+            return Flag.NORMAL;
+        else if (flag == NULL)
+            return Flag.NULL;
+
+        int pos = in.position() - 1;
 
-        return Flag.NORMAL;
+        throw new BinaryObjectException("Unexpected flag value [pos=" + pos + ", expected="
+ expFlag +
+            ", actual=" + flag + ']');
     }
 
     /**


Mime
View raw message