Skip to content

Commit

Permalink
Use UnicodeScalar instead of Character for joining types
Browse files Browse the repository at this point in the history
A bit more efficient memory-wise (16 bytes + buffer -> 4 bytes).
  • Loading branch information
Wevah committed Apr 7, 2022
1 parent b07a8b4 commit 33373b4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sources/IDNA/UTS46+Loading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ extension UTS46 {

for scalar in str.unicodeScalars {
if scalar.isASCII {
type = JoiningType(rawValue: Character(scalar))
type = JoiningType(rawValue: scalar)
} else if let type = type {
if first == nil {
first = scalar
Expand Down
2 changes: 1 addition & 1 deletion Sources/IDNA/UTS46.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class UTS46 {
static let sequenceTerminator: UInt8 = 0
}

enum JoiningType: Character {
enum JoiningType: UnicodeScalar {
case causing = "C"
case dual = "D"
case right = "R"
Expand Down
4 changes: 2 additions & 2 deletions Swift/UTS46+Conversion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ extension UTS46 {
joiningType.count == 1 else { continue }

for codepoint in range {
joiningTypes[UInt32(codepoint)] = JoiningType(rawValue: joiningType.first!)!
joiningTypes[UInt32(codepoint)] = JoiningType(rawValue: joiningType.unicodeScalars.first!)!
}
}
}
Expand Down Expand Up @@ -113,7 +113,7 @@ extension UTS46 {
}

private static func joiningTypesData() -> Data {
var reverseMap: [Character: String] = ["C": "", "D": "", "L": "", "R": "", "T": ""]
var reverseMap: [UnicodeScalar: String] = ["C": "", "D": "", "L": "", "R": "", "T": ""]

for (codepoint, joiningType) in joiningTypes {
reverseMap[joiningType.rawValue]?.unicodeScalars.append(UnicodeScalar(codepoint)!)
Expand Down

0 comments on commit 33373b4

Please sign in to comment.