Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-846

StringUtils.equals() / CharSequenceUtils.regionMatches() assumes that CharSequence.toString() implementation is effective

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.1
    • 3.2
    • lang.*
    • None

    Description

      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() reads

      TODO: Implement rather than convert to String

      Attachments

        1. CharSequenceUtils.patch
          3 kB
          Dmitry Katsubo

        Activity

          People

            Unassigned Unassigned
            dma_k Dmitry Katsubo
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: