@@ -400,7 +400,7 @@ extension String : _ExpressibleByBuiltinUTF16StringLiteral {
400400 ) {
401401 self = String (
402402 _StringCore (
403- baseAddress: OpaquePointer ( start) ,
403+ baseAddress: UnsafeMutableRawPointer ( start) ,
404404 count: Int ( utf16CodeUnitCount) ,
405405 elementShift: 1 ,
406406 hasCocoaBuffer: false ,
@@ -418,7 +418,7 @@ extension String : _ExpressibleByBuiltinStringLiteral {
418418 if Bool ( isASCII) {
419419 self = String (
420420 _StringCore (
421- baseAddress: OpaquePointer ( start) ,
421+ baseAddress: UnsafeMutableRawPointer ( start) ,
422422 count: Int ( utf8CodeUnitCount) ,
423423 elementShift: 0 ,
424424 hasCocoaBuffer: false ,
@@ -699,13 +699,15 @@ extension String : Hashable {
699699 }
700700#else
701701 if self . _core. isASCII {
702- return _swift_stdlib_unicode_hash_ascii (
703- UnsafeMutablePointer < Int8 > ( _core. startASCII) ,
704- Int32 ( _core. count) )
702+ return _core. startASCII. withMemoryRebound (
703+ to: CChar . self, capacity: _core. count) {
704+ _swift_stdlib_unicode_hash_ascii ( $0, Int32 ( _core. count) )
705+ }
705706 } else {
706- return _swift_stdlib_unicode_hash (
707- UnsafeMutablePointer < UInt16 > ( _core. startUTF16) ,
708- Int32 ( _core. count) )
707+ return _core. startUTF16. withMemoryRebound (
708+ to: UInt16 . self, capacity: _core. count) {
709+ _swift_stdlib_unicode_hash ( $0, Int32 ( _core. count) )
710+ }
709711 }
710712#endif
711713 }
@@ -821,7 +823,8 @@ internal func _nativeUnicodeLowercaseString(_ str: String) -> String {
821823 capacity: str. _core. count, initialSize: str. _core. count, elementWidth: 2 )
822824
823825 // Try to write it out to the same length.
824- let dest = UnsafeMutablePointer < UTF16 . CodeUnit > ( buffer. start)
826+ let dest = buffer. start. bindMemory (
827+ to: UTF16 . CodeUnit. self, capacity: str. _core. count)
825828 let z = _swift_stdlib_unicode_strToLower (
826829 dest, Int32 ( str. _core. count) ,
827830 str. _core. startUTF16, Int32 ( str. _core. count) )
@@ -831,7 +834,8 @@ internal func _nativeUnicodeLowercaseString(_ str: String) -> String {
831834 if correctSize != str. _core. count {
832835 buffer = _StringBuffer (
833836 capacity: correctSize, initialSize: correctSize, elementWidth: 2 )
834- let dest = UnsafeMutablePointer < UTF16 . CodeUnit > ( buffer. start)
837+ let dest = buffer. start. bindMemory (
838+ to: UTF16 . CodeUnit. self, capacity: str. _core. count)
835839 _swift_stdlib_unicode_strToLower (
836840 dest, Int32 ( correctSize) , str. _core. startUTF16, Int32 ( str. _core. count) )
837841 }
@@ -844,7 +848,8 @@ internal func _nativeUnicodeUppercaseString(_ str: String) -> String {
844848 capacity: str. _core. count, initialSize: str. _core. count, elementWidth: 2 )
845849
846850 // Try to write it out to the same length.
847- let dest = UnsafeMutablePointer < UTF16 . CodeUnit > ( buffer. start)
851+ let dest = buffer. start. bindMemory (
852+ to: UTF16 . CodeUnit. self, capacity: str. _core. count)
848853 let z = _swift_stdlib_unicode_strToUpper (
849854 dest, Int32 ( str. _core. count) ,
850855 str. _core. startUTF16, Int32 ( str. _core. count) )
@@ -854,7 +859,8 @@ internal func _nativeUnicodeUppercaseString(_ str: String) -> String {
854859 if correctSize != str. _core. count {
855860 buffer = _StringBuffer (
856861 capacity: correctSize, initialSize: correctSize, elementWidth: 2 )
857- let dest = UnsafeMutablePointer < UTF16 . CodeUnit > ( buffer. start)
862+ let dest = buffer. start. bindMemory (
863+ to: UTF16 . CodeUnit. self, capacity: str. _core. count)
858864 _swift_stdlib_unicode_strToUpper (
859865 dest, Int32 ( correctSize) , str. _core. startUTF16, Int32 ( str. _core. count) )
860866 }
@@ -904,7 +910,7 @@ extension String {
904910 let source = self . _core. startASCII
905911 let buffer = _StringBuffer (
906912 capacity: count, initialSize: count, elementWidth: 1 )
907- let dest = UnsafeMutablePointer < UInt8 > ( buffer. start)
913+ let dest = buffer. start
908914 for i in 0 ..< count {
909915 // For each character in the string, we lookup if it should be shifted
910916 // in our ascii table, then we return 0x20 if it should, 0x0 if not.
@@ -923,7 +929,8 @@ extension String {
923929 // Since we are left with either 0x0 or 0x20, we can safely truncate to
924930 // a UInt8 and add to our ASCII value (this will not overflow numbers in
925931 // the ASCII range).
926- dest [ i] = value &+ UInt8 ( truncatingBitPattern: add)
932+ dest. storeBytes ( of: value &+ UInt8 ( truncatingBitPattern: add) ,
933+ toByteOffset: i, as: UInt8 . self)
927934 }
928935 return String ( _storage: buffer)
929936 }
@@ -953,15 +960,16 @@ extension String {
953960 let source = self . _core. startASCII
954961 let buffer = _StringBuffer (
955962 capacity: count, initialSize: count, elementWidth: 1 )
956- let dest = UnsafeMutablePointer < UInt8 > ( buffer. start)
963+ let dest = buffer. start
957964 for i in 0 ..< count {
958965 // See the comment above in lowercaseString.
959966 let value = source [ i]
960967 let isLower =
961968 _asciiLowerCaseTable >>
962969 UInt64 ( ( ( value &- 1 ) & 0b0111_1111 ) >> 1 )
963970 let add = ( isLower & 0x1 ) << 5
964- dest [ i] = value &- UInt8 ( truncatingBitPattern: add)
971+ dest. storeBytes ( of: value &- UInt8 ( truncatingBitPattern: add) ,
972+ toByteOffset: i, as: UInt8 . self)
965973 }
966974 return String ( _storage: buffer)
967975 }
0 commit comments