diff options
author | Bob Lee <crazybob@google.com> | 2009-08-25 22:32:37 -0700 |
---|---|---|
committer | Bob Lee <crazybob@google.com> | 2009-08-26 14:24:13 -0700 |
commit | 5bd2429e5d62e7885c717bda72e789f2649837be (patch) | |
tree | 442f64c158e1e3ab88e38d0cc58abe7f9bcbf0f6 /auth/src/main/java/javax/security | |
parent | 8da7f0d2e2724e8e0f1b9ae1fedb92f3b0f075f6 (diff) | |
download | libcore-5bd2429e5d62e7885c717bda72e789f2649837be.zip libcore-5bd2429e5d62e7885c717bda72e789f2649837be.tar.gz libcore-5bd2429e5d62e7885c717bda72e789f2649837be.tar.bz2 |
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).
Diffstat (limited to 'auth/src/main/java/javax/security')
-rw-r--r-- | auth/src/main/java/javax/security/auth/x500/X500Principal.java | 22 |
1 files changed, 20 insertions, 2 deletions
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() { |