summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2016-07-30 00:14:54 +0100
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2016-07-30 00:14:54 +0100
commit2587d82af8d7a211f7685f0a8a7a198954650586 (patch)
tree81cc5b6e9647c1160140d0b3d305fc3c5939d906
parent7ea121b115536a6a124554b7284c3aa2dd73fbe6 (diff)
downloadslixmpp-2587d82af8d7a211f7685f0a8a7a198954650586.tar.gz
slixmpp-2587d82af8d7a211f7685f0a8a7a198954650586.tar.bz2
slixmpp-2587d82af8d7a211f7685f0a8a7a198954650586.tar.xz
slixmpp-2587d82af8d7a211f7685f0a8a7a198954650586.zip
Make util.XOR about ten times faster by calling bytes only once.
-rw-r--r--slixmpp/util/misc_ops.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/slixmpp/util/misc_ops.py b/slixmpp/util/misc_ops.py
index 2e661045..1dcd6e3f 100644
--- a/slixmpp/util/misc_ops.py
+++ b/slixmpp/util/misc_ops.py
@@ -1,3 +1,4 @@
+import builtins
import sys
import hashlib
@@ -22,7 +23,6 @@ def bytes(text):
if text is None:
return b''
- import builtins
if isinstance(text, builtins.bytes):
# We already have bytes, so do nothing
return text
@@ -80,10 +80,9 @@ def XOR(x, y):
:param bytes y: A byte string
:rtype: bytes
"""
- result = b''
- for a, b in zip(x, y):
- result += bytes([a ^ b])
- return result
+ # This operation is faster with a list comprehension than with a
+ # generator, as of 2016 on python 3.5.
+ return builtins.bytes([a ^ b for a, b in zip(x, y)])
def hash(name):