You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/11/16 10:13:54 UTC

[2/3] ignite git commit: IGNITE-1917: Moved schema holder to a separate class.

IGNITE-1917: Moved schema holder to a separate class.


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

Branch: refs/heads/ignite-1917
Commit: a409163490ca3dd9832a1e519c05c1e26ef71854
Parents: 5915a45
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Mon Nov 16 12:08:25 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Mon Nov 16 12:08:25 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/BinaryWriterExImpl.java   | 146 +------------------
 .../portable/BinaryWriterSchemaHolder.java      | 144 ++++++++++++++++++
 2 files changed, 147 insertions(+), 143 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a4091634/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
index 30f00cb..0e8c855 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
@@ -93,12 +93,6 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     /** Initial capacity. */
     private static final int INIT_CAP = 1024;
 
-    /** Maximum offset which fits in 1 byte. */
-    private static final int MAX_OFFSET_1 = 1 << 8;
-
-    /** Maximum offset which fits in 2 bytes. */
-    private static final int MAX_OFFSET_2 = 1 << 16;
-
     /** */
     private final PortableContext ctx;
 
@@ -118,7 +112,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     private PortableOutputStream out;
 
     /** Schema. */
-    private SchemaHolder schema;
+    private BinaryWriterSchemaHolder schema;
 
     /** Schema ID. */
     private int schemaId = PortableUtils.schemaInitialId();
@@ -138,7 +132,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     private static class TLSContext {
 
         public PortableMemoryAllocatorChunk chunk = PortableMemoryAllocator.INSTANCE.chunk();
-        public SchemaHolder schema = new SchemaHolder();
+        public BinaryWriterSchemaHolder schema = new BinaryWriterSchemaHolder();
     }
     
     /**
@@ -182,7 +176,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
       * @param out Output stream.
       * @param handles Handles.
       */
