trivial patch to reduce allocations in nio open* methods

Alan Bateman Alan.Bateman at oracle.com
Fri Mar 30 08:27:21 UTC 2018


On 30/03/2018 02:11, Brian Burkhalter wrote:
> I created a webrev of this patch:
>
> http://cr.openjdk.java.net/~bpb/8199124/webrev.00/ 
> <http://cr.openjdk.java.net/%7Ebpb/8199124/webrev.00/>
>
> I don’t see any problem in moving forward with it, possibly with some 
> minor cleanup.
>
Just a few comments.

The sizing of the hash map doesn't take the load factor into account. 
You might find `new HashMap<>(1 + (4 * options.length/ 3)` a bit better 
with a larger array of options.

You can use an immutable set to avoid wrapping the EnumSet, e.g.
     private static final Set<OpenOption> DEFAULT_CREATE_OPTIONS = 
Set.of(CREATE_NEW, WRITE);

-Alan


More information about the nio-dev mailing list