groovy
  1. groovy
  2. GROOVY-4714

@EqualsAndHashCode should allow caching of hashCode values

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8-rc-1
    • Fix Version/s: 2.1.0-rc-2, 2.1.0
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      NOTE: @ToString moved to linked issue

      For an immutable object, a hashcode value & toString value only need to be computed once and cached. Then the hashcode and toString methods can just return the cached values.

      The @ToString and @EqualsAndHashCode ast transformation should have options to allow for caching. For example:

      @ToString(cache=true)
      @EqualsAndHashCode(cache=true)

      Also, the @Immutable annotation should use the @ToString and @EqualsAndHashCode transformation with this caching capability enabled.

        Issue Links

          Activity

          Hide
          Travis added a comment -

          btw. See Effective Java 2nd ed. page 49 for details on caching of hashCodes. Josh Bloch talks about either calculating the hashcode on construction or lazily the first time it's requested.

          Show
          Travis added a comment - btw. See Effective Java 2nd ed. page 49 for details on caching of hashCodes. Josh Bloch talks about either calculating the hashcode on construction or lazily the first time it's requested.
          Hide
          Travis added a comment -

          The following method already exists on the transformation class that is used by the @EqualsAndHashCode method. The caching functionality is just not exposed in the annotation.

          EqualsAndHashCodeASTTransformation.createHashCode(ClassNode cNode, boolean cacheResult, boolean includeFields, boolean callSuper, List<String> excludes)
          
          Show
          Travis added a comment - The following method already exists on the transformation class that is used by the @EqualsAndHashCode method. The caching functionality is just not exposed in the annotation. EqualsAndHashCodeASTTransformation.createHashCode(ClassNode cNode, boolean cacheResult, boolean includeFields, boolean callSuper, List< String > excludes)
          Guillaume Laforge made changes -
          Field Original Value New Value
          Fix Version/s 1.8-rc-3 [ 17228 ]
          Fix Version/s 1.8-rc-2 [ 17176 ]
          Guillaume Laforge made changes -
          Fix Version/s 1.8-rc-4 [ 17245 ]
          Fix Version/s 1.8-rc-3 [ 17228 ]
          Guillaume Laforge made changes -
          Fix Version/s 1.7.11 [ 17244 ]
          Fix Version/s 1.8.1 [ 17223 ]
          Fix Version/s 1.9-beta-1 [ 17153 ]
          Fix Version/s 1.8-rc-4 [ 17245 ]
          Guillaume Laforge made changes -
          Fix Version/s 1.8.2 [ 17495 ]
          Fix Version/s 1.8.1 [ 17223 ]
          Guillaume Laforge made changes -
          Fix Version/s 1.9-beta-2 [ 17494 ]
          Fix Version/s 1.9-beta-1 [ 17153 ]
          Guillaume Laforge made changes -
          Fix Version/s 1.8.3 [ 17657 ]
          Fix Version/s 1.8.2 [ 17495 ]
          Guillaume Laforge made changes -
          Fix Version/s 1.9-beta-4 [ 17656 ]
          Fix Version/s 1.9-beta-3 [ 17494 ]
          Guillaume Laforge made changes -
          Fix Version/s 1.8.4 [ 17852 ]
          Fix Version/s 1.8.3 [ 17657 ]
          Guillaume Laforge made changes -
          Fix Version/s 1.9-beta-5 [ 17925 ]
          Fix Version/s 1.9-beta-4 [ 17656 ]
          Guillaume Laforge made changes -
          Fix Version/s 1.8.5 [ 18071 ]
          Fix Version/s 1.8.4 [ 17852 ]
          Guillaume Laforge made changes -
          Fix Version/s 2.0-beta-2 [ 18072 ]
          Fix Version/s 2.0-beta-1 [ 17925 ]
          Hide
          Paul King added a comment -

          At the moment, caching is always turned on for @Immutable objects and left off for other objects. You are asking for control when not using @Immutable?

          Show
          Paul King added a comment - At the moment, caching is always turned on for @Immutable objects and left off for other objects. You are asking for control when not using @Immutable ?
          Paul King made changes -
          Fix Version/s 1.7.11 [ 17244 ]
          Hide
          Travis added a comment -

          That is correct. We are creating immutable classes without using @Immutable and we would like to use these transformations with their caching behavior.

          Show
          Travis added a comment - That is correct. We are creating immutable classes without using @Immutable and we would like to use these transformations with their caching behavior.
          Guillaume Laforge made changes -
          Fix Version/s 1.8.6 [ 18245 ]
          Fix Version/s 1.8.5 [ 18071 ]
          Guillaume Laforge made changes -
          Fix Version/s 2.0-beta-3 [ 18244 ]
          Fix Version/s 2.0-beta-2 [ 18072 ]
          Guillaume Laforge made changes -
          Fix Version/s 1.8.7 [ 18317 ]
          Fix Version/s 1.8.6 [ 18245 ]
          blackdrag blackdrag made changes -
          Assignee Paul King [ paulk ]
          Guillaume Laforge made changes -
          Fix Version/s 2.0-rc-1 [ 18472 ]
          Fix Version/s 2.0-beta-3 [ 18244 ]
          Guillaume Laforge made changes -
          Fix Version/s 2.0-rc-2 [ 18550 ]
          Fix Version/s 2.0-rc-1 [ 18472 ]
          Guillaume Laforge made changes -
          Fix Version/s 2.0-rc-3 [ 18556 ]
          Fix Version/s 2.0-rc-2 [ 18550 ]
          blackdrag blackdrag made changes -
          Fix Version/s 2.0-rc-4 [ 18600 ]
          Fix Version/s 1.8.7 [ 18317 ]
          Fix Version/s 2.0-rc-3 [ 18556 ]
          CÚdric Champeau made changes -
          Fix Version/s 2.0.1 [ 18599 ]
          Fix Version/s 2.0-rc-4 [ 18600 ]
          Hide
          CÚdric Champeau added a comment -

          As an improvement, moved to 2.1.0.

          Show
          CÚdric Champeau added a comment - As an improvement, moved to 2.1.0.
          CÚdric Champeau made changes -
          Fix Version/s 2.1.0 [ 18598 ]
          Fix Version/s 2.0.1 [ 18599 ]
          Guillaume Laforge made changes -
          Fix Version/s 2.1.0-rc-1 [ 19026 ]
          Fix Version/s 2.1.0-beta-1 [ 18598 ]
          Guillaume Laforge made changes -
          Fix Version/s 2.1.0-rc-2 [ 19054 ]
          Fix Version/s 2.1.0-rc-1 [ 19026 ]
          Paul King made changes -
          Link This issue relates to GROOVY-5928 [ GROOVY-5928 ]
          Hide
          Paul King added a comment -

          Clone - split @ToString and @EqualsAndHashCode requests into two parts

          Show
          Paul King added a comment - Clone - split @ToString and @EqualsAndHashCode requests into two parts
          Paul King made changes -
          Summary @ToString, @EqualsAndHashCode should allow caching of toString & hashCode values @EqualsAndHashCode should allow caching of hashCode values
          Paul King made changes -
          Description For an immutable object, a hashcode value & toString value only need to be computed once and cached. Then the hashcode and toString methods can just return the cached values.

          The @ToString and @EqualsAndHashCode ast transformation should have options to allow for caching. For example:

          @ToString(cache=true)
          @EqualsAndHashCode(cache=true)

          Also, the @Immutable annotation should use the @ToString and @EqualsAndHashCode transformation with this caching capability enabled.
          {quote}
          NOTE: @ToString moved to linked issue
          {quote}
          For an immutable object, a hashcode value & toString value only need to be computed once and cached. Then the hashcode and toString methods can just return the cached values.

          The @ToString and @EqualsAndHashCode ast transformation should have options to allow for caching. For example:

          @ToString(cache=true)
          @EqualsAndHashCode(cache=true)

          Also, the @Immutable annotation should use the @ToString and @EqualsAndHashCode transformation with this caching capability enabled.
          Hide
          Paul King added a comment -

          the capability for caching is now exposed for hashCode generation

          Show
          Paul King added a comment - the capability for caching is now exposed for hashCode generation
          Paul King made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 2.1.0 [ 19027 ]
          Resolution Fixed [ 1 ]
          Paul King made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

            • Assignee:
              Paul King
              Reporter:
              Travis
            • Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: