summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorAdrian Tschira <nota@notafile.com>2018-03-30 23:59:02 +0200
committerAdrian Tschira <nota@notafile.com>2018-03-31 02:00:22 +0200
commit11597ddea5c43fdd2c6593b6bf4619a7bbdf3122 (patch)
tree634541bacb9baf284e2b89036c9e0ef085b5c908 /synapse
parentMerge pull request #3043 from matrix-org/erikj/measure_state_group_creation (diff)
downloadsynapse-11597ddea5c43fdd2c6593b6bf4619a7bbdf3122.tar.xz
improve mxid check performance ~4x
Signed-off-by: Adrian Tschira <nota@notafile.com>
Diffstat (limited to 'synapse')
-rw-r--r--synapse/types.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/synapse/types.py b/synapse/types.py
index 7cb24cecb2..f1f41ccf90 100644
--- a/synapse/types.py
+++ b/synapse/types.py
@@ -12,11 +12,11 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-import string
 
 from synapse.api.errors import SynapseError
 
 from collections import namedtuple
+import re
 
 
 class Requester(namedtuple("Requester", [
@@ -214,7 +214,8 @@ class GroupID(DomainSpecificString):
         return group_id
 
 
-mxid_localpart_allowed_characters = set("_-./=" + string.ascii_lowercase + string.digits)
+# A regex that matches any valid mxid characters
+MXID_LOCALPART_REGEX = re.compile("^[_\-./=a-z0-9]*$")
 
 
 def contains_invalid_mxid_characters(localpart):
@@ -226,7 +227,7 @@ def contains_invalid_mxid_characters(localpart):
     Returns:
         bool: True if there are any naughty characters
     """
-    return any(c not in mxid_localpart_allowed_characters for c in localpart)
+    return not MXID_LOCALPART_REGEX.match(localpart)
 
 
 class StreamToken(