You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Henri Yandell (JIRA)" <ji...@apache.org> on 2013/04/18 10:17:15 UTC

[jira] [Commented] (LANG-846) StringUtils.equals() / CharSequenceUtils.regionMatches() assumes that CharSequence.toString() implementation is effective

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

Henri Yandell commented on LANG-846:
------------------------------------

Thanks Dmitry :)

svn ci -m "Adding Dmitry Katsubo's patch from LANG-846, providing CharSequenceUtils.regionMatches with a proper green implementation instead of inefficiently converting to Strings"
Sending        src/main/java/org/apache/commons/lang3/CharSequenceUtils.java
Sending        src/test/java/org/apache/commons/lang3/StringUtilsStartsEndsWithTest.java
Transmitting file data ..
Committed revision 1469220.

                
> StringUtils.equals() / CharSequenceUtils.regionMatches() assumes that CharSequence.toString() implementation is effective
> -------------------------------------------------------------------------------------------------------------------------
>
>                 Key: LANG-846
>                 URL: https://issues.apache.org/jira/browse/LANG-846
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>    Affects Versions: 3.1
>            Reporter: Dmitry Katsubo
>            Priority: Minor
>             Fix For: 3.2
>
>         Attachments: CharSequenceUtils.patch
>
>
> In my case I have {{CharSequence}} that implements a "lazy" string which is stored on disk, and although {{toString()}} implementation is valid, it is very expensive plus can potentially cause OOM.
> Thus {{CharSequenceUtils.regionMatches()}} should really do char-by-char comparison, leaving the optimization to underlying {{CharSequence}} implementation.
> Maybe {{CharSequenceUtils.regionMatches()}} could check that passed {{CharSequence}} is standard implementation (like {{StringBuilder}}, {{StringBuffer}}) that has "effective" {{toString()}} implementation, but this implementation ends up with creating new {{String}} object and thus duplicating the character buffer. So we have classical speed/memory trade-off.
> P.S. [Line 192 of CharSequenceUtils()|http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/CharSequenceUtils.java?revision=1199894&view=markup#l192] reads
> {{TODO: Implement rather than convert to String}}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira