RFR: 8297814: (fs) Re-visit Path.getExtension return value
Stuart Marks
smarks at openjdk.org
Tue Dec 6 20:05:54 UTC 2022
On Tue, 6 Dec 2022 19:03:38 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
>> src/java.base/share/classes/java/nio/file/Path.java line 278:
>>
>>> 276: * return "";
>>> 277: * else if (lastPeriod == fileName.length() - 1)
>>> 278: * return ".";
>>
>> I believe you could remove these two lines (277-278) - as the case where the last period is the last character in the string should now fold into the case where it is followed by some (non-period) characters.
>
> Yes, I was aware of that but decided to leave it in and get comments.
Since this is part of the specification, the simpler it is, the better.
>> src/java.base/share/classes/java/nio/file/Path.java line 305:
>>
>>> 303: // the extension is "." if the last dot is the last character
>>> 304: if (lastDot == fileNameString.length() - 1) // lastDot > 0
>>> 305: return ".";
>>
>> Although this is not needed it's probably a good optimization.
>
> That was my thought.
I'm not sure this is a useful optimization. It does a bit more computation in order to save a string allocation. It probably doesn't occur very frequently though so I don't think this saves much.
-------------
PR: https://git.openjdk.org/jdk/pull/11545
More information about the nio-dev
mailing list