You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "orionlibs (via GitHub)" <gi...@apache.org> on 2023/06/26 14:19:14 UTC

[GitHub] [commons-text] orionlibs opened a new pull request, #430: removed unnecessary IF statement

orionlibs opened a new pull request, #430:
URL: https://github.com/apache/commons-text/pull/430

   removed unnecessary IF statement, because the Character.toChars(i) can handle both single and double-width characters


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-text] aherbert commented on a diff in pull request #430: TEXT-227: removed unnecessary IF statement

Posted by "aherbert (via GitHub)" <gi...@apache.org>.
aherbert commented on code in PR #430:
URL: https://github.com/apache/commons-text/pull/430#discussion_r1264670367


##########
src/main/java/org/apache/commons/text/AlphabetConverter.java:
##########
@@ -87,9 +87,6 @@ public final class AlphabetConverter {
      * @see "http://www.oracle.com/us/technologies/java/supplementary-142654.html"
      */
     private static String codePointToString(final int i) {
-        if (Character.charCount(i) == 1) {

Review Comment:
   Looking at the JDK source for `Character.charCount(int)`, it checks the int has no bits set in the upper 16-bits and returns 1 or 2. This check is also done in `Character.toChars(int)`. If a single char is found that method will immediately return an array with 1 character to use for the String constructor. However in recent JDKs the `String.valueOf(char)` constructor has optimisations for compact strings by storing LATIN1 charsets using 1 byte per character. These look more involved that just using a `char[]` array of size 1.
   
   So the current code could save 1 byte of storage on modern JDK implementations. I would guess it would be slower due to additional checks for LATIN1 chars but that would have to be verified with a speed test.
   
   Note that the `String.valueOf(char)` method may be internally optimised to intern LATIN1 single character strings for reuse. You could cache the ASCII alphabet for example. I cannot see this in my JDK source but it would be an option for a JDK to implement.
   
   Either variation of this method therefore has possible minor advantages. I would be reluctant to change this without a JMH test of performance across the LTS JDK releases for the two variations. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-text] garydgregory commented on a diff in pull request #430: removed unnecessary IF statement

Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #430:
URL: https://github.com/apache/commons-text/pull/430#discussion_r1242769008


##########
src/main/java/org/apache/commons/text/AlphabetConverter.java:
##########
@@ -87,9 +87,6 @@ public final class AlphabetConverter {
      * @see "http://www.oracle.com/us/technologies/java/supplementary-142654.html"
      */
     private static String codePointToString(final int i) {
-        if (Character.charCount(i) == 1) {

Review Comment:
   While undocumented with an inline comment here, this appears to be an optimization (or an attempt at least). 
   
   @kinow Do you know why the code is this way and if it should remain so? It looks like we both touched this method based on git blame and that the change might have come from a PR/Patch from someone at Paypal.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-text] orionlibs closed pull request #430: TEXT-227: removed unnecessary IF statement

Posted by "orionlibs (via GitHub)" <gi...@apache.org>.
orionlibs closed pull request #430: TEXT-227: removed unnecessary IF statement
URL: https://github.com/apache/commons-text/pull/430


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [commons-text] kinow commented on a diff in pull request #430: TEXT-227: removed unnecessary IF statement

Posted by "kinow (via GitHub)" <gi...@apache.org>.
kinow commented on code in PR #430:
URL: https://github.com/apache/commons-text/pull/430#discussion_r1264679028


##########
src/main/java/org/apache/commons/text/AlphabetConverter.java:
##########
@@ -87,9 +87,6 @@ public final class AlphabetConverter {
      * @see "http://www.oracle.com/us/technologies/java/supplementary-142654.html"
      */
     private static String codePointToString(final int i) {
-        if (Character.charCount(i) == 1) {

Review Comment:
   Sorry, Gay, I missed the previous message and only saw the notification after Alex's comment above.
   
   I don't recall about `charCount`, but Alex's explanation sounds solid. And +1 to
   
   >Either variation of this method therefore has possible minor advantages. I would be reluctant to change this without a JMH test of performance across the LTS JDK releases for the two variations.
   
   At least so we understand pros & cons of this change.
   
   Also, for performance issues text/imaging/pool, I find it easier to accept changes like this when users have experienced the performance issues or the JMH tests give a clear indication that the change won't bring issues to users with different use cases, different JVM's, different garbage collectors, etc. (i.e. if the change is being recommended by static analyzers and there are pros & cons in JMH test, then I would probably move it to the bottom of the backlog for now.)
   
   Cheers
   
   -Bruno



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org