@@ -82,9 +82,7 @@ class TreeUnpickler(reader: TastyReader,
82
82
/** The unpickled tree */
83
83
def unpickle ()(implicit ctx : Context ): Tree = {
84
84
assert(roots != null , " unpickle without previous enterTopLevel" )
85
- val rdr = new TreeReader (reader)
86
- if (rdr.isTopLevel) rdr.readTopLevel().head
87
- else rdr.readTerm()
85
+ new TreeReader (reader).readTopLevel()
88
86
}
89
87
90
88
class Completer (owner : Symbol , reader : TastyReader ) extends LazyType {
@@ -851,19 +849,14 @@ class TreeUnpickler(reader: TastyReader,
851
849
}
852
850
}
853
851
854
- def isTopLevel (implicit ctx : Context ): Boolean =
855
- nextByte == IMPORT || nextByte == PACKAGE
852
+ def isTopLevel (implicit ctx : Context ): Boolean = nextByte == PACKAGE
856
853
857
- def readTopLevel ()(implicit ctx : Context ): List [Tree ] = {
858
- @ tailrec def read (acc : ListBuffer [Tree ]): List [Tree ] = {
859
- if (isTopLevel) {
860
- acc += readIndexedStat(NoSymbol )
861
- if (! isAtEnd) read(acc) else acc.toList
862
- }
863
- else // top-level trees which are not imports or packages are not part of tree
864
- acc.toList
865
- }
866
- read(new ListBuffer [tpd.Tree ])
854
+ /** Read the top level of a tree.
855
+ * It may be a package in case of class file tasty or a term if in a term.
856
+ */
857
+ def readTopLevel ()(implicit ctx : Context ): Tree = {
858
+ if (isTopLevel) readIndexedStat(NoSymbol )
859
+ else readTerm()
867
860
}
868
861
869
862
def readIndexedStat (exprOwner : Symbol )(implicit ctx : Context ): Tree = nextByte match {
0 commit comments