File tree Expand file tree Collapse file tree 2 files changed +27
-10
lines changed Expand file tree Collapse file tree 2 files changed +27
-10
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,27 @@ internal func _cocoaStringSubscript(
69
69
return _swift_stdlib_CFStringGetCharacterAtIndex ( cfSelf, position)
70
70
}
71
71
72
+ @_effects ( releasenone)
73
+ internal func _cocoaStringCopyUTF8(
74
+ _ target: _CocoaString ,
75
+ into bufPtr: UnsafeMutableBufferPointer < UInt8 >
76
+ ) -> Int ? {
77
+ let ptr = bufPtr. baseAddress. _unsafelyUnwrappedUnchecked
78
+ let len = _stdlib_binary_CFStringGetLength ( target)
79
+ var count = 0
80
+ let converted = _swift_stdlib_CFStringGetBytes (
81
+ target,
82
+ _swift_shims_CFRange ( location: 0 , length: len) ,
83
+ kCFStringEncodingUTF8,
84
+ 0 ,
85
+ 0 ,
86
+ ptr,
87
+ bufPtr. count,
88
+ & count
89
+ )
90
+ return len == converted ? count : nil
91
+ }
92
+
72
93
@_effects ( readonly)
73
94
internal func _cocoaStringCompare(
74
95
_ string: _CocoaString , _ other: _CocoaString
Original file line number Diff line number Diff line change @@ -246,16 +246,12 @@ extension _StringGuts {
246
246
internal func _foreignCopyUTF8(
247
247
into mbp: UnsafeMutableBufferPointer < UInt8 >
248
248
) -> Int ? {
249
- var ptr = mbp. baseAddress. _unsafelyUnwrappedUnchecked
250
- var numWritten = 0
251
- for cu in String ( self ) . utf8 {
252
- guard numWritten < mbp. count else { return nil }
253
- ptr. initialize ( to: cu)
254
- ptr += 1
255
- numWritten += 1
256
- }
257
-
258
- return numWritten
249
+ #if _runtime(_ObjC)
250
+ // Currently, foreign means NSString
251
+ return _cocoaStringCopyUTF8 ( _object. cocoaObject, into: mbp)
252
+ #else
253
+ fatalError ( " No foreign strings on Linux in this version of Swift " )
254
+ #endif
259
255
}
260
256
261
257
@inline ( __always)
You can’t perform that action at this time.
0 commit comments