diff options
author | Paul Phillips <paulp@improving.org> | 2011-05-21 17:45:58 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-05-21 17:45:58 +0000 |
commit | 9d2c066436453b78b977d44a6eb4da446aca87b2 (patch) | |
tree | d93aac5bb9110df5c8a28fd940610cba6b76bfd5 | |
parent | 3e75e7e462b27fcf64185c08eb10cce5166c9d26 (diff) | |
download | scala-9d2c066436453b78b977d44a6eb4da446aca87b2.tar.gz scala-9d2c066436453b78b977d44a6eb4da446aca87b2.tar.bz2 scala-9d2c066436453b78b977d44a6eb4da446aca87b2.zip |
Now that I've convinced myself getOrElseUpdate ...
Now that I've convinced myself getOrElseUpdate isn't a big killer
performancewise, simplified ZipArchive a bit. No review.
-rw-r--r-- | src/compiler/scala/tools/nsc/io/ZipArchive.scala | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/src/compiler/scala/tools/nsc/io/ZipArchive.scala b/src/compiler/scala/tools/nsc/io/ZipArchive.scala index 00827393bd..90cb827280 100644 --- a/src/compiler/scala/tools/nsc/io/ZipArchive.scala +++ b/src/compiler/scala/tools/nsc/io/ZipArchive.scala @@ -95,28 +95,17 @@ abstract class ZipArchive(override val file: JFile) extends AbstractFile with Eq } } - private def newDir(dirs: mutable.Map[String, DirEntry], path: String, zipEntry: ZipEntry): DirEntry = { - val parent = { - val parentPath = dirName(path) - if (dirs contains parentPath) dirs(parentPath) - else newDir(dirs, parentPath, null) - } - val dir = new DirEntry(path) - parent.entries(baseName(path)) = dir - dirs(path) = dir - dir + private def ensureDir(dirs: mutable.Map[String, DirEntry], path: String, zipEntry: ZipEntry): DirEntry = { + dirs.getOrElseUpdate(path, { + val parent = ensureDir(dirs, dirName(path), null) + val dir = new DirEntry(path) + parent.entries(baseName(path)) = dir + dir + }) } protected def getDir(dirs: mutable.Map[String, DirEntry], entry: ZipEntry): DirEntry = { - val name = entry.getName - if (entry.isDirectory) { - if (dirs contains name) dirs(name) - else newDir(dirs, name, entry) - } - else { - val path = dirName(name) - if (dirs contains path) dirs(path) - else newDir(dirs, path, null) - } + if (entry.isDirectory) ensureDir(dirs, entry.getName, entry) + else ensureDir(dirs, dirName(entry.getName), null) } } |