This is an automated email from the ASF dual-hosted git repository.

abulatski pushed a commit to branch STABLE-4.0
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/STABLE-4.0 by this push:
     new f722169  CAY-2517 EventManager: optimization of adding listeners
f722169 is described below

commit f7221695545fb7db67ca32ecfe470db81a444b66
Author: Arseni Bulatski <ancars...@gmail.com>
AuthorDate: Mon Jan 21 14:33:15 2019 +0300

    CAY-2517 EventManager: optimization of adding listeners
    
    (cherry picked from commit c5e0f0099a49b0aa287b523146367f59b6477f53)
---
 RELEASE-NOTES.txt                                        |  1 +
 .../main/java/org/apache/cayenne/util/Invocation.java    | 16 +++++++---------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index e669130..a27c383 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -20,6 +20,7 @@ CAY-2474 Modeler: swap buttons in dialog toolbar
 CAY-2475 Modeler: move inheritance icon to name column in objAttr table and 
objRel table
 CAY-2476 Modeler: Fixed wrong behaviour of code generation dialog
 CAY-2479 Modeler: update cgen dialog
+CAY-2517 EventManager: optimization of adding listeners
 
 Bug Fixes:
 
diff --git 
a/cayenne-server/src/main/java/org/apache/cayenne/util/Invocation.java 
b/cayenne-server/src/main/java/org/apache/cayenne/util/Invocation.java
index 23a6fdf..41c4553 100644
--- a/cayenne-server/src/main/java/org/apache/cayenne/util/Invocation.java
+++ b/cayenne-server/src/main/java/org/apache/cayenne/util/Invocation.java
@@ -37,6 +37,7 @@ public class Invocation {
     private WeakReference _target;
     private Method _method;
     private Class[] _parameterTypes;
+    private int _hashCode;
 
     /**
      * Prevent use of empty default constructor
@@ -119,6 +120,11 @@ public class Invocation {
             _method.setAccessible(true);
         }
 
+        /**
+         * IMPORTANT: include Invocation target object(not a WeakReference) 
into
+         * algorithm is used to compute hashCode.
+         */
+        _hashCode = 31 * target.hashCode() + _method.hashCode();
         _parameterTypes = parameterTypes;
         _target = new WeakReference(target);
     }
@@ -258,15 +264,7 @@ public class Invocation {
      */
     @Override
     public int hashCode() {
-        // IMPORTANT: DO NOT include Invocation target into whatever
-        // algorithm is used to compute hashCode, since it is using a
-        // WeakReference and can be released at a later time, altering
-        // hashCode, and breaking collections using Invocation as a key
-        // (e.g. event DispatchQueue)
-
-        // TODO: use Jakarta commons HashBuilder
-        int hash = 42, hashMultiplier = 59;
-        return hash * hashMultiplier + _method.hashCode();
+        return _hashCode;
     }
 
     /**

Reply via email to