aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-02-24 17:21:18 +0100
committerMartin Odersky <odersky@gmail.com>2014-02-24 18:56:49 +0100
commita995ab85b7747275a1798cf29ac54466fbe82e2f (patch)
tree9ccf359de71fe9ade478932636ccba391f74b651 /src
parented7755b781bd1b444d38329cb22eacaa3fc1c005 (diff)
downloaddotty-a995ab85b7747275a1798cf29ac54466fbe82e2f.tar.gz
dotty-a995ab85b7747275a1798cf29ac54466fbe82e2f.tar.bz2
dotty-a995ab85b7747275a1798cf29ac54466fbe82e2f.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala2
-rw-r--r--src/dotty/tools/dotc/core/pickling/PickleBuffer.scala39
-rw-r--r--src/dotty/tools/dotc/core/pickling/UnPickler.scala1
-rw-r--r--src/dotty/tools/dotc/util/Positions.scala2
-rw-r--r--src/dotty/tools/dotc/util/ShowPickled.scala2
5 files changed, 25 insertions, 21 deletions
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index 7bd64a6c2..4ff6e629e 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -709,7 +709,7 @@ object SymDenotations {
s"$kindString $name"
}
- val debugString = toString+"#"+symbol.id // !!! DEBUG
+ def debugString = toString+"#"+symbol.id // !!! DEBUG
// ----- copies ------------------------------------------------------
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
diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
index 544a2ebdb..84b300a2a 100644
--- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala
+++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
@@ -15,6 +15,7 @@ import printing.Texts._
import printing.Printer
import io.AbstractFile
import util.common._
+import PickleBuffer._
import scala.reflect.internal.pickling.PickleFormat._
import Decorators._
import scala.collection.{ mutable, immutable }
diff --git a/src/dotty/tools/dotc/util/Positions.scala b/src/dotty/tools/dotc/util/Positions.scala
index 21ee788ca..293bb4a4c 100644
--- a/src/dotty/tools/dotc/util/Positions.scala
+++ b/src/dotty/tools/dotc/util/Positions.scala
@@ -125,7 +125,7 @@ object Positions {
def Position(start: Int, end: Int, point: Int): Position = {
val pointDelta = (point - start) max 0
val pos = fromOffsets(start, end, if (pointDelta >= SyntheticPointDelta) 0 else pointDelta)
- assert(pos.isSourceDerived, pos+" "+SyntheticPointDelta)
+ assert(pos.isSourceDerived)
pos
}
diff --git a/src/dotty/tools/dotc/util/ShowPickled.scala b/src/dotty/tools/dotc/util/ShowPickled.scala
index 92ce44bc6..1a9da23d5 100644
--- a/src/dotty/tools/dotc/util/ShowPickled.scala
+++ b/src/dotty/tools/dotc/util/ShowPickled.scala
@@ -149,7 +149,7 @@ object ShowPickled {
idx + "(" + s + ")"
}
)
- val flagString = buf.unpickleScalaFlags(pflags, isType).toString
+ val flagString = PickleBuffer.unpickleScalaFlags(pflags, isType).toString
out.print(" %s[%s]".format(toHexString(pflags), flagString))
}