aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2015-03-04 19:56:24 +0100
committeriNPUTmice <daniel@gultsch.de>2015-03-04 19:56:24 +0100
commite10c4e78f17dd7f428c139f1f4c29feb97b64099 (patch)
treedeba984189a8e54263d7b4ec11c1c0406cdd91a2
parentac577fe4fd36e56ff492d588af5bb427b98d915e (diff)
experimantal in memory jid caching
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/jid/Jid.java15
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;
}