I'm working on some stdlib performance improvements for integer parsing and other string handling, and I'm running into some issues.
I have a UTF8 pointer and (from contiguous string storage) and would like to efficiently read it out 64-bits (or alternatively, native UInt size) at a time. I'm ok with the remainder (%8) bytes being at either end. Two approaches I've been looking at:
UnsafeMutableRawPointer. This works well with a constant 8 byte count argument, but seems to be relatively slow when using a byte count not know at compile time (i.e. for the remainder bytes).
Copying (as above) or directly loading (which requires handling alignment) UInt64 chunks, and then masking out the garbage bytes outside of the UTF-8 buffer. However I'm not sure whether any amount of reading before or after the buffer is ever guaranteed to be safe? Or is this safe up to word size or maximum alignment size?