Menu

1 / 3

OutputSpan and UTF8Span in Practice: Building and Parsing Without Copies in Swift 6.2

DEV Community: ios·Dheerendra Chaturvedi·about 8 hours ago
#qqzU1K6U
#devtoios#devto#dev#available#string
Long article (2153 words) — no AI summary yet.
Reading 0:00
15s threshold

This is a follow-up to my earlier post, Span, InlineArray and ~Escapable in Practice . Same setup as before: I'm an iOS developer who ported real code onto these types, I built a small package first and wrote this from it, and I'll be honest about where the shipped toolchain and the proposals don't line up yet.

Last time I looked at reading contiguous storage without copies. The two halves I kept hitting after that were the other direction — building a buffer, and parsing text. Building a byte buffer by hand meant Array(unsafeUninitializedCapacity:initializingWith:) with an inout count I had to remember to advance, or a pre-zeroed [UInt8] and an index cursor that nothing checked. Parsing text meant one of two bad choices: copy the String into [UInt8] so I could index bytes, or iterate Character s and pay for grapheme breaking on every byte even when I was looking for an ASCII colon.

OutputSpan (SE-0485) and UTF8Span (SE-0464) are the stdlib's answers.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.