ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [5/5] ignite git commit: IGNITE-1816: Prepared builder for actual implementation.
Date Thu, 05 Nov 2015 08:06:40 GMT
IGNITE-1816: Prepared builder for actual implementation.


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

Branch: refs/heads/ignite-1816
Commit: d311c5dd5d8a1ac9fc6ecd58b56c6f5257f727c5
Parents: 425f26f
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Wed Nov 4 17:40:24 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Wed Nov 4 17:40:24 2015 +0300

----------------------------------------------------------------------
 .../internal/portable/PortableObjectImpl.java   |  8 ++--
 .../portable/PortableObjectOffheapImpl.java     |  8 ++--
 .../internal/portable/PortableReaderExImpl.java | 26 ++++++------
 .../ignite/internal/portable/PortableUtils.java | 15 ++++++-
 .../portable/builder/PortableBuilderImpl.java   | 44 +++++++++++---------
 5 files changed, 58 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/d311c5dd/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
index 1d1be2b..33dfe62 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectImpl.java
@@ -269,15 +269,15 @@ public final class PortableObjectImpl extends PortableObjectEx implements
Extern
         int schemaOffset = PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
 
         short flags = PortablePrimitives.readShort(arr, start + GridPortableMarshaller.FLAGS_POS);
-        int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
+        int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
 
-        int fieldOffsetPos = start + schemaOffset + order * (4 + fieldOffsetSize) + 4;
+        int fieldOffsetPos = start + schemaOffset + order * (4 + fieldOffsetLen) + 4;
 
         int fieldPos;
 
-        if (fieldOffsetSize == PortableUtils.OFFSET_1)
+        if (fieldOffsetLen == PortableUtils.OFFSET_1)
             fieldPos = start + ((int)PortablePrimitives.readByte(arr, fieldOffsetPos) &
0xFF);
-        else if (fieldOffsetSize == PortableUtils.OFFSET_2)
+        else if (fieldOffsetLen == PortableUtils.OFFSET_2)
             fieldPos = start + ((int)PortablePrimitives.readShort(arr, fieldOffsetPos) &
0xFFFF);
         else
             fieldPos = start + PortablePrimitives.readInt(arr, fieldOffsetPos);

http://git-wip-us.apache.org/repos/asf/ignite/blob/d311c5dd/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
index 3027f76..1a4e448 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableObjectOffheapImpl.java
@@ -211,15 +211,15 @@ public class PortableObjectOffheapImpl extends PortableObjectEx implements
Exter
         int schemaOffset = PortablePrimitives.readInt(ptr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
 
         short flags = PortablePrimitives.readShort(ptr, start + GridPortableMarshaller.FLAGS_POS);
-        int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
 
-        int fieldOffsetPos = start + schemaOffset + order * (4 + fieldOffsetSize) + 4;
+        int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
+        int fieldOffsetPos = start + schemaOffset + order * (4 + fieldOffsetLen) + 4;
 
         int fieldPos;
 
-        if (fieldOffsetSize == PortableUtils.OFFSET_1)
+        if (fieldOffsetLen == PortableUtils.OFFSET_1)
             fieldPos = start + ((int)PortablePrimitives.readByte(ptr, fieldOffsetPos) &
0xFF);
-        else if (fieldOffsetSize == PortableUtils.OFFSET_2)
+        else if (fieldOffsetLen == PortableUtils.OFFSET_2)
             fieldPos = start + ((int)PortablePrimitives.readShort(ptr, fieldOffsetPos) &
0xFFFF);
         else
             fieldPos = start + PortablePrimitives.readInt(ptr, fieldOffsetPos);

http://git-wip-us.apache.org/repos/asf/ignite/blob/d311c5dd/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 09eb9d9..c774e34 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
@@ -160,12 +160,12 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
     /** Schema Id. */
     private int schemaId;
 
-    /** Offset size in bytes. */
-    private int offsetSize;
-
     /** Whether field IDs exist. */
     private int fieldIdLen;
 
+    /** Offset size in bytes. */
+    private int fieldOffsetLen;
+
     /** Object schema. */
     private PortableSchema schema;
 
@@ -226,19 +226,19 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
 
         short flags = in.readShort();
 
-        offsetSize = PortableUtils.fieldOffsetSize(flags);
-        fieldIdLen = PortableUtils.isNoFieldIds(flags) ? 0 : PortableUtils.FIELD_ID_LEN;
+        fieldIdLen = PortableUtils.fieldIdLength(flags);
+        fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
 
         typeId = in.readIntPositioned(start + GridPortableMarshaller.TYPE_ID_POS);
 
-        IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(in, start,
offsetSize);
+        IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(in, start,
fieldOffsetLen);
 
         footerStart = footer.get1();
         footerLen = footer.get2() - footerStart;
 
         schemaId = in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_ID_POS);
 
