ruby-concurrency/thread_safe

View on GitHub

Showing 181 of 329 total issues

Method split_bin has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def split_bin(new_table, i, node, node_hash)
      bit          = new_table.size >> 1 # bit to split on
      run_bit      = node_hash & bit
      last_run     = nil
      low          = nil
Severity: Minor
Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 1 hr to fix

    Method splitTreeBin has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        private static void splitTreeBin(AtomicReferenceArray<Node> nextTab, int i, TreeBin t) {
            int bit = nextTab.length() >>> 1;
            TreeBin lt = new TreeBin();
            TreeBin ht = new TreeBin();
            int lc = 0, hc = 0;

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method splitTreeBin has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        private static void splitTreeBin(Node[] nextTab, int i, TreeBin t) {
            int bit = nextTab.length >>> 1;
            TreeBin lt = new TreeBin();
            TreeBin ht = new TreeBin();
            int lc = 0, hc = 0;
    Severity: Minor
    Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method split_bin has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def split_bin(new_table, i, node, node_hash)
          bit          = new_table.size >> 1 # bit to split on
          run_bit      = node_hash & bit
          last_run     = nil
          low          = nil
    Severity: Minor
    Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method initialize_table has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize_table
          until current_table ||= table
            if (size_ctrl = size_control) == NOW_RESIZING
              Thread.pass # lost initialization race; just spin
            else
    Severity: Minor
    Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method toArray has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            @SuppressWarnings("unchecked") public final <T> T[] toArray(T[] a) {
                long sz = map.mappingCount();
                if (sz > (long)(MAX_ARRAY_SIZE))
                    throw new OutOfMemoryError(oomeMsg);
                int m = (int)sz;
    Severity: Minor
    Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 1 hr to fix

      Method toArray has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              @SuppressWarnings("unchecked") public final <T> T[] toArray(T[] a) {
                  long sz = map.mappingCount();
                  if (sz > (long)(MAX_ARRAY_SIZE))
                      throw new OutOfMemoryError(oomeMsg);
                  int m = (int)sz;

        Method attempt_compute has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def attempt_compute(key, hash, current_table, i, node, node_hash)
              added = false
              current_table.try_lock_via_hash(i, node, node_hash) do
                predecessor_node = nil
                while true
        Severity: Minor
        Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 1 hr to fix

          Method getTreeNode has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  @SuppressWarnings("unchecked") final TreeNode getTreeNode
                  (int h, RubyObject k, TreeNode p) {
                      RubyClass c = k.getMetaClass(); boolean kNotComparable = !k.respondsTo("<=>");
                      while (p != null) {
                          int dir, ph;  RubyObject pk; RubyClass pc;
          Severity: Minor
          Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 1 hr to fix

            Method tryAwaitLock has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    final void tryAwaitLock(AtomicReferenceArray<Node> tab, int i) {
                        if (tab != null && i >= 0 && i < tab.length()) { // sanity check
                            int r = ThreadLocalRandom.current().nextInt(); // randomize spins
                            int spins = MAX_SPINS, h;
                            while (tabAt(tab, i) == this && ((h = hash) & LOCKED) != 0) {

              Method tryAwaitLock has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      final void tryAwaitLock(Node[] tab, int i) {
                          if (tab != null && i >= 0 && i < tab.length) { // sanity check
                              int r = ThreadLocalRandom.current().nextInt(); // randomize spins
                              int spins = MAX_SPINS, h;
                              while (tabAt(tab, i) == this && ((h = hash) & LOCKED) != 0) {
              Severity: Minor
              Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 1 hr to fix

                Method getTreeNode has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        @SuppressWarnings("unchecked") final TreeNode getTreeNode
                        (int h, RubyObject k, TreeNode p) {
                            RubyClass c = k.getMetaClass(); boolean kNotComparable = !k.respondsTo("<=>");
                            while (p != null) {
                                int dir, ph;  RubyObject pk; RubyClass pc;

                  Method clear has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def clear
                        return self unless current_table = table
                        current_table_size = current_table.size
                        deleted_count = i = 0
                        while i < current_table_size
                  Severity: Minor
                  Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 1 hr to fix

                    Method get_or_default has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def get_or_default(key, else_value = nil)
                          hash          = key_hash(key)
                          current_table = table
                          while current_table
                            node = current_table.volatile_get_by_hash(hash)
                    Severity: Minor
                    Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 55 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Method attempt_internal_replace has 7 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def attempt_internal_replace(key, expected_old_value, hash, current_table, i, node, node_hash)
                    Severity: Major
                    Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 50 mins to fix

                      Method attempt_get_and_set has 7 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          def attempt_get_and_set(key, value, hash, current_table, i, node, node_hash)
                      Severity: Major
                      Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 50 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                    if ((pr = p.right) != null && h >= pr.hash && (r = getTreeNode(h, k, pr)) != null)
                                                        return r;
                                                    // try to continue iterating on the left side
                                                    else if ((pl = p.left) != null && h <= pl.hash)
                                                        dir = -1;
                        Severity: Major
                        Found in ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java - About 45 mins to fix

                          Method compare_and_set has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                          Open

                                      def compare_and_set(old_value, new_value)
                                        return false unless @___mutex.try_lock
                                        begin
                                          return false unless @___value.equal? old_value
                                          @___value = new_value
                          Severity: Minor
                          Found in lib/thread_safe/util/atomic_reference.rb - About 45 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Method writeObject has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                          Open

                              @SuppressWarnings("unchecked") private void writeObject(java.io.ObjectOutputStream s)
                                      throws java.io.IOException {
                                  if (segments == null) { // for serialization compatibility
                                      segments = (Segment<K,V>[])
                                              new Segment<?,?>[DEFAULT_CONCURRENCY_LEVEL];
                          Severity: Minor
                          Found in ext/org/jruby/ext/thread_safe/jsr166e/nounsafe/ConcurrentHashMapV8.java - About 45 mins to fix

                          Cognitive Complexity

                          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                          A method's cognitive complexity is based on a few simple rules:

                          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                          • Code is considered more complex for each "break in the linear flow of the code"
                          • Code is considered more complex when "flow breaking structures are nested"

                          Further reading

                          Avoid deeply nested control flow statements.
                          Open

                                                                  if (count >= TREE_THRESHOLD)
                                                                      replaceWithTreeBin(tab, i, k);
                          Severity: Major
                          Found in ext/org/jruby/ext/thread_safe/jsr166e/ConcurrentHashMapV8.java - About 45 mins to fix
                            Severity
                            Category
                            Status
                            Source
                            Language