Ir al contenido

Large Collection Copy (ARCH6086)

Esta página aún no está disponible en tu idioma.

Key ruby.performance.large-collection-copy · Severity info · Category performance

Materializing a whole collection with to_a when only the first few elements are needed allocates needless memory. Use lazy evaluation or slicing.

def first_three(enumerator)
enumerator.to_a.first(3)
end
def first_three(enumerator)
enumerator.first(3)
end

Slice directly or use lazy enumeration instead of copying the entire collection.