-        rawOff = PortableUtils.rawOffsetAbsolute(in, start, offsetSize);
+        rawOff = PortableUtils.rawOffsetAbsolute(in, start, fieldOffsetLen);
 
         if (typeId == UNREGISTERED_TYPE_ID) {
             // Skip to the class name position.
@@ -2582,7 +2582,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
 
             fields.put(fieldId, idx++);
 
-            searchPos += PortableUtils.FIELD_ID_LEN + offsetSize;
+            searchPos += PortableUtils.FIELD_ID_LEN + fieldOffsetLen;
         }
 
         return new PortableSchema(fields);
@@ -2610,14 +2610,14 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
 
                 if (id0 == id) {
                     int pos = start + PortableUtils.fieldOffsetRelative(in, searchPos + PortableUtils.FIELD_ID_LEN,
-                        offsetSize);
+                        fieldOffsetLen);
 
                     in.position(pos);
 
                     return pos;
                 }
 
-                searchPos += PortableUtils.FIELD_ID_LEN + offsetSize;
+                searchPos += PortableUtils.FIELD_ID_LEN + fieldOffsetLen;
             }
         }
         else {
@@ -2644,9 +2644,9 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
             int order = schema.order(id);
 
             if (order != PortableSchema.ORDER_NOT_FOUND) {
-                int offsetPos = footerStart + order * (fieldIdLen + offsetSize) + fieldIdLen;
+                int offsetPos = footerStart + order * (fieldIdLen + fieldOffsetLen) + fieldIdLen;
 
-                int pos = start + PortableUtils.fieldOffsetRelative(in, offsetPos, offsetSize);
+                int pos = start + PortableUtils.fieldOffsetRelative(in, offsetPos, fieldOffsetLen);
 
                 in.position(pos);
 
@@ -2665,7 +2665,7 @@ public class PortableReaderExImpl implements PortableReader, PortableRawReaderEx
     private boolean hasLowFieldsCount(int footerLen) {
         assert hdrParsed;
 
-        return footerLen < ((offsetSize + fieldIdLen) << 3);
+        return footerLen < ((fieldOffsetLen + fieldIdLen) << 3);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/d311c5dd/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 78c66cc..b760849 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
@@ -677,11 +677,12 @@ public class PortableUtils {
     }
 
     /**
-     * Get offset size for the given flags.
+     * Get offset length for the given flags.
+     *
      * @param flags Flags.
      * @return Offset size.
      */
-    public static int fieldOffsetSize(short flags) {
+    public static int fieldOffsetLength(short flags) {
         if ((flags & FLAG_OFFSET_ONE_BYTE) == FLAG_OFFSET_ONE_BYTE)
             return OFFSET_1;
         else if ((flags & FLAG_OFFSET_TWO_BYTES) == FLAG_OFFSET_TWO_BYTES)
@@ -691,6 +692,16 @@ public class PortableUtils {
     }
 
     /**
+     * Get field ID length.
+     *
+     * @param flags Flags.
+     * @return Field ID length.
+     */
+    public static int fieldIdLength(short flags) {
+        return isNoFieldIds(flags) ? 0 : FIELD_ID_LEN;
+    }
+
+    /**
      * Get relative field offset.
      *
      * @param stream Stream.

http://git-wip-us.apache.org/repos/asf/ignite/blob/d311c5dd/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 104eb4c..cc78770 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
@@ -229,26 +229,28 @@ public class PortableBuilderImpl implements PortableBuilder {
                     assignedFldsById = Collections.emptyMap();
 
                 // Get footer details.
-                int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
+                int fieldIdLen = PortableUtils.fieldIdLength(flags);
+                int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
 
-                IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader,
start, fieldOffsetSize);
+                IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader,
start, fieldOffsetLen);
 
                 int footerPos = footer.get1();
                 int footerEnd = footer.get2();
 
                 // Get raw position.
-                int rawPos = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetSize);
+                int rawPos = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetLen);
 
                 // Position reader on data.
                 reader.position(start + hdrLen);
 
-                while (reader.position() + 4 < rawPos) {
+                while (reader.position() + fieldIdLen < rawPos) {
                     int fieldId = reader.readIntPositioned(footerPos);
-                    int fieldLen = fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldOffsetSize).get2();
+                    int fieldLen =
+                        fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldIdLen,
fieldOffsetLen).get2();
 
                     int postPos = reader.position() + fieldLen; // Position where reader
will be placed afterwards.
 
-                    footerPos += 4 + fieldOffsetSize;
+                    footerPos += fieldIdLen + fieldOffsetLen;
 
                     if (assignedFldsById.containsKey(fieldId)) {
                         Object assignedVal = assignedFldsById.remove(fieldId);
@@ -367,9 +369,9 @@ public class PortableBuilderImpl implements PortableBuilder {
 
             if (reader != null) {
                 // Write raw data if any.
-                int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
+                int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
 
-                int rawOff = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetSize);
+                int rawOff = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetLen);
                 int footerStart = PortableUtils.footerStartAbsolute(reader, start);
 
                 if (rawOff < footerStart) {
@@ -402,25 +404,26 @@ public class PortableBuilderImpl implements PortableBuilder {
      * @param footerPos Field position inside the footer (absolute).
      * @param footerEnd Footer end (absolute).
      * @param rawPos Raw data position (absolute).
-     * @param fieldOffsetSize Size of field's offset.
+     * @param fieldIdLen Field ID length.
+     * @param fieldOffsetLen Field offset length.
      * @return Tuple with field position and length.
      */
     private IgniteBiTuple<Integer, Integer> fieldPositionAndLength(int footerPos, int
footerEnd, int rawPos,
-        int fieldOffsetSize) {
+        int fieldIdLen, int fieldOffsetLen) {
         // Get field offset first.
-        int fieldOffset = PortableUtils.fieldOffsetRelative(reader, footerPos + 4, fieldOffsetSize);
+        int fieldOffset = PortableUtils.fieldOffsetRelative(reader, footerPos + fieldIdLen,
fieldOffsetLen);
         int fieldPos = start + fieldOffset;
 
         // Get field length.
         int fieldLen;
 
-        if (footerPos + 4 + fieldOffsetSize == footerEnd)
+        if (footerPos + fieldIdLen + fieldOffsetLen == 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 = PortableUtils.fieldOffsetRelative(reader, footerPos + 4
+ fieldOffsetSize + 4,
-                fieldOffsetSize);
+            int nextFieldOffset = PortableUtils.fieldOffsetRelative(reader,
+                footerPos + fieldIdLen + fieldOffsetLen + fieldIdLen, fieldOffsetLen);
 
             fieldLen = nextFieldOffset - fieldOffset;
         }
@@ -433,29 +436,30 @@ public class PortableBuilderImpl implements PortableBuilder {
      */
     private void ensureReadCacheInit() {
         if (readCache == null) {
-            int fieldOffsetSize = PortableUtils.fieldOffsetSize(flags);
+            int fieldIdLen = PortableUtils.fieldIdLength(flags);
+            int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
 
             Map<Integer, Object> readCache = new HashMap<>();
 
-            IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader,
start, fieldOffsetSize);
+            IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader,
start, fieldOffsetLen);
 
             int footerPos = footer.get1();
             int footerEnd = footer.get2();
 
-            int rawPos = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetSize);
+            int rawPos = PortableUtils.rawOffsetAbsolute(reader, start, fieldOffsetLen);
 
-            while (footerPos + 4 < footerEnd) {
+            while (footerPos + fieldIdLen < footerEnd) {
                 int fieldId = reader.readIntPositioned(footerPos);
 
                 IgniteBiTuple<Integer, Integer> posAndLen =
-                    fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldOffsetSize);
+                    fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldIdLen, fieldOffsetLen);
 
                 Object val = reader.getValueQuickly(posAndLen.get1(), posAndLen.get2());
 
                 readCache.put(fieldId, val);
 
                 // Shift current footer position.
-                footerPos += 4 + fieldOffsetSize;
+                footerPos += fieldIdLen + fieldOffsetLen;
             }
 
             this.readCache = readCache;


Mime
View raw message