ruby-concurrency/thread_safe

View on GitHub
lib/thread_safe/atomic_reference_cache_backend.rb

Summary

Maintainability
F
1 wk
Test Coverage

File atomic_reference_cache_backend.rb has 613 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module ThreadSafe
  # A Ruby port of the Doug Lea's jsr166e.ConcurrentHashMapV8 class version 1.59
  # available in public domain.
  #
  # Original source code available here:
Severity: Major
Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 1 day to fix

    Method rebuild has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

        def rebuild(table)
          old_table_size = table.size
          new_table      = table.next_in_size_table
          # puts "#{old_table_size} -> #{new_table.size}"
          forwarder      = Node.new(MOVED, new_table, NULL)
    Severity: Minor
    Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 5 hrs 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

    Class AtomicReferenceCacheBackend has 38 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class AtomicReferenceCacheBackend
        class Table < Util::PowerOfTwoTuple
          def cas_new_node(i, hash, key, value)
            cas(i, nil, Node.new(hash, key, value))
          end
    Severity: Minor
    Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 5 hrs to fix

      Method internal_compute has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          def internal_compute(key, &block)
            hash          = key_hash(key)
            current_table = table || initialize_table
            while true
              if !(node = current_table.volatile_get(i = current_table.hash_to_index(hash)))
      Severity: Minor
      Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 2 hrs 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_compute has a Cognitive Complexity of 20 (exceeds 5 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 2 hrs 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 try_await_lock has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

            def try_await_lock(table, i)
              if table && i >= 0 && i < table.size # bounds check, TODO: why are we bounds checking?
                spins = SPIN_LOCK_ATTEMPTS
                randomizer = base_randomizer = Util::XorShiftRandom.get
                while equal?(table.volatile_get(i)) && self.class.locked_hash?(my_hash = hash)
      Severity: Minor
      Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 2 hrs 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 each_pair has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def each_pair
            return self unless current_table = table
            current_table_size = base_size = current_table.size
            i = base_index = 0
            while base_index < base_size
      Severity: Minor
      Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 2 hrs 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_get_and_set has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

          def attempt_get_and_set(key, value, hash, current_table, i, node, node_hash)
            node_nesting = nil
            current_table.try_lock_via_hash(i, node, node_hash) do
              node_nesting    = 1
              old_value       = nil
      Severity: Minor
      Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 2 hrs 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 get_and_set has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_and_set(key, value) # internalPut in the original CHMV8
            hash          = key_hash(key)
            current_table = table || initialize_table
            while true
              if !(node = current_table.volatile_get(i = current_table.hash_to_index(hash)))
      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 compute_if_absent has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def compute_if_absent(key)
            hash          = key_hash(key)
            current_table = table || initialize_table
            while true
              if !(node = current_table.volatile_get(i = current_table.hash_to_index(hash)))
      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 rebuild has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def rebuild(table)
            old_table_size = table.size
            new_table      = table.next_in_size_table
            # puts "#{old_table_size} -> #{new_table.size}"
            forwarder      = Node.new(MOVED, new_table, NULL)
      Severity: Minor
      Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 1 hr to fix

        Method internal_replace has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            def internal_replace(key, expected_old_value = NULL, &block)
              hash          = key_hash(key)
              current_table = table
              while current_table
                if !(node = current_table.volatile_get(i = current_table.hash_to_index(hash)))
        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 attempt_internal_replace has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            def attempt_internal_replace(key, expected_old_value, hash, current_table, i, node, node_hash)
              current_table.try_lock_via_hash(i, node, node_hash) do
                predecessor_node = nil
                old_value        = NULL
                begin
        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 clear has a Cognitive Complexity of 12 (exceeds 5 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

        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_compute_if_absent has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def attempt_internal_compute_if_absent(key, hash, current_table, i, node, node_hash)
              added = false
              current_table.try_lock_via_hash(i, node, node_hash) do
                while true
                  if node.matches?(key, hash) && NULL != (value = node.value)
        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 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 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 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 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 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 (spins -= 1) == 0
                                    Thread.pass # yield before blocking
                                  else
                                    randomizer = base_randomizer = Util::XorShiftRandom.xorshift(base_randomizer) if randomizer.zero?
                                  end
                  Severity: Major
                  Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 45 mins to fix

                    Method split_old_bin has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        def split_old_bin(table, new_table, i, node, node_hash, forwarder)
                    Severity: Minor
                    Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 45 mins to fix

                      Method attempt_internal_compute_if_absent has 6 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          def attempt_internal_compute_if_absent(key, hash, current_table, i, node, node_hash)
                      Severity: Minor
                      Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 45 mins to fix

                        Method attempt_compute has 6 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            def attempt_compute(key, hash, current_table, i, node, node_hash)
                        Severity: Minor
                        Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 45 mins to fix

                          Method lock_and_clean_up_reverse_forwarders has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              def lock_and_clean_up_reverse_forwarders(old_table, old_table_size, new_table, i, forwarder)
                          Severity: Minor
                          Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 35 mins to fix

                            Method find_value_in_node_list has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                def find_value_in_node_list(node, key, hash, pure_hash)
                                  do_check_for_resize = false
                                  while true
                                    if pure_hash == hash && node.key?(key) && NULL != (value = node.value)
                                      return value
                            Severity: Minor
                            Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 35 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 compute_if_present has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                def compute_if_present(key)
                                  new_value = nil
                                  internal_replace(key) do |old_value|
                                    if (new_value = yield(NULL == old_value ? nil : old_value)).nil?
                                      NULL
                            Severity: Minor
                            Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 35 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 compute has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                def compute(key)
                                  internal_compute(key) do |old_value|
                                    if (new_value = yield(NULL == old_value ? nil : old_value)).nil?
                                      NULL
                                    else
                            Severity: Minor
                            Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 35 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 try_to_cas_in_computed has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                                  def try_to_cas_in_computed(i, hash, key)
                                    succeeded = false
                                    new_value = nil
                                    new_node  = Node.new(locked_hash = hash | LOCKED, key, NULL)
                                    if cas(i, nil, new_node)
                            Severity: Minor
                            Found in lib/thread_safe/atomic_reference_cache_backend.rb - About 35 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

                            There are no issues that match your filters.

                            Category
                            Status