Skip to content

Commit

Permalink
Avoid the call to BaseTypeSeq.toList in type Unification.
Browse files Browse the repository at this point in the history
The method `toList` of the `BaseTypeSeq` class creates a list
from the elements already in an array. In the Types unification,
this method was called to create a list of types that was
immediately filtered out and folded with an `exists`.

To avoid the call to `toList`, we do the following:
- Add a `toIterator` method in the `BaseTypeSeq` class. This is a
  simple counter that goes through the array at once.
- use the iterator.exists method instead.
  • Loading branch information
diesalbla authored and retronym committed Mar 12, 2019
1 parent 8e71ae3 commit a181111
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/reflect/scala/reflect/internal/BaseTypeSeqs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ trait BaseTypeSeqs {
/** Return all evaluated types in this sequence as a list */
def toList: List[Type] = elems.toList

/** Return an iterator over all evaluated types in this sequence */
def toIterator: Iterator[Type] = elems.iterator

def copy(head: Type, offset: Int): BaseTypeSeq = {
val arr = new Array[Type](elems.length + offset)
java.lang.System.arraycopy(elems, 0, arr, offset, elems.length)
Expand Down
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/internal/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3326,7 +3326,7 @@ trait Types
(tp.parents exists unifyFull) || (
// @PP: Is it going to be faster to filter out the parents we just checked?
// That's what's done here but I'm not sure it matters.
tp.baseTypeSeq.toList.tail filterNot (tp.parents contains _) exists unifyFull
tp.baseTypeSeq.toIterator.drop(1).exists(bt => !tp.parents.contains(bt) && unifyFull(bt))
)
)
)
Expand Down

0 comments on commit a181111

Please sign in to comment.