diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java b/src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java index b8be527b..f6ab73bf 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java +++ b/src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java @@ -1,5 +1,7 @@ package eu.siacs.conversations.xmpp.jid; +import android.util.LruCache; + import net.java.otr4j.session.SessionID; import java.net.IDN; @@ -12,6 +14,8 @@ import gnu.inet.encoding.StringprepException; */ public final class Jid { + private static LruCache<String,Jid> cache = new LruCache<>(1024); + private final String localpart; private final String domainpart; private final String resourcepart; @@ -62,6 +66,15 @@ public final class Jid { private Jid(final String jid) throws InvalidJidException { if (jid == null) throw new InvalidJidException(InvalidJidException.IS_NULL); + Jid fromCache = Jid.cache.get(jid); + if (fromCache != null) { + displayjid = fromCache.displayjid; + localpart = fromCache.localpart; + domainpart = fromCache.domainpart; + resourcepart = fromCache.resourcepart; + return; + } + // Hackish Android way to count the number of chars in a string... should work everywhere. final int atCount = jid.length() - jid.replace("@", "").length(); final int slashCount = jid.length() - jid.replace("/", "").length(); @@ -141,6 +154,8 @@ public final class Jid { throw new InvalidJidException(InvalidJidException.INVALID_PART_LENGTH); } + Jid.cache.put(jid,this); + this.displayjid = finaljid; } |