summary refs log tree commit diff
path: root/synapse/util/caches/__init__.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-03-23 16:34:59 +0000
committerErik Johnston <erik@matrix.org>2016-03-23 16:41:54 +0000
commit8122ad7bab74b1a52188e350ca605033a9eca28e (patch)
treedccf33e860071251238ccdf5c1b6dbab9270e6eb /synapse/util/caches/__init__.py
parentDon't bother interning keys that are already interned (diff)
downloadsynapse-8122ad7bab74b1a52188e350ca605033a9eca28e.tar.xz
Simplify intern_dict
Diffstat (limited to 'synapse/util/caches/__init__.py')
-rw-r--r--synapse/util/caches/__init__.py27
1 files changed, 10 insertions, 17 deletions
diff --git a/synapse/util/caches/__init__.py b/synapse/util/caches/__init__.py
index 838cec45fe..d53569ca49 100644
--- a/synapse/util/caches/__init__.py
+++ b/synapse/util/caches/__init__.py
@@ -65,27 +65,20 @@ def intern_string(string):
 def intern_dict(dictionary):
     """Takes a dictionary and interns well known keys and their values
     """
-    return _intern_known_values({
-        _intern_key(key): value for key, value in dictionary.items()
-    })
+    return {
+        KNOWN_KEYS.get(key, key): _intern_known_values(key, value)
+        for key, value in dictionary.items()
+    }
 
 
-def _intern_known_values(dictionary):
+def _intern_known_values(key, value):
     intern_str_keys = ("event_id", "room_id")
     intern_unicode_keys = ("sender", "user_id", "type", "state_key")
 
-    for key in intern_str_keys:
-        val = dictionary.get(key, None)
-        if val is not None:
-            dictionary[key] = intern(val.encode('ascii'))
+    if key in intern_str_keys:
+        return intern(value.encode('ascii'))
 
-    for key in intern_unicode_keys:
-        val = dictionary.get(key, None)
-        if val is not None:
-            dictionary[key] = intern_string(val)
+    if key in intern_unicode_keys:
+        return intern_string(value)
 
-    return dictionary
-
-
-def _intern_key(key):
-    return KNOWN_KEYS.get(key, key)
+    return value