locking: Use frozenset instead of utils.UniqueSequence
authorMichael Hanselmann <hansmi@google.com>
Mon, 19 Nov 2012 21:09:47 +0000 (22:09 +0100)
committerMichael Hanselmann <hansmi@google.com>
Wed, 21 Nov 2012 01:44:24 +0000 (02:44 +0100)
In this case “frozenset” is good enough as the result's order doesn't
matter--it is the input to “sorted” (“utils.UniqueSequence” preserves
the order). “frozenset” is ca. 25% faster for this use-case.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

lib/locking.py

index e494785..7d65d33 100644 (file)
@@ -1191,7 +1191,7 @@ class LockSet:
     # they will still be there after, but this makes it a lot faster should
     # just one of them be the already wrong. Using a sorted sequence to prevent
     # deadlocks.
-    for lname in sorted(utils.UniqueSequence(names)):
+    for lname in sorted(frozenset(names)):
       try:
         lock = self.__lockdict[lname] # raises KeyError if lock is not there
       except KeyError: