mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-24 22:45:19 +00:00
Data.hexEncodedString() built each byte via String(format: "%02x", _), paying Foundation format-string parsing per byte on the hot BLE receive path (PeerID(hexData:) is called several times per received packet). Replace it with an ASCII lookup table writing into a preallocated buffer; output is byte-for-byte identical (lowercase hex). Data(hexString:) similarly allocated a two-character substring and went through integer radix parsing per byte; replace with direct nibble lookups over the UTF-8 bytes. Semantics are unchanged except that sign-prefixed pairs like "+f", which the old radix parser incorrectly accepted, are now rejected. Add round-trip, known-vector, and invalid-input tests to BitFoundationTests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>