-     private BinaryWriterExImpl(PortableContext ctx, PortableOutputStream out, SchemaHolder schema,
+     private BinaryWriterExImpl(PortableContext ctx, PortableOutputStream out, BinaryWriterSchemaHolder schema,
          BinaryWriterHandles handles) {
          this.ctx = ctx;
          this.out = out;
@@ -1846,138 +1840,4 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     public PortableContext context() {
         return ctx;
     }
-
-    /**
-     * Schema holder.
-     */
-    private static class SchemaHolder {
-        /** Grow step. */
-        private static final int GROW_STEP = 64;
-
-        /** Maximum stable size. */
-        private static final int MAX_SIZE = 1024;
-
-        /** Data. */
-        private int[] data;
-
-        /** Index. */
-        private int idx;
-
-        /**
-         * Constructor.
-         */
-        public SchemaHolder() {
-            data = new int[GROW_STEP];
-        }
-
-        /**
-         * Push another frame.
-         *
-         * @param id Field ID.
-         * @param off Field offset.
-         */
-        public void push(int id, int off) {
-            if (idx == data.length) {
-                int[] data0 = new int[data.length + GROW_STEP];
-
-                System.arraycopy(data, 0, data0, 0, data.length);
-
-                data = data0;
-            }
-
-            data[idx] = id;
-            data[idx + 1] = off;
-
-            idx += 2;
-        }
-
-        /**
-         * Build the schema.
-         *
-         * @param builder Builder.
-         * @param fieldCnt Fields count.
-         */
-        public void build(PortableSchema.Builder builder, int fieldCnt) {
-            for (int curIdx = idx - fieldCnt * 2; curIdx < idx; curIdx += 2)
-                builder.addField(data[curIdx]);
-        }
-
-        /**
-         * Write collected frames and pop them.
-         *
-         * @param writer Writer.
-         * @param fieldCnt Count.
-         * @param compactFooter Whether footer should be written in compact form.
-         * @return Amount of bytes dedicated to each field offset. Could be 1, 2 or 4.
-         */
-        public int write(BinaryWriterExImpl writer, int fieldCnt, boolean compactFooter) {
-            int startIdx = idx - fieldCnt * 2;
-
-            assert startIdx >= 0;
-
-            int lastOffset = data[idx - 1];
-
-            int res;
-
-            if (compactFooter) {
-                if (lastOffset < MAX_OFFSET_1) {
-                    for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
-                        writer.writeByte((byte)data[curIdx]);
-
-                    res = PortableUtils.OFFSET_1;
-                }
-                else if (lastOffset < MAX_OFFSET_2) {
-                    for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
-                        writer.writeShort((short)data[curIdx]);
-
-                    res = PortableUtils.OFFSET_2;
-                }
-                else {
-                    for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
-                        writer.writeInt(data[curIdx]);
-
-                    res = PortableUtils.OFFSET_4;
-                }
-            }
-            else {
-                if (lastOffset < MAX_OFFSET_1) {
-                    for (int curIdx = startIdx; curIdx < idx;) {
-                        writer.writeInt(data[curIdx++]);
-                        writer.writeByte((byte) data[curIdx++]);
-                    }
-
-                    res = PortableUtils.OFFSET_1;
-                }
-                else if (lastOffset < MAX_OFFSET_2) {
-                    for (int curIdx = startIdx; curIdx < idx;) {
-                        writer.writeInt(data[curIdx++]);
-                        writer.writeShort((short)data[curIdx++]);
-                    }
-
-                    res = PortableUtils.OFFSET_2;
-                }
-                else {
-                    for (int curIdx = startIdx; curIdx < idx;) {
-                        writer.writeInt(data[curIdx++]);
-                        writer.writeInt(data[curIdx++]);
-                    }
-
-                    res = PortableUtils.OFFSET_4;
-                }
-            }
-
-            return res;
-        }
-
-        /**
-         * Pop current object's frame.
-         */
-        public void pop(int fieldCnt) {
-            idx = idx - fieldCnt * 2;
-
-            // Shrink data array if needed.
-            if (idx == 0 && data.length > MAX_SIZE)
-                data = new int[MAX_SIZE];
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/a4091634/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterSchemaHolder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterSchemaHolder.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterSchemaHolder.java
new file mode 100644
index 0000000..a3ee555
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterSchemaHolder.java
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.portable;
+
+/**
+ * Binary writer schema holder.
+ */
+public class BinaryWriterSchemaHolder {
+    /** Maximum offset which fits in 1 byte. */
+    private static final int MAX_OFFSET_1 = 1 << 8;
+
+    /** Maximum offset which fits in 2 bytes. */
+    private static final int MAX_OFFSET_2 = 1 << 16;
+
+    /** Grow step. */
+    private static final int GROW_STEP = 64;
+
+    /** Data. */
+    private int[] data = new int[GROW_STEP];
+
+    /** Index. */
+    private int idx;
+
+    /**
+     * Push another frame.
+     *
+     * @param id Field ID.
+     * @param off Field offset.
+     */
+    public void push(int id, int off) {
+        if (idx == data.length) {
+            int[] data0 = new int[data.length + GROW_STEP];
+
+            System.arraycopy(data, 0, data0, 0, data.length);
+
+            data = data0;
+        }
+
+        data[idx] = id;
+        data[idx + 1] = off;
+
+        idx += 2;
+    }
+
+    /**
+     * Build the schema.
+     *
+     * @param builder Builder.
+     * @param fieldCnt Fields count.
+     */
+    public void build(PortableSchema.Builder builder, int fieldCnt) {
+        for (int curIdx = idx - fieldCnt * 2; curIdx < idx; curIdx += 2)
+            builder.addField(data[curIdx]);
+    }
+
+    /**
+     * Write collected frames and pop them.
+     *
+     * @param writer Writer.
+     * @param fieldCnt Count.
+     * @param compactFooter Whether footer should be written in compact form.
+     * @return Amount of bytes dedicated to each field offset. Could be 1, 2 or 4.
+     */
+    public int write(BinaryWriterExImpl writer, int fieldCnt, boolean compactFooter) {
+        int startIdx = idx - fieldCnt * 2;
+
+        assert startIdx >= 0;
+
+        int lastOffset = data[idx - 1];
+
+        int res;
+
+        if (compactFooter) {
+            if (lastOffset < MAX_OFFSET_1) {
+                for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
+                    writer.writeByte((byte)data[curIdx]);
+
+                res = PortableUtils.OFFSET_1;
+            }
+            else if (lastOffset < MAX_OFFSET_2) {
+                for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
+                    writer.writeShort((short)data[curIdx]);
+
+                res = PortableUtils.OFFSET_2;
+            }
+            else {
+                for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
+                    writer.writeInt(data[curIdx]);
+
+                res = PortableUtils.OFFSET_4;
+            }
+        }
+        else {
+            if (lastOffset < MAX_OFFSET_1) {
+                for (int curIdx = startIdx; curIdx < idx;) {
+                    writer.writeInt(data[curIdx++]);
+                    writer.writeByte((byte) data[curIdx++]);
+                }
+
+                res = PortableUtils.OFFSET_1;
+            }
+            else if (lastOffset < MAX_OFFSET_2) {
+                for (int curIdx = startIdx; curIdx < idx;) {
+                    writer.writeInt(data[curIdx++]);
+                    writer.writeShort((short)data[curIdx++]);
+                }
+
+                res = PortableUtils.OFFSET_2;
+            }
+            else {
+                for (int curIdx = startIdx; curIdx < idx;) {
+                    writer.writeInt(data[curIdx++]);
+                    writer.writeInt(data[curIdx++]);
+                }
+
+                res = PortableUtils.OFFSET_4;
+            }
+        }
+
+        return res;
+    }
+
+    /**
+     * Pop current object's frame.
+     */
+    public void pop(int fieldCnt) {
+        idx = idx - fieldCnt * 2;
+    }
+}