Browse Source

GC: Replace Files methods with File alternatives

The Files.exists method has noticeably poor performance in JDK 8 and can
slow an application significantly when used to check files that do not
actually exist. The same goes for Files.notExists, Files.isDirectory and
Files.isRegularFile [1].

Replace them with their File counterpart.

[1] https://rules.sonarsource.com/java/tag/performance/RSPEC-3725

Signed-off-by: Hector Oswaldo Caballero <hector.caballero@ericsson.com>
Change-Id: I89d23b9cc74bec8e05f6b7f3e49bfd967dbb6373
tags/v4.11.0.201803080745-r
Hector Caballero 6 years ago
parent
commit
4644d15bc5

+ 2
- 2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java View File

@@ -1525,12 +1525,12 @@ public class GC {
int n = 0;
int threshold = (auto + 255) / 256;
Path dir = repo.getObjectsDirectory().toPath().resolve("17"); //$NON-NLS-1$
if (!Files.exists(dir)) {
if (!dir.toFile().exists()) {
return false;
}
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, file -> {
Path fileName = file.getFileName();
return Files.isRegularFile(file) && fileName != null
return file.toFile().isFile() && fileName != null
&& PATTERN_LOOSE_OBJECT.matcher(fileName.toString())
.matches();
})) {

Loading…
Cancel
Save