Sha256: bab2a21df065046cd9a02e44433d1e13e8ba61994c99ab2c2cb0d97ca66bd72f

Contents?: true

Size: 654 Bytes

Versions: 13

Compression:

Stored size: 654 Bytes

Contents

module Skylight
  module Util
    # Helpers to reduce memory allocation
    module AllocationFree

      # Find an item in an array without allocation.
      #
      # @param array [Array] the array to search
      # @yield a block called against each item until a match is found
      # @yieldparam item an item from the array
      # @yieldreturn [Boolean] whether `item` matches the criteria
      # return the found item or nil, if nothing found
      def array_find(array)
        i = 0

        while i < array.size
          item = array[i]
          return item if yield item
          i += 1
        end

        nil
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
skylight-1.7.2 lib/skylight/util/allocation_free.rb
skylight-1.7.1 lib/skylight/util/allocation_free.rb
skylight-1.7.0 lib/skylight/util/allocation_free.rb
skylight-1.6.1 lib/skylight/util/allocation_free.rb
skylight-1.6.0 lib/skylight/util/allocation_free.rb
skylight-1.5.1 lib/skylight/util/allocation_free.rb
skylight-1.5.0 lib/skylight/util/allocation_free.rb
skylight-1.4.4 lib/skylight/util/allocation_free.rb
skylight-1.4.3 lib/skylight/util/allocation_free.rb
skylight-1.4.2 lib/skylight/util/allocation_free.rb
skylight-1.4.1 lib/skylight/util/allocation_free.rb
skylight-1.4.0 lib/skylight/util/allocation_free.rb
skylight-1.4.0.beta.2 lib/skylight/util/allocation_free.rb