diff options
author | Adriaan Moors <adriaan@lightbend.com> | 2016-08-31 16:54:11 +0200 |
---|---|---|
committer | Adriaan Moors <adriaan@lightbend.com> | 2016-09-01 01:31:17 +0200 |
commit | 743f0d2c2a33bc8ab0c1f7bee796865672ba2fcc (patch) | |
tree | 9f7d44074ffb05806cb697102572460d01d36283 /README.md | |
parent | c0763b05dac2e3d12301e828f4f1aaf83b4e41ac (diff) | |
download | scala-743f0d2c2a33bc8ab0c1f7bee796865672ba2fcc.tar.gz scala-743f0d2c2a33bc8ab0c1f7bee796865672ba2fcc.tar.bz2 scala-743f0d2c2a33bc8ab0c1f7bee796865672ba2fcc.zip |
Lazy val without local.
Now `synchronized` is erased specially to avoid boxing,
we can drop that work around.
Note that this does add an extra cast and getter
call on the slow path, but that likely doesn't matter.
```
class C { def foo = {lazy val x = {println("a"); "A" }; x } }
```
becomes
```
def foo(): String = {
lazy <artifact> val x$lzy: scala.runtime.LazyRef[String] = new scala.runtime.LazyRef[String]();
<artifact> private def x$lzycompute(): String =
x$lzy.synchronized[String]{
if (x$lzy.initialized())
x$lzy.value() // NOTE: gets an `.asInstanceOf[String]` after erasure
else
{
x$lzy.value_=({
scala.Predef.println("a");
"A"
});
x$lzy.initialized_=(true);
x$lzy.value() // NOTE: gets an `.asInstanceOf[String]` after erasure
}
}
lazy def x(): String =
if (x$lzy.initialized())
x$lzy.value() // NOTE: gets an `.asInstanceOf[String]` after erasure
else
x$lzycompute();
x()
}
```
Diffstat (limited to 'README.md')
0 files changed, 0 insertions, 0 deletions