Skip to content

Commit 2622fba

Browse files
committed
WIP reduce file stats in classpath setup
1 parent 44e39f2 commit 2622fba

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/compiler/scala/tools/nsc/classpath/ZipAndJarFileLookupFactory.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,16 @@ sealed trait ZipAndJarFileLookupFactory {
3636
private val cache = new FileBasedCache[ZipSettings, ClassPath with Closeable]
3737

3838
def create(zipFile: AbstractFile, settings: Settings, closeableRegistry: CloseableRegistry): ClassPath = {
39-
val disabled = (settings.YdisableFlatCpCaching.value && !settings.YforceFlatCpCaching.value) || zipFile.file == null
39+
val jfile = zipFile.file
40+
val disabled = (settings.YdisableFlatCpCaching.value && !settings.YforceFlatCpCaching.value) || jfile == null
4041
val zipSettings = ZipSettings(settings.releaseValue)
41-
cache.checkCacheability(zipFile.toURL :: Nil, checkStamps = true, disableCache = disabled) match {
42-
case Left(_) =>
43-
val result: ClassPath with Closeable = createForZipFile(zipFile, zipSettings)
44-
closeableRegistry.registerCloseable(result)
45-
result
46-
case Right(paths) =>
47-
cache.getOrCreate(zipSettings, paths, () => createForZipFile(zipFile, zipSettings), closeableRegistry, checkStamps = true)
42+
43+
if (disabled) {
44+
val result: ClassPath with Closeable = createForZipFile(zipFile, zipSettings)
45+
closeableRegistry.registerCloseable(result)
46+
result
47+
} else {
48+
cache.getOrCreate(zipSettings, Seq(jfile.toPath), () => createForZipFile(zipFile, zipSettings), closeableRegistry, checkStamps = true)
4849
}
4950
}
5051

src/reflect/scala/reflect/io/AbstractFile.scala

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import java.io.{BufferedOutputStream, ByteArrayOutputStream, IOException, InputS
1818
import java.io.{File => JFile}
1919
import java.net.URL
2020
import java.nio.ByteBuffer
21-
21+
import java.nio.file.attribute.BasicFileAttributes
22+
import java.nio.file.{Files, NoSuchFileException}
2223
import scala.collection.AbstractIterable
2324

2425
/**
@@ -46,10 +47,18 @@ object AbstractFile {
4647
* readable zip or jar archive, returns an abstract directory
4748
* backed by it. Otherwise, returns `null`.
4849
*/
49-
def getDirectory(file: File): AbstractFile =
50-
if (file.isDirectory) new PlainFile(file)
51-
else if (file.isFile && Path.isExtensionJarOrZip(file.jfile)) ZipArchive.fromFile(file)
50+
def getDirectory(file: File): AbstractFile = {
51+
val attrs = try {
52+
Files.readAttributes(file.jfile.toPath, classOf[BasicFileAttributes])
53+
} catch {
54+
case _: IOException =>
55+
return null
56+
}
57+
58+
if (attrs.isDirectory) new PlainFile(file)
59+
else if (attrs.isRegularFile && Path.isExtensionJarOrZip(file.jfile)) ZipArchive.fromFile(file)
5260
else null
61+
}
5362

5463
/**
5564
* If the specified URL exists and is a regular file or a directory, returns an

0 commit comments

Comments
 (0)