From 9d2c066436453b78b977d44a6eb4da446aca87b2 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 21 May 2011 17:45:58 +0000 Subject: 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. --- src/compiler/scala/tools/nsc/io/ZipArchive.scala | 29 ++++++++---------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'src/compiler/scala/tools/nsc/io/ZipArchive.scala') 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) } } -- cgit v1.2.3