Skip to content

Commit 21e7e71

Browse files
committed
Micro-optimization: Avoid nonEmpty in hot paths
1 parent 67ba7b5 commit 21e7e71

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ object Trees {
771771
def flatten[T >: Untyped](trees: List[Tree[T]]): List[Tree[T]] = {
772772
var buf: ListBuffer[Tree[T]] = null
773773
var xs = trees
774-
while (xs.nonEmpty) {
774+
while (!xs.isEmpty) {
775775
xs.head match {
776776
case Thicket(elems) =>
777777
if (buf == null) {

compiler/src/dotty/tools/dotc/core/Hashable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ trait Hashable {
6464
var h = seed
6565
var xs = tps
6666
var len = arity
67-
while (xs.nonEmpty) {
67+
while (!xs.isEmpty) {
6868
val elemHash = typeHash(bs, xs.head)
6969
if (elemHash == NotCached) return NotCached
7070
h = hashing.mix(h, elemHash)

compiler/src/dotty/tools/dotc/core/Signature.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ case class Signature(paramsSig: List[TypeName], resSig: TypeName) {
4545
final def consistentParams(that: Signature): Boolean = {
4646
@tailrec def loop(names1: List[TypeName], names2: List[TypeName]): Boolean =
4747
if (names1.isEmpty) names2.isEmpty
48-
else names2.nonEmpty && consistent(names1.head, names2.head) && loop(names1.tail, names2.tail)
48+
else !names2.isEmpty && consistent(names1.head, names2.head) && loop(names1.tail, names2.tail)
4949
loop(this.paramsSig, that.paramsSig)
5050
}
5151

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@ object Scanners {
249249
/** Are we directly in a string interpolation expression?
250250
*/
251251
private def inStringInterpolation =
252-
sepRegions.nonEmpty && sepRegions.head == STRINGLIT
252+
!sepRegions.isEmpty && sepRegions.head == STRINGLIT
253253

254254
/** Are we directly in a multiline string interpolation expression?
255255
* @pre inStringInterpolation
256256
*/
257257
private def inMultiLineInterpolation =
258-
inStringInterpolation && sepRegions.tail.nonEmpty && sepRegions.tail.head == STRINGPART
258+
inStringInterpolation && !sepRegions.tail.isEmpty && sepRegions.tail.head == STRINGPART
259259

260260
/** read next token and return last offset
261261
*/

0 commit comments

Comments
 (0)