22//
33// This source file is part of the Swift.org open source project
44//
5- // Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
5+ // Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
66// Licensed under Apache License v2.0 with Runtime Library Exception
77//
88// See https://swift.org/LICENSE.txt for license information
@@ -681,6 +681,8 @@ final internal class __SharedStringStorage
681681
682682 internal var _breadcrumbs : _StringBreadcrumbs ? = nil
683683
684+ internal var immortal = false
685+
684686 internal var count : Int { _countAndFlags. count }
685687
686688 internal init (
@@ -689,6 +691,7 @@ final internal class __SharedStringStorage
689691 ) {
690692 self . _owner = nil
691693 self . start = ptr
694+ self . immortal = true
692695#if _pointerBitWidth(_64)
693696 self . _countAndFlags = countAndFlags
694697#elseif _pointerBitWidth(_32)
@@ -709,6 +712,32 @@ final internal class __SharedStringStorage
709712 return String ( _StringGuts ( self ) )
710713 }
711714 }
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+ }
712741}
713742
714743extension __SharedStringStorage {
0 commit comments