From e10c4e78f17dd7f428c139f1f4c29feb97b64099 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Wed, 4 Mar 2015 19:56:24 +0100 Subject: [PATCH] experimantal in memory jid caching --- .../java/eu/siacs/conversations/xmpp/jid/Jid.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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 b8be527b4..f6ab73bfa 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 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; }