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

ObjectUtils.identityToString(Object) and friends should allocate builders and buffers with a size

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 3.8
    • lang.*
    • None

    Description

      The method ObjectUtils.identityToString(Object) and its friends should allocate builders and buffers with a size.

      Calling ObjectUtils.identityToString(Object) will allocate a StringBuilder and append to it. The StringBuilder will reallocate it's internal char[] at least once since most strings end up being larger than the default 16 characters initially allocated by a StringBuilder (on Oracle Java 7).

      This change computes the strings part first (class name and hex hash code string) and then allocates a StringBuilder of the right size.

      Similarly, the identityToString methods that accept an existing builder/buffer can call ensureCapacity to avoid any extraneous allocations.

      Attachments

        Activity

          People

            ggregory Gary D. Gregory
            ggregory Gary D. Gregory
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: