Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10710

operator == is slow when comparing primitive arrays and lists

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.0.5
    • groovy-runtime
    • None

    Description

      To perform checks likeĀ  a == b groovy runtime invokes method DefaultTypeTransformation.compareEqual(Object left, Object right).

      This method is OK if both the left side and the right side are arrays. But it is utterly broken if only one side of the comparison is an array:

      1. There are calls to primitiveArrayToList() before making sure whether this is really necessary. This results in creation of most likely unnecessary objects (lists). It is much better to perform more checks like 'whether the other operand is a collection or array' and 'if so whether both left and right operand have the same size'.
      2. The conversion with primitiveArrayToList() might also a break normal equals() implementation which compareEqual(Object left, Object right) falls back to if operands do not fall into the special cases. This is because the original operands are replaced with results of primitiveArrayToList() and equals() is invoked not on the original objects.

      This problem is present in the current 3.X, 4.X and 5.X versions of groovy.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            paulk Paul King
            klv_m72 L
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment