Skip to content

Commit 5ffa3c8

Browse files
authored
Merge pull request #2173 from ianpartridge/string-data-conversion-perf
2 parents 3919af1 + 7704c94 commit 5ffa3c8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Foundation/NSStringAPI.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,14 @@ extension StringProtocol where Index == String.Index {
800800
using encoding: String.Encoding,
801801
allowLossyConversion: Bool = false
802802
) -> Data? {
803-
return _ns.data(
804-
using: encoding.rawValue,
805-
allowLossyConversion: allowLossyConversion)
803+
switch encoding {
804+
case .utf8:
805+
return Data(self.utf8)
806+
default:
807+
return _ns.data(
808+
using: encoding.rawValue,
809+
allowLossyConversion: allowLossyConversion)
810+
}
806811
}
807812

808813
// @property NSString* decomposedStringWithCanonicalMapping;

0 commit comments

Comments
 (0)