ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [09/11] ignite git commit: IGNITE-1770: Optimized PortableReaderContext.
Date Tue, 27 Oct 2015 14:32:14 GMT
IGNITE-1770: Optimized PortableReaderContext.


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

Branch: refs/heads/ignite-1770
Commit: f6fc097c116b99d711719566538158c1d98b34e8
Parents: 0dfdaca
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Tue Oct 27 17:10:11 2015 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Tue Oct 27 17:10:11 2015 +0300

----------------------------------------------------------------------
 .../portable/PortableReaderContext.java         | 118 +++++--------------
 .../java/org/apache/ignite/MyBenchmark.java     |  14 +--
 2 files changed, 35 insertions(+), 97 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f6fc097c/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java
index 0141d70..51fc407 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableReaderContext.java
@@ -25,11 +25,11 @@ import org.apache.ignite.portable.PortableObject;
 import org.jetbrains.annotations.Nullable;
 
 /**
- * Reader context.
- */
+* Reader context.
+*/
 class PortableReaderContext {
     /** */
-    private Map<Integer, Object> oHandles;
+    private Object oHandles;
 
     /** */
     private Map<Integer, PortableObject> poHandles;
@@ -38,13 +38,24 @@ class PortableReaderContext {
      * @param handle Handle.
      * @param obj Object.
      */
+    @SuppressWarnings("unchecked")
     void setObjectHandler(int handle, Object obj) {
         assert obj != null;
 
         if (oHandles == null)
-            oHandles = new HashMap<>(3, 1.0f);
+            oHandles = new IgniteBiTuple(handle, obj);
+        else if (oHandles instanceof IgniteBiTuple) {
+            Map map = new HashMap(3, 1.0f);
+
+            IgniteBiTuple t = (IgniteBiTuple)oHandles;
 
-        oHandles.put(handle, obj);
+            map.put(t.getKey(), t.getValue());
+            map.put(handle, obj);
+
+            oHandles = map;
+        }
+        else
+            ((Map)oHandles).put(handle, obj);
     }
 
     /**
@@ -65,7 +76,18 @@ class PortableReaderContext {
      * @return Object.
      */
     @Nullable Object getObjectByHandle(int handle) {
-        return oHandles != null ? oHandles.get(handle) : null;
+        if (oHandles != null) {
+            if (oHandles instanceof IgniteBiTuple) {
+                IgniteBiTuple t = (IgniteBiTuple)oHandles;
+
+                if ((int)t.get1() == handle)
+                    return t.get2();
+            }
+            else
+                return ((Map)oHandles).get(handle);
+        }
+
+        return null;
     }
 
     /**
@@ -81,87 +103,3 @@ class PortableReaderContext {
         return S.toString(PortableReaderContext.class, this);
     }
 }
-
-
-// TODO: Opto
-///**
-//* Reader context.
-//*/
-//class PortableReaderContext {
-//    /** */
-//    private Object oHandles;
-//
-//    /** */
-//    private Map<Integer, PortableObject> poHandles;
-//
-//    /**
-//     * @param handle Handle.
-//     * @param obj Object.
-//     */
-//    @SuppressWarnings("unchecked")
-//    void setObjectHandler(int handle, Object obj) {
-//        assert obj != null;
-//
-//        if (oHandles == null) {
-//            oHandles = new IgniteBiTuple(handle, obj);
-//        }
-//        else if (oHandles instanceof Map) {
-//            ((Map)oHandles).put(handle, obj);
-//        }
-//        else {
-//            Map map = new HashMap(3, 1.0f);
-//
-//            IgniteBiTuple t = (IgniteBiTuple)oHandles;
-//
-//            map.put(t.getKey(), t.getValue());
-//            map.put(handle, obj);
-//
-//            oHandles = map;
-//        }
-//    }
-//
-//    /**
-//     * @param handle Handle.
-//     * @param po Portable object.
-//     */
-//    void setPortableHandler(int handle, PortableObject po) {
-//        assert po != null;
-//
-//        if (poHandles == null)
-//            poHandles = new HashMap<>(3, 1.0f);
-//
-//        poHandles.put(handle, po);
-//    }
-//
-//    /**
-//     * @param handle Handle.
-//     * @return Object.
-//     */
-//    @Nullable Object getObjectByHandle(int handle) {
-//        if (oHandles != null) {
-//            if (oHandles instanceof IgniteBiTuple) {
-//                IgniteBiTuple t = (IgniteBiTuple)oHandles;
-//
-//                if (t.get1().equals(handle))
-//                    return t.get2();
-//            }
-//            else
-//                return ((Map)oHandles).get(handle);
-//        }
-//
-//        return null;
-//    }
-//
-//    /**
-//     * @param handle Handle.
-//     * @return Object.
-//     */
-//    @Nullable PortableObject getPortableByHandle(int handle) {
-//        return poHandles != null ? poHandles.get(handle) : null;
-//    }
-//
-//    /** {@inheritDoc} */
-//    @Override public String toString() {
-//        return S.toString(PortableReaderContext.class, this);
-//    }
-//}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6fc097c/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java
----------------------------------------------------------------------
diff --git a/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java b/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java
index 2c5deb1..9eba07a 100644
--- a/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java
+++ b/modules/microbench/src/main/java/org/apache/ignite/MyBenchmark.java
@@ -110,16 +110,16 @@ public class MyBenchmark {
         System.out.println(data.length);
     }
 
-    @Benchmark
-    public byte[] testAddressWrite() throws Exception {
-        return marsh.marshal(new Address());
-    }
-
 //    @Benchmark
-//    public Address testAddressRead() throws Exception {
-//        return marsh.unmarshal(marshAddrBytes, null);
+//    public byte[] testAddressWrite() throws Exception {
+//        return marsh.marshal(new Address());
 //    }
 
+    @Benchmark
+    public Address testAddressRead() throws Exception {
+        return marsh.unmarshal(marshAddrBytes, null);
+    }
+
     private static final Address addr = new Address();
 
     public static void main(String[] args) throws Exception {


Mime
View raw message