[foreign-memaccess+abi] RFR: 8315041: Optimize Java to C string conversion by avoiding double copy [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Mon Aug 28 12:21:04 UTC 2023


On Sun, 27 Aug 2023 19:57:01 GMT, ExE Boss <duke at openjdk.org> wrote:

>> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Drop internal property to switch between different implementations
>
> src/java.base/share/classes/java/lang/String.java line 1849:
> 
>> 1847:         } else {
>> 1848:             return false;
>> 1849:         }
> 
> The common check for `coder == LATIN1` can be extracted to its own block and use the internal `String::isLatin1()` helper method, which correctly handles the case when `COMPACT_STRINGS` is `false`:
> Suggestion:
> 
>         if (isLatin1()) {
>             if (charset == ISO_8859_1.INSTANCE) {
>                 return true;
>             } else if (charset == UTF_8.INSTANCE || charset == US_ASCII.INSTANCE) {
>                 return !StringCoding.hasNegatives(value, 0, value.length);
>             }
>         }
>         return false;

I've tweaked this code to use the `isLatin1` method, but please note that when compressed strings are disabled, the coder is always set to UTF16.

-------------

PR Review Comment: https://git.openjdk.org/panama-foreign/pull/875#discussion_r1307348768


More information about the panama-dev mailing list