2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
@@ -681,6 +681,8 @@ final internal class __SharedStringStorage
681
681
682
682
internal var _breadcrumbs : _StringBreadcrumbs ? = nil
683
683
684
+ internal var immortal = false
685
+
684
686
internal var count : Int { _countAndFlags. count }
685
687
686
688
internal init (
@@ -689,6 +691,7 @@ final internal class __SharedStringStorage
689
691
) {
690
692
self . _owner = nil
691
693
self . start = ptr
694
+ self . immortal = true
692
695
#if _pointerBitWidth(_64)
693
696
self . _countAndFlags = countAndFlags
694
697
#elseif _pointerBitWidth(_32)
@@ -709,6 +712,32 @@ final internal class __SharedStringStorage
709
712
return String ( _StringGuts ( self ) )
710
713
}
711
714
}
715
+
716
+ internal init (
717
+ _mortal ptr: UnsafePointer < UInt8 > ,
718
+ countAndFlags: _StringObject . CountAndFlags
719
+ ) {
720
+ // ptr *must* be the start of an allocation
721
+ self . _owner = nil
722
+ self . start = ptr
723
+ self . immortal = false
724
+ #if _pointerBitWidth(_64)
725
+ self . _countAndFlags = countAndFlags
726
+ #elseif _pointerBitWidth(_32)
727
+ self . _count = countAndFlags. count
728
+ self . _countFlags = countAndFlags. flags
729
+ #else
730
+ #error("Unknown platform")
731
+ #endif
732
+ super. init ( )
733
+ self . _invariantCheck ( )
734
+ }
735
+
736
+ deinit {
737
+ if ( _owner == nil ) && !immortal {
738
+ start. deallocate ( )
739
+ }
740
+ }
712
741
}
713
742
714
743
extension __SharedStringStorage {
0 commit comments