trivial patch to reduce allocations in nio open* methods

Brian Burkhalter brian.burkhalter at
Wed Jun 20 00:23:53 UTC 2018

Picking up this thread from [1] after a few months. A new patch is available at [2]. The changes versus version .00 are at [3].

On Mar 30, 2018, at 1:27 AM, Alan Bateman <Alan.Bateman at> wrote:

> On 30/03/2018 02:11, Brian Burkhalter wrote:
>> I created a webrev of this patch:
>> <>
>> 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.

I don’t see what you are referring to. There is no use of HashMap in these classes. The HashSets are created to be of a fixed size as they are not resized later. Perhaps Set.of(E… elements) should be used to create these Sets?

> 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);

The two occurrences like this are changed according to the suggestion.



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nio-dev mailing list