File tree Expand file tree Collapse file tree 3 files changed +16
-10
lines changed Expand file tree Collapse file tree 3 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -150,13 +150,6 @@ extension StringProtocol {
150
150
}
151
151
return String ( String . CharacterView ( self ) )
152
152
}
153
-
154
- internal var _persistentString : String {
155
- if _fastPath ( self is _SwiftStringView ) {
156
- return ( self as! _SwiftStringView ) . _persistentContent
157
- }
158
- return String ( String . CharacterView ( self ) )
159
- }
160
153
}
161
154
162
155
extension String : _SwiftStringView {
Original file line number Diff line number Diff line change @@ -266,10 +266,16 @@ extension Substring : _SwiftStringView {
266
266
var _persistentContent : String {
267
267
let wholeCore = _slice._base._core
268
268
let native = wholeCore.nativeBuffer
269
- if _fastPath(native != nil), let n = native {
269
+ if _fastPath(native != nil) {
270
+ let wholeString = String(wholeCore)
271
+ let n = native._unsafelyUnwrappedUnchecked
270
272
if _fastPath(
271
- n.start == wholeCore._baseAddress && n.usedCount == wholeCore.count) {
272
- return String(wholeCore)
273
+ n.start == wholeCore._baseAddress
274
+ && n.usedCount == wholeCore.count
275
+ && _slice.startIndex == wholeString.startIndex
276
+ && _slice.endIndex == wholeString.endIndex
277
+ ) {
278
+ return wholeString
273
279
}
274
280
}
275
281
var r = String()
Original file line number Diff line number Diff line change @@ -190,4 +190,11 @@ SubstringTests.test("UTF8View") {
190
190
expectEqual ( " " , String ( u. dropLast ( 10 ) ) !)
191
191
}
192
192
193
+ SubstringTests . test ( " Persistent Content " ) {
194
+ var str = " abc "
195
+ str += " def "
196
+ expectEqual ( " bcdefg " , str. dropFirst ( 1 ) + " g " )
197
+ expectEqual ( " bcdefg " , ( str. dropFirst ( 1 ) + " g " ) as String )
198
+ }
199
+
193
200
runAllTests ( )
You can’t perform that action at this time.
0 commit comments