Skip to content

Commit b700b76

Browse files
committed
Refactor code
1 parent b4bfd23 commit b700b76

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ object ClassfileParser {
5050
mapOver(tp)
5151
}
5252
}
53+
54+
def withReader[T](classfile: AbstractFile)(op: DataReader ?=> T)(using Context): T =
55+
ctx.base.reusableDataReader.using { reader =>
56+
op(using reader.reset(classfile))
57+
}
5358
}
5459

5560
class ClassfileParser(
@@ -81,9 +86,7 @@ class ClassfileParser(
8186
private def mismatchError(className: SimpleName) =
8287
throw new IOException(s"class file '${classfile.canonicalPath}' has location not matching its contents: contains class $className")
8388

84-
def run()(using Context): Option[Embedded] = try ctx.base.reusableDataReader.using { reader =>
85-
implicit val in: DataReader = reader.reset(classfile)
86-
89+
def run()(using Context): Option[Embedded] = try withReader(classfile) { (using in) =>
8790
report.debuglog("[class] >> " + classRoot.fullName)
8891
parseHeader()
8992
this.pool = new ConstantPool
@@ -238,9 +241,7 @@ class ClassfileParser(
238241

239242
val memberCompleter: LazyType = new LazyType {
240243

241-
def complete(denot: SymDenotation)(using Context): Unit = ctx.base.reusableDataReader.using { reader =>
242-
implicit val in: DataReader = reader.reset(classfile)
243-
244+
def complete(denot: SymDenotation)(using Context): Unit = withReader(classfile) { (using in) =>
244245
in.bp = denot.symbol.coord.toIndex
245246
val sym = denot.symbol
246247
val jflags = in.nextChar

0 commit comments

Comments
 (0)