Просмотр исходного кода

SEC-223: Improve hashCode() performance.

Ben Alex 19 лет назад
Родитель
Сommit
36c096858d

+ 6 - 4
core/src/main/java/org/acegisecurity/providers/AbstractAuthenticationToken.java

@@ -146,10 +146,12 @@ public abstract class AbstractAuthenticationToken implements Authentication {
 
     public int hashCode() {
         int code = 31;
-
-        if (this.getAuthorities() != null) {
-            for (int i = 0; i < this.getAuthorities().length; i++) {
-                code ^= this.getAuthorities()[i].hashCode();         
+        
+        // Copy authorities to local variable for performance (SEC-223)
+        GrantedAuthority[] authorities = this.getAuthorities();
+        if (authorities != null) {
+            for (int i = 0; i < authorities.length; i++) {
+                code ^= authorities[i].hashCode();         
             }
         }