ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [1/7] ignite git commit: IGNITE-1814: WIP.
Date Mon, 02 Nov 2015 12:01:58 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-1814 [created] e225cab21


IGNITE-1814: WIP.


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

Branch: refs/heads/ignite-1814
Commit: 247825e2624215d7d372d2058f2cae49318a5055
Parents: 00c3a43
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Mon Nov 2 12:15:47 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Mon Nov 2 12:15:47 2015 +0300

----------------------------------------------------------------------
 .../ignite/internal/portable/PortableUtils.java |  6 ++
 .../internal/portable/PortableWriterExImpl.java | 63 ++++++++++++++++++--
 2 files changed, 64 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/247825e2/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
index eafcbd1..c369317 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
@@ -100,6 +100,12 @@ public class PortableUtils {
     /** Flag: only raw data exists. */
     public static final short FLAG_RAW_ONLY = 0x2;
 
+    /** Flag: offsets take 1 byte. */
+    public static final short FLAG_OFFSET_ONE_BYTE = 0x4;
+
+    /** Flag: offsets take 2 bytes. */
+    public static final short FLAG_OFFSET_TWO_BYTES = 0x8;
+
     /**
      * Write flags.
      *

http://git-wip-us.apache.org/repos/asf/ignite/blob/247825e2/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
index 227087b..5991f18 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableWriterExImpl.java
@@ -99,6 +99,21 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
     /** FNV1 hash prime. */
     private static final int FNV1_PRIME = 0x01000193;
 
+    /** Maximum offset which fits in 1 byte. */
+    private static final int MAX_OFFSET_1 = 2 << 8;
+
+    /** Maximum offset which fits in 2 bytes. */
+    private static final int MAX_OFFSET_2 = 2 << 16;
+
+    /** Offset which fits into 1 byte. */
+    private static final int OFFSET_1 = 1;
+
+    /** Offset which fits into 2 bytes. */
+    private static final int OFFSET_2 = 2;
+
+    /** Offset which fits into 4 bytes. */
+    private static final int OFFSET_4 = 4;
+
     /** Thread-local schema. */
     private static final ThreadLocal<SchemaHolder> SCHEMA = new ThreadLocal<>();
 
@@ -342,11 +357,22 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
             out.writeInt(start + SCHEMA_OR_RAW_OFF_POS, out.position() - start);
 
             // Write the schema.
-            schema.writeAndPop(this, fieldCnt);
+            int offsetByteCnt = schema.writeAndPop(this, fieldCnt);
 
             // Write raw offset if needed.
             if (rawOffPos != 0)
                 out.writeInt(rawOffPos - start);
+
+            if (offsetByteCnt == OFFSET_1) {
+                int flags = (userType ? PortableUtils.FLAG_USR_TYP : 0) | PortableUtils.FLAG_OFFSET_ONE_BYTE;
+
+                out.writeShort(start + FLAGS_POS, (short)flags);
+            }
+            else if (offsetByteCnt == OFFSET_2) {
+                int flags = (userType ? PortableUtils.FLAG_USR_TYP : 0) | PortableUtils.FLAG_OFFSET_TWO_BYTES;
+
+                out.writeShort(start + FLAGS_POS, (short)flags);
+            }
         }
         else {
             // Write raw-only flag is needed.
@@ -1834,15 +1860,40 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
          *
          * @param writer Writer.
          * @param cnt Count.
+         * @return Amount of bytes dedicated to
          */
-        public void writeAndPop(PortableWriterExImpl writer, int cnt) {
+        public int writeAndPop(PortableWriterExImpl writer, int cnt) {
             int startIdx = idx - cnt * 2;
 
             assert startIdx >= 0;
 
-            for (int idx0 = startIdx; idx0 < idx;) {
-                writer.writeInt(data[idx0++]);
-                writer.writeInt(data[idx0++]);
+            int lastOffset = data[idx - 1];
+
+            int res;
+
+            if (lastOffset < MAX_OFFSET_1) {
+                for (int idx0 = startIdx; idx0 < idx; ) {
+                    writer.writeInt(data[idx0++]);
+                    writer.writeByte((byte) data[idx0++]);
+                }
+
+                res = OFFSET_1;
+            }
+            else if (lastOffset < MAX_OFFSET_2) {
+                for (int idx0 = startIdx; idx0 < idx; ) {
+                    writer.writeInt(data[idx0++]);
+                    writer.writeShort((short)data[idx0++]);
+                }
+
+                res = OFFSET_2;
+            }
+            else {
+                for (int idx0 = startIdx; idx0 < idx; ) {
+                    writer.writeInt(data[idx0++]);
+                    writer.writeInt(data[idx0++]);
+                }
+
+                res = OFFSET_4;
             }
 
             idx = startIdx;
@@ -1850,6 +1901,8 @@ public class PortableWriterExImpl implements PortableWriter, PortableRawWriterEx
             // Shrink data array if needed.
             if (idx == 0 && data.length > MAX_SIZE)
                 data = new int[MAX_SIZE];
+
+            return res;
         }
     }
 }


Mime
View raw message