Commit 0fbb2c4
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
1 file changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | | - | |
221 | | - | |
| 220 | + | |
| 221 | + | |
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
| |||
0 commit comments