8246592: Simplify checking of boolean file attributes

Reviewed-by: rriggs, alanb
This commit is contained in:
Claes Redestad 2020-06-08 22:47:16 +02:00
parent 1786701011
commit 9cd41b6555
4 changed files with 47 additions and 9 deletions

View file

@ -26,6 +26,8 @@ import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.concurrent.TimeUnit;
/**
@ -44,6 +46,15 @@ public class FileOpen {
public String trailingSlash = "/test/dir/file/name.txt/";
public String notNormalizedFile = "/test/dir/file//name.txt";
public File tmp;
@Setup
public void setup() throws IOException {
tmp = new File("FileOpen.tmp");
tmp.createNewFile();
tmp.deleteOnExit();
}
@Benchmark
public void mix(Blackhole bh) {
bh.consume(new File(normalFile));
@ -66,4 +77,12 @@ public class FileOpen {
public File notNormalized() {
return new File(notNormalizedFile);
}
@Benchmark
public boolean booleanAttributes() {
return tmp.exists()
&& tmp.isHidden()
&& tmp.isDirectory()
&& tmp.isFile();
}
}