Groovy
  1. Groovy
  2. GROOVY-4714

@EqualsAndHashCode should allow caching of hashCode values

    Details

    • Type: Improvement Improvement
    • Status: 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

      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

          Travis Schneeberger created issue -
          Hide
          Travis Schneeberger 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 Schneeberger 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 Schneeberger 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 Schneeberger 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 Delcroix made changes -
          Field Original Value New Value
          Fix Version/s 1.8-rc-2 [ 17176 ]
          Fix Version/s 1.8-rc-3 [ 17228 ]
          Guillaume Delcroix made changes -
          Fix Version/s 1.8-rc-4 [ 17245 ]
          Fix Version/s 1.8-rc-3 [ 17228 ]
          Guillaume Delcroix made changes -
          Fix Version/s 1.8.1 [ 17223 ]
          Fix Version/s 1.8-rc-4 [ 17245 ]
          Fix Version/s 1.9-beta-1 [ 17153 ]
          Fix Version/s 1.7.11 [ 17244 ]
          Guillaume Delcroix made changes -
          Fix Version/s 1.8.1 [ 17223 ]
          Fix Version/s 1.8.2 [ 17495 ]
          Guillaume Delcroix made changes -
          Fix Version/s 1.9-beta-2 [ 17494 ]
          Fix Version/s 1.9-beta-1 [ 17153 ]
          Guillaume Delcroix made changes -
          Fix Version/s 1.8.3 [ 17657 ]
          Fix Version/s 1.8.2 [ 17495 ]
          Guillaume Delcroix made changes -
          Fix Version/s 1.9-beta-3 [ 17494 ]
          Fix Version/s 1.9-beta-4 [ 17656 ]
          Guillaume Delcroix made changes -
          Fix Version/s 1.8.4 [ 17852 ]
          Fix Version/s 1.8.3 [ 17657 ]
          Guillaume Delcroix made changes -
          Fix Version/s 1.9-beta-4 [ 17656 ]
          Fix Version/s 1.9-beta-5 [ 17925 ]
          Guillaume Delcroix made changes -
          Fix Version/s 1.8.5 [ 18071 ]
          Fix Version/s 1.8.4 [ 17852 ]
          Guillaume Delcroix made changes -
          Fix Version/s 2.0-beta-1 [ 17925 ]
          Fix Version/s 2.0-beta-2 [ 18072 ]
          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 Schneeberger 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 Schneeberger 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 Delcroix made changes -
          Fix Version/s 1.8.6 [ 18245 ]
          Fix Version/s 1.8.5 [ 18071 ]
          Guillaume Delcroix made changes -
          Fix Version/s 2.0-beta-2 [ 18072 ]
          Fix Version/s 2.0-beta-3 [ 18244 ]
          Guillaume Delcroix made changes -
          Fix Version/s 1.8.6 [ 18245 ]
          Fix Version/s 1.8.7 [ 18317 ]
          Jochen Theodorou made changes -
          Assignee Paul King [ paulk ]
          Guillaume Delcroix made changes -
          Fix Version/s 2.0-rc-1 [ 18472 ]
          Fix Version/s 2.0-beta-3 [ 18244 ]
          Guillaume Delcroix made changes -
          Fix Version/s 2.0-rc-1 [ 18472 ]
          Fix Version/s 2.0-rc-2 [ 18550 ]
          Guillaume Delcroix made changes -
          Fix Version/s 2.0-rc-3 [ 18556 ]
          Fix Version/s 2.0-rc-2 [ 18550 ]
          Jochen Theodorou 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-rc-4 [ 18600 ]
          Fix Version/s 2.0.1 [ 18599 ]
          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.0.1 [ 18599 ]
          Fix Version/s 2.1.0 [ 18598 ]
          Guillaume Delcroix made changes -
          Fix Version/s 2.1.0-beta-1 [ 18598 ]
          Fix Version/s 2.1.0-rc-1 [ 19026 ]
          Guillaume Delcroix 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 -
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Resolved [ 5 ]
          Fix Version/s 2.1.0 [ 19027 ]
          Paul King made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
          Mark Thomas made changes -
          Workflow jira [ 12733644 ] Default workflow, editable Closed status [ 12745439 ]
          Mark Thomas made changes -
          Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
          Mark Thomas made changes -
          Workflow jira [ 12971154 ] Default workflow, editable Closed status [ 12978939 ]
          Transition Time In Source Status Execution Times Last Executer Last Execution Date
          Open Open Resolved Resolved
          682d 6h 6m 1 Paul King 17/Jan/13 16:56
          Resolved Resolved Closed Closed
          23h 10m 1 Paul King 18/Jan/13 16:06

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Development