File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -127,14 +127,17 @@ public struct Character :
127
127
) {
128
128
// Most character literals are going to be fewer than eight UTF-8 code
129
129
// units; for those, build the small character representation directly.
130
- if _fastPath ( Int ( utf8CodeUnitCount) <= 8 ) {
130
+ let maxCodeUnitCount = MemoryLayout< UInt64> . size
131
+ if _fastPath ( Int ( utf8CodeUnitCount) <= maxCodeUnitCount) {
131
132
var buffer : UInt64 = ~ 0
132
133
_memcpy (
133
134
dest: UnsafeMutableRawPointer ( Builtin . addressof ( & buffer) ) ,
134
135
src: UnsafeMutableRawPointer ( start) ,
135
136
size: UInt ( utf8CodeUnitCount) )
137
+ // Copying the bytes directly from the literal into an integer assumes
138
+ // little endianness, so convert the copied data into host endianness.
136
139
let utf8Chunk = UInt64 ( littleEndian: buffer)
137
- let bits = MemoryLayout . size ( ofValue : utf8Chunk ) &* 8 &- 1
140
+ let bits = maxCodeUnitCount &* 8 &- 1
138
141
// Verify that the highest bit isn't set so that we can truncate it to
139
142
// 63 bits.
140
143
if _fastPath ( utf8Chunk & ( 1 << numericCast ( bits) ) != 0 ) {
You can’t perform that action at this time.
0 commit comments