ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [10/22] ignite git commit: IGNITE-1770: Reader refactoring (5): Removed offset-related methods.
Date Mon, 26 Oct 2015 12:57:53 GMT
IGNITE-1770: Reader refactoring (5): Removed offset-related methods.


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

Branch: refs/heads/ignite-1770
Commit: af1eddf3e2369e4634f46a121913b61c8604baa3
Parents: eac1ed3
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Mon Oct 26 13:28:00 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Mon Oct 26 13:28:00 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/PortableReaderExImpl.java | 164 ++++---------------
 1 file changed, 29 insertions(+), 135 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/af1eddf3/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
index 575548e..0f17861 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderExImpl.java
@@ -1416,7 +1416,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @throws PortableException In case of error.
      */
     @Nullable private Object unmarshal(boolean raw, boolean detach) throws PortableException
{
-        int start = offset(raw);
+        int start = in.position();
 
         byte flag = doReadByte(raw);
 
@@ -1578,8 +1578,6 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
                     throw new PortableException("Failed to unmarshal object with optmMarsh
marshaller", e);
                 }
 
-                shiftOffset(raw, len);
-
                 return obj;
 
             default:
@@ -1592,13 +1590,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private byte doReadByte(boolean raw) {
-        in.position(offset(raw));
-
-        byte val = in.readByte();
-
-        shiftOffset(raw, 1);
-
-        return val;
+        return in.readByte();
     }
 
     /**
@@ -1606,13 +1598,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     public short doReadShort(boolean raw) {
-        in.position(offset(raw));
-
-        short val = in.readShort();
-
-        shiftOffset(raw, 2);
-
-        return val;
+        return in.readShort();
     }
 
     /**
@@ -1620,13 +1606,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private int doReadInt(boolean raw) {
-        in.position(offset(raw));
-
-        int val = in.readInt();
-
-        shiftOffset(raw, 4);
-
-        return val;
+        return in.readInt();
     }
 
     /**
@@ -1634,13 +1614,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private long doReadLong(boolean raw) {
-        in.position(offset(raw));
-
-        long val = in.readLong();
-
-        shiftOffset(raw, 8);
-
-        return val;
+        return in.readLong();
     }
 
     /**
@@ -1648,13 +1622,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private float doReadFloat(boolean raw) {
-        in.position(offset(raw));
-
-        float val = in.readFloat();
-
-        shiftOffset(raw, 4);
-
-        return val;
+        return in.readFloat();
     }
 
     /**
@@ -1662,13 +1630,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private double doReadDouble(boolean raw) {
-        in.position(offset(raw));
-
-        double val = in.readDouble();
-
-        shiftOffset(raw, 8);
-
-        return val;
+        return in.readDouble();
     }
 
     /**
@@ -1676,13 +1638,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private char doReadChar(boolean raw) {
-        in.position(offset(raw));
-
-        char val = in.readChar();
-
-        shiftOffset(raw, 2);
-
-        return val;
+        return in.readChar();
     }
 
     /**
@@ -1690,13 +1646,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private boolean doReadBoolean(boolean raw) {
-        in.position(offset(raw));
-
-        boolean val = in.readBoolean();
-
-        shiftOffset(raw, 1);
-
-        return val;
+        return in.readBoolean();
     }
 
     /**
@@ -1728,7 +1678,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
                 return new String(doReadByteArray(raw), UTF_8);
 
             int strLen = doReadInt(raw);
-            int strOff = offset(raw);
+            int strOff = in.position();
 
             String res = new String(in.array(), strOff, strLen, UTF_8);
 
@@ -1782,13 +1732,9 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @throws PortableException In case of error.
      */
     @Nullable private Object doReadObject(boolean raw) throws PortableException {
-        PortableReaderExImpl reader = new PortableReaderExImpl(ctx, in, offset(raw), ldr,
rCtx);
+        PortableReaderExImpl reader = new PortableReaderExImpl(ctx, in, in.position(), ldr,
rCtx);
 
-        Object obj = reader.deserialize();
-
-        shiftOffset(raw, reader.len);
-
-        return obj;
+        return reader.deserialize();
     }
 
     /**
@@ -2056,18 +2002,14 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private byte[] doReadByteArray(boolean raw) {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int len = doReadInt(raw);
 
-        in.position(offset(raw));
-
         byte[] arr = in.readByteArray(len);
 
         setHandler(arr, hPos);
 
-        shiftOffset(raw, len);
-
         return arr;
     }
 
@@ -2076,18 +2018,14 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private short[] doReadShortArray(boolean raw) {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int len = doReadInt(raw);
 
-        in.position(offset(raw));
-
         short[] arr = in.readShortArray(len);
 
         setHandler(arr, hPos);
 
-        shiftOffset(raw, len << 1);
-
         return arr;
     }
 
@@ -2096,18 +2034,14 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private int[] doReadIntArray(boolean raw) {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int len = doReadInt(raw);
 
-        in.position(offset(raw));
-
         int[] arr = in.readIntArray(len);
 
         setHandler(arr, hPos);
 
-        shiftOffset(raw, len << 2);
-
         return arr;
     }
 
@@ -2116,18 +2050,14 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private long[] doReadLongArray(boolean raw) {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int len = doReadInt(raw);
 
-        in.position(offset(raw));
-
         long[] arr = in.readLongArray(len);
 
         setHandler(arr, hPos);
 
-        shiftOffset(raw, len << 3);
-
         return arr;
     }
 
@@ -2136,18 +2066,14 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private float[] doReadFloatArray(boolean raw) {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int len = doReadInt(raw);
 
-        in.position(offset(raw));
-
         float[] arr = in.readFloatArray(len);
 
         setHandler(arr, hPos);
 
-        shiftOffset(raw, len << 2);
-
         return arr;
     }
 
@@ -2156,18 +2082,14 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private double[] doReadDoubleArray(boolean raw) {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int len = doReadInt(raw);
 
-        in.position(offset(raw));
-
         double[] arr = in.readDoubleArray(len);
 
         setHandler(arr, hPos);
 
-        shiftOffset(raw, len << 3);
-
         return arr;
     }
 
@@ -2176,18 +2098,14 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private char[] doReadCharArray(boolean raw) {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int len = doReadInt(raw);
 
-        in.position(offset(raw));
-
         char[] arr = in.readCharArray(len);
 
         setHandler(arr, hPos);
 
-        shiftOffset(raw, len << 1);
-
         return arr;
     }
 
@@ -2196,18 +2114,14 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @return Value.
      */
     private boolean[] doReadBooleanArray(boolean raw) {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int len = doReadInt(raw);
 
-        in.position(offset(raw));
-
         boolean[] arr = in.readBooleanArray(len);
 
         setHandler(arr, hPos);
 
-        shiftOffset(raw, len);
-
         return arr;
     }
 
@@ -2217,7 +2131,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @throws PortableException In case of error.
      */
     private BigDecimal[] doReadDecimalArray(boolean raw) throws PortableException {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int len = doReadInt(raw);
 
@@ -2247,7 +2161,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @throws PortableException In case of error.
      */
     private String[] doReadStringArray(boolean raw) throws PortableException {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int len = doReadInt(raw);
 
@@ -2277,7 +2191,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @throws PortableException In case of error.
      */
     private UUID[] doReadUuidArray(boolean raw) throws PortableException {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int len = doReadInt(raw);
 
@@ -2307,7 +2221,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @throws PortableException In case of error.
      */
     private Date[] doReadDateArray(boolean raw) throws PortableException {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int len = doReadInt(raw);
 
@@ -2337,7 +2251,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @throws PortableException In case of error.
      */
     private Timestamp[] doReadTimestampArray(boolean raw) throws PortableException {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int len = doReadInt(raw);
 
@@ -2368,7 +2282,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @throws PortableException In case of error.
      */
     private Object[] doReadObjectArray(boolean raw, boolean deep) throws PortableException
{
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         Class compType = doReadClass(raw);
 
@@ -2394,7 +2308,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
     @SuppressWarnings("unchecked")
     private Collection<?> doReadCollection(boolean raw, boolean deep, @Nullable Class<?
extends Collection> cls)
         throws PortableException {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int size = doReadInt(raw);
 
@@ -2483,7 +2397,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
     @SuppressWarnings("unchecked")
     private Map<?, ?> doReadMap(boolean raw, boolean deep, @Nullable Class<? extends
Map> cls)
         throws PortableException {
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         int size = doReadInt(raw);
 
@@ -2559,7 +2473,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
      * @throws PortableException In case of error.
      */
     private Map.Entry<?, ?> doReadMapEntry(boolean raw, boolean deep) throws PortableException
{
-        int hPos = (offset(raw)) - 1;
+        int hPos = in.position() - 1;
 
         Object val1 = deep ? doReadObject(raw) : unmarshal(raw);
         Object val2 = deep ? doReadObject(raw) : unmarshal(raw);
@@ -2845,26 +2759,6 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
     }
 
     /**
-     * Get offset.
-     *
-     * @param raw Raw flag.
-     * @return Offset.
-     */
-    private int offset(boolean raw) {
-        return in.position();
-    }
-
-    /**
-     * Shift offset.
-     *
-     * @param raw Raw flag.
-     * @param cnt Count.
-     */
-    private void shiftOffset(boolean raw, int cnt) {
-        //in.position(in.position() + cnt);
-    }
-
-    /**
      * Flag.
      */
     private static enum Flag {


Mime
View raw message