Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 15A6DD88F for ; Mon, 29 Oct 2012 15:32:14 +0000 (UTC) Received: (qmail 53353 invoked by uid 500); 29 Oct 2012 15:32:13 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 53039 invoked by uid 500); 29 Oct 2012 15:32:13 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 53014 invoked by uid 99); 29 Oct 2012 15:32:12 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 Oct 2012 15:32:12 +0000 Date: Mon, 29 Oct 2012 15:32:12 +0000 (UTC) From: "Dmitry Katsubo (JIRA)" To: issues@commons.apache.org Message-ID: <2108507506.39227.1351524732489.JavaMail.jiratomcat@arcas> In-Reply-To: <869126517.22190.1351092491937.JavaMail.jiratomcat@arcas> Subject: [jira] [Updated] (LANG-846) StringUtils.equals() / CharSequenceUtils.regionMatches() assumes that CharSequence.toString() implementation is effective MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/LANG-846?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Dmitry Katsubo updated LANG-846: -------------------------------- Attachment: CharSequenceUtils.patch Here goes the patch. The patch follows "slow but memory efficient" approach. > 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 > 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