mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8246592: Simplify checking of boolean file attributes
Reviewed-by: rriggs, alanb
This commit is contained in:
parent
1786701011
commit
9cd41b6555
4 changed files with 47 additions and 9 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue