You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Robert Scholte (JIRA)" <ji...@apache.org> on 2008/04/21 23:01:22 UTC

[jira] Commented: (LANG-427) StringUtils code readability (method acceleration)

    [ https://issues.apache.org/jira/browse/LANG-427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12591057#action_12591057 ] 

Robert Scholte commented on LANG-427:
-------------------------------------

I can't see which unittests you've written, so it's hard to make conclusions yet.
Doesn't it have to do with an optimistic or pessimistic approach? If you're optimistic and expects the string to be blank your approach is probably faster. 
But if you expect the string not to be blank the original version is faster, I guess. (or should you use isNotBlank() in this case?)
And about the readablility: both implementations are clear enough. But I guess the speed usualy prio one 


> StringUtils code readability (method acceleration)
> --------------------------------------------------
>
>                 Key: LANG-427
>                 URL: https://issues.apache.org/jira/browse/LANG-427
>             Project: Commons Lang
>          Issue Type: Improvement
>         Environment: All systems, all plattforms
>            Reporter: Torsten
>            Priority: Trivial
>   Original Estimate: 0.08h
>  Remaining Estimate: 0.08h
>
> First of all i hope you will let me stay alive :) because this is not a critical error or even a bug. My proposal will not help to make the method run twice as fast, but I think this would make the code easier to read, test and to maintain. I tested both methods with Strings of length 1 to 10000 and with growing size of the Strings, the second method got actual faster and it *never* was slower.
> This method is from the framework:
> {code:title=StringUtils.java|borderStyle=solid}
>     public static boolean isBlank(String str) {
>         int strLen;
>         if (str == null || (strLen = str.length()) == 0) {
>             return true;
>         }
>         for (int i = 0; i < strLen; i++) {
>             if ((Character.isWhitespace(str.charAt(i)) == false)) {
>                 return false;
>             }
>         }
>         return true;
>     }
> {code}
> I think this method would have the same result:
> {code:borderStyle=solid}
>     public static final boolean isBlank(String str) {
> 	return str == null || str.trim().length() == 0;
>     }
> {code}
> Greetings from Germany
> Torsten

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.