From 5bd2429e5d62e7885c717bda72e789f2649837be Mon Sep 17 00:00:00 2001 From: Bob Lee Date: Tue, 25 Aug 2009 22:32:37 -0700 Subject: Each time we start an SSL session, we have to find the trust anchor. This used to be an O(N) operation. If the trust anchor we're looking for was close to N, finding it could take a couple seconds. This change makes the operation O(1). --- .../javax/security/auth/x500/X500Principal.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'auth/src/main/java/javax/security') diff --git a/auth/src/main/java/javax/security/auth/x500/X500Principal.java b/auth/src/main/java/javax/security/auth/x500/X500Principal.java index fa9dfe8..efc57d1 100644 --- a/auth/src/main/java/javax/security/auth/x500/X500Principal.java +++ b/auth/src/main/java/javax/security/auth/x500/X500Principal.java @@ -141,6 +141,16 @@ public final class X500Principal implements Serializable, Principal { } } +// BEGIN android-added + private transient String canonicalName; + private synchronized String getCanonicalName() { + if (canonicalName == null) { + canonicalName = dn.getName(CANONICAL); + } + return canonicalName; + } +// END android-added + @Override public boolean equals(Object o) { if (this == o) { @@ -150,7 +160,9 @@ public final class X500Principal implements Serializable, Principal { return false; } X500Principal principal = (X500Principal) o; - return dn.getName(CANONICAL).equals(principal.dn.getName(CANONICAL)); +// BEGIN android-changed + return getCanonicalName().equals(principal.getCanonicalName()); +// END android-changed } /** @@ -196,13 +208,19 @@ public final class X500Principal implements Serializable, Principal { * mentioned above */ public String getName(String format) { +// BEGIN android-changed + if (CANONICAL.equals(format)) { + return getCanonicalName(); + } + return dn.getName(format); } @Override public int hashCode() { - return dn.getName(CANONICAL).hashCode(); + return getCanonicalName().hashCode(); } +// END android-changed @Override public String toString() { -- cgit v1.1