]> Cypherpunks repositories - keks.git/commitdiff
Another compare optimisation
authorSergey Matveev <stargrave@stargrave.org>
Sat, 30 Nov 2024 22:29:00 +0000 (01:29 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 30 Nov 2024 22:29:00 +0000 (01:29 +0300)
Instead of always checking of the length, do it only when error happens.

pyac/pyac.py

index 59c038ff976b4ce8939775cb866d8deb25e1c40a2dec303d11744141f851d217..4cb9c5321e70acd3bf772a11f3b21d617581ee3f3e67b198f8d16e33026bb7aa 100755 (executable)
@@ -375,9 +375,9 @@ def loads(v, sets=False, leapsecUTCAllow=False):
                 break
             if not isinstance(k, str):
                 raise DecodeError("non-string key")
-            if len(k) == 0:
-                raise DecodeError("empty key")
             if (len(k) < len(kPrev)) or ((len(k) == len(kPrev)) and (k <= kPrev)):
+                if len(k) == 0:
+                    raise DecodeError("empty key")
                 raise DecodeError("unsorted keys")
             i, v = loads(v, sets=sets)
             if i == _EOC: