Scala

Scala

Made by DeepSource

Consider using the efficient alternative .reverseIterator over .reverse.iterator SC-P1010

Performance
Major

The reverse method reverses the ordering of the collection. Chaining it with iterator returns the iterator for this reversed order. However, consider using the provided suitable and efficient alternative .reverseIterator as it is defined for this very specific purpose.

This is more suitable and efficient as:

  1. There is no reversing involved, and,

  2. No resources are allocated for the intermediate buffer to hold the reversed order as the operation itself is made redundant.

Bad practice

nums.reverse.iterator

Recommended

nums.reverseIterator