Skip to content

Commit 0fbb2c4

Browse files
committed
Avoid unnecessary implicit view on String
Using length instead of size on String to avoid a conversion call. This dump confirms there is a conversion to StringOps when using size. object StringSize { val s = "hi" println(s.size) } $ scalac -Xprint:typer StringSize.scala [[syntax trees at end of typer]] // StringSize.scala package <empty> { object StringSize extends scala.AnyRef { def <init>(): StringSize.type = { StringSize.super.<init>(); () }; private[this] val s: String = "hi"; <stable> <accessor> def s: String = StringSize.this.s; scala.this.Predef.println(scala.this.Predef.augmentString(StringSize.this.s).size) } }
1 parent ccded7d commit 0fbb2c4

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/library/scala/collection/immutable/StringLike.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ self =>
217217
pos = thisString.indexOf(separator, prev)
218218
} while (pos != -1)
219219

220-
if (prev != thisString.size)
221-
res += thisString.substring(prev, thisString.size)
220+
if (prev != thisString.length)
221+
res += thisString.substring(prev, thisString.length)
222222

223223
val initialResult = res.result()
224224
pos = initialResult.length

0 commit comments

Comments
 (0)