Skip to content

Commit 0710549

Browse files
committed
revert UUIDv1 construction
1 parent a2278b8 commit 0710549

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

Doc/whatsnew/3.14.rst

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -675,18 +675,14 @@ uuid
675675
* Improve generation of :class:`~uuid.UUID` objects via their dedicated
676676
functions:
677677

678-
* For a given 48-bit hardware address *node* and a given 14-bit
679-
clock sequence *clock_seq*, :func:`uuid1(node=node) <uuid.uuid1>`
680-
and :func:`uuid1(clock_seq=clock_seq) <uuid.uuid1>` are 35% faster.
681-
Performances for :func:`~uuid.uuid1` remain unchanged when neither
682-
the hardware address nor the clock sequence is specified.
683-
* :func:`~uuid.uuid3` is 27% faster for 16-byte names and 8% faster
678+
* :func:`~uuid.uuid3` is 40% faster for 16-byte names and 10% faster
684679
for 1024-byte names. Performances for longer names remain unchanged.
685-
* :func:`~uuid.uuid5` is 24% faster for 16-byte names and 11% faster
680+
* :func:`~uuid.uuid5` is 38% faster for 16-byte names and 21% faster
686681
for 1024-byte names. Performances for longer names remain unchanged.
687-
* :func:`~uuid.uuid4` and :func:`~uuid.uuid8` are 20% faster.
682+
* :func:`~uuid.uuid4` is 31% faster and :func:`~uuid.uuid8` is 37% faster.
688683

689-
Overall, dedicated generation of UUID objects is 20% faster.
684+
Overall, dedicated generation of UUID objects version 3, 4, 5, and 8 is
685+
roughly 30% faster.
690686

691687
(Contributed by Bénédikt Tran in :gh:`128150`.)
692688

Lib/uuid.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -710,14 +710,12 @@ def uuid1(node=None, clock_seq=None):
710710
time_low = timestamp & 0xffffffff
711711
time_mid = (timestamp >> 32) & 0xffff
712712
time_hi_version = (timestamp >> 48) & 0x0fff
713+
clock_seq_low = clock_seq & 0xff
714+
clock_seq_hi_variant = (clock_seq >> 8) & 0x3f
713715
if node is None:
714716
node = getnode()
715-
clock_seq = clock_seq & 0x3fff
716-
int_uuid_1 = ((time_low << 96) | (time_mid << 80) |
717-
(time_hi_version << 64) | (clock_seq << 48) | node)
718-
# by construction, the variant and version bits are already cleared
719-
int_uuid_1 |= _RFC_4122_VERSION_1_FLAGS
720-
return UUID(int=int_uuid_1, version=None)
717+
return UUID(fields=(time_low, time_mid, time_hi_version,
718+
clock_seq_hi_variant, clock_seq_low, node), version=1)
721719

722720
def uuid3(namespace, name):
723721
"""Generate a UUID from the MD5 hash of a namespace UUID and a name."""
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Improve generation of :class:`~uuid.UUID` objects via their dedicated
2-
functions by 20%. Patch by Bénédikt Tran.
1+
Improve generation of :class:`~uuid.UUID` objects version 3, 4, 5, and 8
2+
via their dedicated functions by 30%. Patch by Bénédikt Tran.

0 commit comments

Comments
 (0)