Skip to content

Commit

Permalink
revert UUIDv1 construction
Browse files Browse the repository at this point in the history
  • Loading branch information
picnixz committed Dec 21, 2024
1 parent a2278b8 commit 0710549
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
14 changes: 5 additions & 9 deletions Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -675,18 +675,14 @@ uuid
* Improve generation of :class:`~uuid.UUID` objects via their dedicated
functions:

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

Overall, dedicated generation of UUID objects is 20% faster.
Overall, dedicated generation of UUID objects version 3, 4, 5, and 8 is
roughly 30% faster.

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

Expand Down
10 changes: 4 additions & 6 deletions Lib/uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,14 +710,12 @@ def uuid1(node=None, clock_seq=None):
time_low = timestamp & 0xffffffff
time_mid = (timestamp >> 32) & 0xffff
time_hi_version = (timestamp >> 48) & 0x0fff
clock_seq_low = clock_seq & 0xff
clock_seq_hi_variant = (clock_seq >> 8) & 0x3f
if node is None:
node = getnode()
clock_seq = clock_seq & 0x3fff
int_uuid_1 = ((time_low << 96) | (time_mid << 80) |
(time_hi_version << 64) | (clock_seq << 48) | node)
# by construction, the variant and version bits are already cleared
int_uuid_1 |= _RFC_4122_VERSION_1_FLAGS
return UUID(int=int_uuid_1, version=None)
return UUID(fields=(time_low, time_mid, time_hi_version,
clock_seq_hi_variant, clock_seq_low, node), version=1)

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

0 comments on commit 0710549

Please sign in to comment.