@@ -806,116 +806,119 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
806
806
}
807
807
808
808
#if arch(x86_64) || arch(arm64) || arch(s390x) || arch(powerpc64) || arch(powerpc64le)
809
- @usableFromInline
810
- internal typealias HalfInt = Int32
809
+ @usableFromInline internal typealias HalfInt = Int32
811
810
#elseif arch(i386) || arch(arm)
812
- @usableFromInline
813
- internal typealias HalfInt = Int16
811
+ @usableFromInline internal typealias HalfInt = Int16
814
812
#endif
815
813
814
+ // A buffer of bytes too large to fit in an InlineData, but still small enough to fit a storage pointer + range in two words.
815
+ // Inlinability strategy: everything here should be easily inlinable as large _DataStorage methods should not inline into here.
816
816
@usableFromInline
817
817
@_fixed_layout
818
818
internal struct InlineSlice {
819
819
// ***WARNING***
820
820
// These ivars are specifically laid out so that they cause the enum _Representation to be 16 bytes on 64 bit platforms. This means we _MUST_ have the class type thing last
821
- @usableFromInline
822
- var slice : Range < HalfInt >
823
- @usableFromInline
824
- var storage : _DataStorage
821
+ @usableFromInline var slice : Range < HalfInt >
822
+ @usableFromInline var storage : _DataStorage
825
823
826
- @inlinable
824
+ @inlinable // This is @inlinable as trivially computable.
827
825
static func canStore( count: Int ) -> Bool {
828
826
return count < HalfInt . max
829
827
}
830
828
831
- @inlinable
829
+ @inlinable // This is @inlinable as a convenience initializer.
832
830
init ( _ buffer: UnsafeRawBufferPointer ) {
833
831
assert ( buffer. count < HalfInt . max)
834
832
self . init ( _DataStorage ( bytes: buffer. baseAddress, length: buffer. count) , count: buffer. count)
835
833
}
836
834
837
- @inlinable
835
+ @inlinable // This is @inlinable as a convenience initializer.
838
836
init ( capacity: Int ) {
839
837
assert ( capacity < HalfInt . max)
840
838
self . init ( _DataStorage ( capacity: capacity) , count: 0 )
841
839
}
842
840
843
- @inlinable
841
+ @inlinable // This is @inlinable as a convenience initializer.
844
842
init ( count: Int ) {
845
843
assert ( count < HalfInt . max)
846
844
self . init ( _DataStorage ( length: count) , count: count)
847
845
}
848
846
849
- @inlinable
847
+ @inlinable // This is @inlinable as a convenience initializer.
850
848
init ( _ inline: InlineData ) {
851
849
assert ( inline. count < HalfInt . max)
852
850
self . init ( inline. withUnsafeBytes { return _DataStorage ( bytes: $0. baseAddress, length: $0. count) } , count: inline. count)
853
851
}
854
852
855
- @inlinable
853
+ @inlinable // This is @inlinable as a convenience initializer.
856
854
init ( _ inline: InlineData , range: Range < Int > ) {
857
855
assert ( range. lowerBound < HalfInt . max)
858
856
assert ( range. upperBound < HalfInt . max)
859
857
self . init ( inline. withUnsafeBytes { return _DataStorage ( bytes: $0. baseAddress, length: $0. count) } , range: range)
860
858
}
861
859
862
- @inlinable
860
+ @inlinable // This is @inlinable as a convenience initializer.
863
861
init ( _ large: LargeSlice ) {
864
862
assert ( large. range. lowerBound < HalfInt . max)
865
863
assert ( large. range. upperBound < HalfInt . max)
866
864
self . init ( large. storage, range: large. range)
867
865
}
868
866
869
- @inlinable
867
+ @inlinable // This is @inlinable as a convenience initializer.
870
868
init ( _ large: LargeSlice , range: Range < Int > ) {
871
869
assert ( range. lowerBound < HalfInt . max)
872
870
assert ( range. upperBound < HalfInt . max)
873
871
self . init ( large. storage, range: range)
874
872
}
875
873
876
- @inlinable
874
+ @inlinable // This is @inlinable as a trivial initializer.
877
875
init ( _ storage: _DataStorage , count: Int ) {
878
876
assert ( count < HalfInt . max)
879
877
self . storage = storage
880
878
slice = 0 ..< HalfInt ( count)
881
879
}
882
880
883
- @inlinable
881
+ @inlinable // This is @inlinable as a trivial initializer.
884
882
init ( _ storage: _DataStorage , range: Range < Int > ) {
885
883
assert ( range. lowerBound < HalfInt . max)
886
884
assert ( range. upperBound < HalfInt . max)
887
885
self . storage = storage
888
886
slice = HalfInt ( range. lowerBound) ..< HalfInt ( range. upperBound)
889
887
}
890
888
891
- @inlinable
889
+ @inlinable // This is @inlinable as trivially computable (and inlining may help avoid retain-release traffic).
892
890
mutating func ensureUniqueReference( ) {
893
891
if !isKnownUniquelyReferenced( & storage) {
894
892
storage = storage. mutableCopy ( self . range)
895
893
}
896
894
}
897
895
898
- @inlinable
899
- var startIndex : Int { return numericCast ( slice . lowerBound ) }
900
- @ inlinable
901
- var endIndex : Int { return numericCast ( slice . upperBound ) }
896
+ @inlinable // This is @inlinable as trivially computable.
897
+ var startIndex : Int {
898
+ return Int ( slice . lowerBound )
899
+ }
902
900
903
- @inlinable
901
+ @inlinable // This is @inlinable as trivially computable.
902
+ var endIndex : Int {
903
+ return Int ( slice. upperBound)
904
+ }
905
+
906
+ @inlinable // This is @inlinable as trivially computable.
904
907
var capacity : Int {
905
908
return storage. capacity
906
909
}
907
910
908
- @inlinable
911
+ @inlinable // This is @inlinable as trivially computable (and inlining may help avoid retain-release traffic).
909
912
mutating func reserveCapacity( _ minimumCapacity: Int ) {
910
913
ensureUniqueReference ( )
911
914
// the current capacity can be zero (representing externally owned buffer), and count can be greater than the capacity
912
915
storage. ensureUniqueBufferReference ( growingTo: Swift . max ( minimumCapacity, count) )
913
916
}
914
917
915
- @inlinable
918
+ @inlinable // This is @inlinable as trivially computable.
916
919
var count : Int {
917
920
get {
918
- return numericCast ( slice. upperBound - slice. lowerBound)
921
+ return Int ( slice. upperBound - slice. lowerBound)
919
922
}
920
923
set ( newValue) {
921
924
assert ( newValue < HalfInt . max)
@@ -925,10 +928,10 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
925
928
}
926
929
}
927
930
928
- @inlinable
931
+ @inlinable // This is @inlinable as trivially computable.
929
932
var range : Range < Int > {
930
933
get {
931
- return numericCast ( slice. lowerBound) ..< numericCast ( slice. upperBound)
934
+ return Int ( slice. lowerBound) ..< Int ( slice. upperBound)
932
935
}
933
936
set ( newValue) {
934
937
assert ( newValue. lowerBound < HalfInt . max)
@@ -937,26 +940,26 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
937
940
}
938
941
}
939
942
940
- @inlinable
943
+ @inlinable // This is @inlinable as a generic, trivially forwarding function.
941
944
func withUnsafeBytes< Result> ( _ apply: ( UnsafeRawBufferPointer ) throws -> Result ) rethrows -> Result {
942
945
return try storage. withUnsafeBytes ( in: range, apply: apply)
943
946
}
944
947
945
- @inlinable
948
+ @inlinable // This is @inlinable as a generic, trivially forwarding function.
946
949
mutating func withUnsafeMutableBytes< Result> ( _ apply: ( UnsafeMutableRawBufferPointer ) throws -> Result ) rethrows -> Result {
947
950
ensureUniqueReference ( )
948
951
return try storage. withUnsafeMutableBytes ( in: range, apply: apply)
949
952
}
950
953
951
- @inlinable
954
+ @inlinable // This is @inlinable as reasonably small.
952
955
mutating func append( contentsOf buffer: UnsafeRawBufferPointer ) {
953
956
assert ( endIndex + buffer. count < HalfInt . max)
954
957
ensureUniqueReference ( )
955
958
storage. replaceBytes ( in: NSRange ( location: range. upperBound, length: storage. length - ( range. upperBound - storage. _offset) ) , with: buffer. baseAddress, length: buffer. count)
956
- slice = slice. lowerBound..< HalfInt ( numericCast ( slice. upperBound) + buffer. count)
959
+ slice = slice. lowerBound..< HalfInt ( Int ( slice. upperBound) + buffer. count)
957
960
}
958
961
959
- @inlinable
962
+ @inlinable // This is @inlinable as reasonably small.
960
963
subscript( index: Index ) -> UInt8 {
961
964
get {
962
965
assert ( index < HalfInt . max)
@@ -973,12 +976,12 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
973
976
}
974
977
}
975
978
976
- @inlinable
979
+ @inlinable // This is @inlinable as trivially forwarding.
977
980
func bridgedReference( ) -> NSData {
978
981
return storage. bridgedReference ( self . range)
979
982
}
980
983
981
- @inlinable
984
+ @inlinable // This is @inlinable as reasonably small.
982
985
mutating func resetBytes( in range: Range < Index > ) {
983
986
assert ( range. lowerBound < HalfInt . max)
984
987
assert ( range. upperBound < HalfInt . max)
@@ -990,7 +993,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
990
993
}
991
994
}
992
995
993
- @inlinable
996
+ @inlinable // This is @inlinable as reasonably small.
994
997
mutating func replaceSubrange( _ subrange: Range < Index > , with bytes: UnsafeRawPointer ? , count cnt: Int ) {
995
998
precondition ( startIndex <= subrange. lowerBound, " index \( subrange. lowerBound) is out of bounds of \( startIndex) ..< \( endIndex) " )
996
999
precondition ( subrange. lowerBound <= endIndex, " index \( subrange. lowerBound) is out of bounds of \( startIndex) ..< \( endIndex) " )
@@ -1005,7 +1008,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
1005
1008
slice = slice. lowerBound..< HalfInt ( resultingUpper)
1006
1009
}
1007
1010
1008
- @inlinable
1011
+ @inlinable // This is @inlinable as reasonably small.
1009
1012
func copyBytes( to pointer: UnsafeMutableRawPointer , from range: Range < Int > ) {
1010
1013
precondition ( startIndex <= range. lowerBound, " index \( range. lowerBound) is out of bounds of \( startIndex) ..< \( endIndex) " )
1011
1014
precondition ( range. lowerBound <= endIndex, " index \( range. lowerBound) is out of bounds of \( startIndex) ..< \( endIndex) " )
0 commit comments