Module: Skylight::Core::Util::AllocationFree Private

Included in:
Normalizers::RenderNormalizer
Defined in:
lib/skylight/core/util/allocation_free.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Helpers to reduce memory allocation

Instance Method Summary collapse

Instance Method Details

#array_find(array) {|item| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Find an item in an array without allocation.

return the found item or nil, if nothing found

Parameters:

  • array (Array)

    the array to search

Yields:

  • a block called against each item until a match is found

Yield Parameters:

  • item

    an item from the array

Yield Returns:

  • (Boolean)

    whether ‘item` matches the criteria



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/skylight/core/util/allocation_free.rb', line 12

def array_find(array)
  i = 0

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

  nil
end