On Sat, 5 Jun 2021 15:17:09 GMT, Michael Strauß <[email protected]> wrote:
>> In that case, it might be clearer and simpler to just call `trim()` on the
>> input String before doing anything with it, unless there is a reason not to.
>
> My idea was to avoid repeatedly allocating a new String with the data
> contained in the URI. Since `matchScheme` is called at least twice (maybe
> more), that would be a total of at least three copies of the URI data until
> we parse it. Granted, this would only apply for URIs that contain leading or
> trailing whitespace (since `trim()` is specified to return the same String
> instance if it contains no leading or trailing whitespace).
I see. How about something like this then?
if (uri == null || uri.isEmpty()) {
return false;
}
if (Character.isWhiteSpace(uri.charAt(0)) {
uri = uri.trim();
}
if (uri.length() < 6) {
return false;
}
The rest of the method can then work on a trimmed string.
-------------
PR: https://git.openjdk.java.net/jfx/pull/508