Skip to content

Commit 7741fb5

Browse files
committed
Minor cleanup; add some documentation.
1 parent 65ebcc8 commit 7741fb5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

stdlib/public/core/Character.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,17 @@ public struct Character :
127127
) {
128128
// Most character literals are going to be fewer than eight UTF-8 code
129129
// 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) {
131132
var buffer: UInt64 = ~0
132133
_memcpy(
133134
dest: UnsafeMutableRawPointer(Builtin.addressof(&buffer)),
134135
src: UnsafeMutableRawPointer(start),
135136
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.
136139
let utf8Chunk = UInt64(littleEndian: buffer)
137-
let bits = MemoryLayout.size(ofValue: utf8Chunk) &* 8 &- 1
140+
let bits = maxCodeUnitCount &* 8 &- 1
138141
// Verify that the highest bit isn't set so that we can truncate it to
139142
// 63 bits.
140143
if _fastPath(utf8Chunk & (1 << numericCast(bits)) != 0) {

0 commit comments

Comments
 (0)