Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed
- `bytes_to_mac` renders addresses with `bytes.hex(":")` instead of a
generator over `format()`. The old form ran seven generator steps and
six `format()` calls per address, twice per Ethernet frame, and showed
up in a corpus profile as 88,200 generator calls. Measured 16–29×
faster on the call depending on run. Output is byte-for-byte
identical, and `memoryview.hex` takes a separator too, so a
decode-time view still works. No API change.

### Fixed
- **The release workflow can no longer publish untested code.** Pushing
a `v*` tag ran `uv build` and `uv publish` with no dependency on the
Expand Down
6 changes: 5 additions & 1 deletion src/netprotocols/_base.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,7 +47,11 @@ def mac_to_bytes(mac: str) -> bytes:

def bytes_to_mac(data: bytes) -> str:
"""Render 6 raw bytes as a colon-separated lowercase MAC address."""
return ":".join(format(octet, "02x") for octet in data)
# bytes.hex(sep) does this in one C call; the generator-plus-format
# equivalent it replaces ran seven generator steps and six format()
# calls per address, twice per Ethernet frame. memoryview.hex takes
# a separator too, so this still accepts a decode-time view.
return data.hex(":")


def ipv4_to_bytes(addr: str) -> bytes:
Expand Down
Loading