diff options
author | Paul Phillips <paulp@improving.org> | 2012-09-13 07:03:17 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-09-14 11:12:22 -0700 |
commit | 47587dca4d3fb7c171cff21587b42f40bab77e21 (patch) | |
tree | 4da603fb0bf26a8670bc5567e0c4ae91ef85d516 /src | |
parent | 9d84e89d27c396203e84f6ae685863210ebc1968 (diff) | |
download | scala-47587dca4d3fb7c171cff21587b42f40bab77e21.tar.gz scala-47587dca4d3fb7c171cff21587b42f40bab77e21.tar.bz2 scala-47587dca4d3fb7c171cff21587b42f40bab77e21.zip |
Optimization in ZipArchive.
There's that empty array. When compiling "trait Foo", this
took me from allocating 44,410 empty arrays to allocating
383 of them.
Diffstat (limited to 'src')
-rw-r--r-- | src/reflect/scala/tools/nsc/io/VirtualFile.scala | 2 | ||||
-rw-r--r-- | src/reflect/scala/tools/nsc/io/ZipArchive.scala | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/src/reflect/scala/tools/nsc/io/VirtualFile.scala b/src/reflect/scala/tools/nsc/io/VirtualFile.scala index be888e92e6..9061534edc 100644 --- a/src/reflect/scala/tools/nsc/io/VirtualFile.scala +++ b/src/reflect/scala/tools/nsc/io/VirtualFile.scala @@ -33,7 +33,7 @@ class VirtualFile(val name: String, override val path: String) extends AbstractF //######################################################################## // Private data - private var content = new Array[Byte](0) + private var content = Byte.emptyArray //######################################################################## // Public Methods diff --git a/src/reflect/scala/tools/nsc/io/ZipArchive.scala b/src/reflect/scala/tools/nsc/io/ZipArchive.scala index d1a91294a5..8201059ca0 100644 --- a/src/reflect/scala/tools/nsc/io/ZipArchive.scala +++ b/src/reflect/scala/tools/nsc/io/ZipArchive.scala @@ -107,14 +107,14 @@ abstract class ZipArchive(override val file: JFile) extends AbstractFile with Eq // }) dirs get path match { case Some(v) => v - case None => + case None => val parent = ensureDir(dirs, dirName(path), null) val dir = new DirEntry(path) parent.entries(baseName(path)) = dir dirs(path) = dir dir } - + protected def getDir(dirs: mutable.Map[String, DirEntry], entry: ZipEntry): DirEntry = { if (entry.isDirectory) ensureDir(dirs, entry.getName, entry) else ensureDir(dirs, dirName(entry.getName), null) @@ -177,7 +177,7 @@ final class URLZipArchive(val url: URL) extends ZipArchive(null) { class FileEntry() extends Entry(zipEntry.getName) { override val toByteArray: Array[Byte] = { val len = zipEntry.getSize().toInt - val arr = new Array[Byte](len) + val arr = if (len == 0) Byte.emptyArray else new Array[Byte](len) var offset = 0 def loop() { |