trivial patch to reduce allocations in nio open* methods
Michael Skells
mike.skells1 at gmail.com
Tue Mar 6 22:00:15 UTC 2018
Hi Remi,
the code in FileSystemProvider does not add to the immutable set, if we are
talking about the same method - the add of the WRITE only occurs in the
case where options are specified, and is pre-populated in the default case.
public OutputStream newOutputStream(Path path, OpenOption... options)
throws IOException
{
int len = options.length;
Set<OpenOption> opts ;
if (len == 0) {
opts = DEFAULT_OPEN_OPTIONS;
} else {
opts = new HashSet<>(len + 1);
for (OpenOption opt: options) {
if (opt == StandardOpenOption.READ)
throw new IllegalArgumentException("READ not allowed");
opts.add(opt);
}
opts.add(StandardOpenOption.WRITE);
}
return Channels.newOutputStream(newByteChannel(path, opts));
}
Files.createFile() - The usage that I was interested in is the new
input or output streams - I just looked through the other methods that
had similar patterns
What is the next step - are you looking for me to do any rework?
I dont have the ability to validate performance in the different
platforms, other than allocation (which is where I came in)
Regards
Mike
On Tue, 6 Mar 2018 at 19:05 Alan Bateman <Alan.Bateman at oracle.com> wrote:
> On 06/03/2018 18:34, Chris Hegarty wrote:
> >
> > It seems crummy, but using Set.of will require some care when
> > handling duplicate options. The code currently silently ignores
> > duplicates, if I'm not mistaken.
> I just read Rémi's mail now. So yes, it could only use Set.of for
> options.length < 2.
>
> -Alan
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/nio-dev/attachments/20180306/84870992/attachment.html>
More information about the nio-dev
mailing list