ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [31/48] incubator-ignite git commit: # ignite-47 Use Integer.highestOneBit() to calculate table size, Integer.highestOneBit() works fast because JIT translate it to one processor instruction. (cherry picked from commit de1f71f)
Date Thu, 12 Mar 2015 10:16:17 GMT
# ignite-47 Use Integer.highestOneBit() to calculate table size, Integer.highestOneBit() works
fast because JIT translate it to one processor instruction.
(cherry picked from commit de1f71f)


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

Branch: refs/heads/ignite-394
Commit: a46067a464c80d07f0cc0b31b34b3afd3db15a8a
Parents: c799054
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Tue Mar 10 16:25:39 2015 +0300
Committer: sevdokimov <sevdokimov@gridgain.com>
Committed: Wed Mar 11 18:34:53 2015 +0300

----------------------------------------------------------------------
 .../java/org/jdk8/backport/ConcurrentHashMap8.java    | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a46067a4/modules/core/src/main/java/org/jdk8/backport/ConcurrentHashMap8.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/jdk8/backport/ConcurrentHashMap8.java b/modules/core/src/main/java/org/jdk8/backport/ConcurrentHashMap8.java
index e944961..91181d5 100644
--- a/modules/core/src/main/java/org/jdk8/backport/ConcurrentHashMap8.java
+++ b/modules/core/src/main/java/org/jdk8/backport/ConcurrentHashMap8.java
@@ -2001,16 +2001,14 @@ public class ConcurrentHashMap8<K, V>
 
     /**
      * Returns a power of two table size for the given desired capacity.
-     * See Hackers Delight, sec 3.2
      */
     private static final int tableSizeFor(int c) {
-        int n = c - 1;
-        n |= n >>> 1;
-        n |= n >>> 2;
-        n |= n >>> 4;
-        n |= n >>> 8;
-        n |= n >>> 16;
-        return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
+        if (c <= 0)
+            return 1;
+
+        int n = Integer.highestOneBit(c - 1) << 1;
+
+        return (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n;
     }
 
     /**


Mime
View raw message