From a995ab85b7747275a1798cf29ac54466fbe82e2f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 24 Feb 2014 17:21:18 +0100 Subject: Misc performance improvements by eliminating stupid allocations - Avoid closure creation in Position. - Avoid creating debug string in SymDenotations - Avoid creating Flag translation tables in pickle buffers --- .../tools/dotc/core/pickling/PickleBuffer.scala | 39 ++++++++++++---------- 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'src/dotty/tools/dotc/core/pickling/PickleBuffer.scala') diff --git a/src/dotty/tools/dotc/core/pickling/PickleBuffer.scala b/src/dotty/tools/dotc/core/pickling/PickleBuffer.scala index b44d7f292..72007758c 100644 --- a/src/dotty/tools/dotc/core/pickling/PickleBuffer.scala +++ b/src/dotty/tools/dotc/core/pickling/PickleBuffer.scala @@ -166,6 +166,27 @@ class PickleBuffer(data: Array[Byte], from: Int, to: Int) { def times[T](n: Int, op: ()=>T): List[T] = if (n == 0) List() else op() :: times(n-1, op) + /** Pickle = majorVersion_Nat minorVersion_Nat nbEntries_Nat {Entry} + * Entry = type_Nat length_Nat [actual entries] + * + * Assumes that the ..Version_Nat are already consumed. + * + * @return an array mapping entry numbers to locations in + * the byte array where the entries start. + */ + def createIndex: Array[Int] = { + val index = new Array[Int](readNat()) // nbEntries_Nat + for (i <- 0 until index.length) { + index(i) = readIndex + readByte() // skip type_Nat + readIndex = readNat() + readIndex // read length_Nat, jump to next entry + } + index + } +} + +object PickleBuffer { + private final val ScalaFlagEnd = 48 private final val ChunkBits = 8 private final val ChunkSize = 1 << ChunkBits @@ -261,24 +282,6 @@ class PickleBuffer(data: Array[Byte], from: Int, to: Int) { (chunkMap(termMap), chunkMap(typeMap)) } - /** Pickle = majorVersion_Nat minorVersion_Nat nbEntries_Nat {Entry} - * Entry = type_Nat length_Nat [actual entries] - * - * Assumes that the ..Version_Nat are already consumed. - * - * @return an array mapping entry numbers to locations in - * the byte array where the entries start. - */ - def createIndex: Array[Int] = { - val index = new Array[Int](readNat()) // nbEntries_Nat - for (i <- 0 until index.length) { - index(i) = readIndex - readByte() // skip type_Nat - readIndex = readNat() + readIndex // read length_Nat, jump to next entry - } - index - } - def unpickleScalaFlags(sflags: Long, isType: Boolean): FlagSet = { val map: FlagMap = if (isType) scalaTypeFlagMap else scalaTermFlagMap val shift = ChunkBits -- cgit v1.2.3