If both sets are sorted, this can be faster if you get the iterator for each and manually iterate:

```
if (other is TreeSet) {
  var i1 = iterator;
  var i2 = other.iterator;
  var hasMore1 = i1.moveNext();
  var hasMore2 = i2.moveNext();
  while(hasMore1 && hasMore2) {
    var c = comparator(i1.current, i2.current);
    if (c == 0) set.add(i1.current);
    if (c <= 0) hasMore1 = i1.moveNext();
    if (c >= 0) hasMore2 = i2.moveNext();
  }
  return set;
}
```