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.
Incorrect
Section titled “Incorrect”def first_three(enumerator) enumerator.to_a.first(3)endCorrect
Section titled “Correct”def first_three(enumerator) enumerator.first(3)endSlice directly or use lazy enumeration instead of copying the entire collection.