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

ArrayUtils removeElements methods use unnecessary HashSet

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1
    • Fix Version/s: 3.2
    • Component/s: lang.*
    • Labels:
      None

      Description

      The removeElements() methods use a HashSet to collect the indexes that need removing.

      This requires creating Integer objects for each index, and the HashSet then has to be converted into an int[] array.

      It would be more efficient to store the entries in an actual int[] array.

      The maximum size of this is the length of the values array (or the length of the input array if that is shorter).

      The array must be truncated before calling the private removeAll() method; this can be done with Arrays.copyOf(x[], length).

      However, if the arrays are very large, and most of the values do not appear in the input, this might result in using more memory than the HashSet implementation.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              sebb@apache.org Sebb
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: