File tree Expand file tree Collapse file tree 2 files changed +10
-14
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 2 files changed +10
-14
lines changed Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ class ClassfileParser(
81
81
private def mismatchError (className : SimpleName ) =
82
82
throw new IOException (s " class file ' ${classfile.canonicalPath}' has location not matching its contents: contains class $className" )
83
83
84
- def run ()(using Context ): Option [Embedded ] = try ctx.base.reusableDataReader.using { reader =>
84
+ def run ()(using Context ): Option [Embedded ] = try ctx.base.reusableDataReader.withInstance { reader =>
85
85
implicit val reader2 = reader.reset(classfile)
86
86
report.debuglog(" [class] >> " + classRoot.fullName)
87
87
parseHeader()
Original file line number Diff line number Diff line change @@ -14,24 +14,20 @@ import scala.util.chaining._
14
14
*
15
15
* Ported from scala.reflect.internal.util.ReusableInstance
16
16
*/
17
- final class ReusableInstance [T <: AnyRef ] private (make : => T , enabled : Boolean ) {
18
- private [this ] val cache = if (enabled) new ArrayBuffer [T ](ReusableInstance .InitialSize ).tap(_.addOne(make)) else null
17
+ final class ReusableInstance [T <: AnyRef ] private (make : => T ) {
18
+ private [this ] val cache = new ArrayBuffer [T ](ReusableInstance .InitialSize ).tap(_.addOne(make))
19
19
private [this ] var taken = 0
20
20
21
- @ inline def using [R ](action : T => R ): R =
22
- if (! enabled)
23
- action(make)
24
- else {
25
- if (taken == cache.size)
26
- cache += make
27
- taken += 1
28
- try action(cache(taken- 1 )) finally taken -= 1
29
- }
21
+ inline def withInstance [R ](action : T => R ): R = {
22
+ if (taken == cache.size)
23
+ cache += make
24
+ taken += 1
25
+ try action(cache(taken- 1 )) finally taken -= 1
26
+ }
30
27
}
31
28
32
29
object ReusableInstance {
33
30
private final val InitialSize = 4
34
31
35
- def apply [T <: AnyRef ](make : => T ): ReusableInstance [T ] = new ReusableInstance [T ](make, enabled = true )
36
- def apply [T <: AnyRef ](make : => T , enabled : Boolean ): ReusableInstance [T ] = new ReusableInstance [T ](make, enabled = enabled)
32
+ def apply [T <: AnyRef ](make : => T ): ReusableInstance [T ] = new ReusableInstance [T ](make)
37
33
}
You can’t perform that action at this time.
0 commit comments