@@ -41,7 +41,7 @@ struct _Deque<Element> {
41
41
}
42
42
43
43
internal func slot( after slot: Int ) -> Int {
44
- assert ( slot < capacity)
44
+ _internalInvariant ( slot < capacity)
45
45
let position = slot + 1
46
46
if position >= capacity {
47
47
return 0
@@ -51,7 +51,7 @@ struct _Deque<Element> {
51
51
52
52
53
53
internal func slot( _ slot: Int , offsetBy delta: Int ) -> Int {
54
- assert ( slot <= capacity)
54
+ _internalInvariant ( slot <= capacity)
55
55
let position = slot + delta
56
56
if delta >= 0 {
57
57
if position >= capacity { return position - capacity }
@@ -66,13 +66,13 @@ struct _Deque<Element> {
66
66
}
67
67
68
68
internal func uncheckedAppend( _ element: Element ) {
69
- assert ( count < capacity)
69
+ _internalInvariant ( count < capacity)
70
70
ptr ( at: endSlot) . initialize ( to: element)
71
71
count += 1
72
72
}
73
73
74
74
internal func uncheckedRemoveFirst( ) -> Element {
75
- assert ( count > 0 )
75
+ _internalInvariant ( count > 0 )
76
76
let result = ptr ( at: startSlot) . move ( )
77
77
startSlot = slot ( after: startSlot)
78
78
count -= 1
@@ -101,7 +101,7 @@ struct _Deque<Element> {
101
101
) {
102
102
self . first = first
103
103
self . second = second
104
- assert ( first. count > 0 || second == nil )
104
+ _internalInvariant ( first. count > 0 || second == nil )
105
105
}
106
106
107
107
internal init (
@@ -135,7 +135,7 @@ struct _Deque<Element> {
135
135
) {
136
136
self . first = first
137
137
self . second = second? . count == 0 ? nil : second
138
- assert ( first. count > 0 || second == nil )
138
+ _internalInvariant ( first. count > 0 || second == nil )
139
139
}
140
140
141
141
internal init (
@@ -180,7 +180,7 @@ struct _Deque<Element> {
180
180
}
181
181
182
182
func ptr( at slot: Int ) -> UnsafeMutablePointer < Element > {
183
- assert ( slot >= 0 && slot <= capacity)
183
+ _internalInvariant ( slot >= 0 && slot <= capacity)
184
184
return _elements! + slot
185
185
}
186
186
@@ -189,7 +189,7 @@ struct _Deque<Element> {
189
189
at start: Int ,
190
190
from source: UnsafeBufferPointer < Element >
191
191
) -> Int {
192
- assert ( start + source. count <= capacity)
192
+ _internalInvariant ( start + source. count <= capacity)
193
193
guard source. count > 0 else { return start }
194
194
ptr ( at: start) . initialize ( from: source. baseAddress!, count: source. count)
195
195
return start + source. count
@@ -200,7 +200,7 @@ struct _Deque<Element> {
200
200
at start: Int ,
201
201
from source: UnsafeMutableBufferPointer < Element >
202
202
) -> Int {
203
- assert ( start + source. count <= capacity)
203
+ _internalInvariant ( start + source. count <= capacity)
204
204
guard source. count > 0 else { return start }
205
205
ptr ( at: start) . moveInitialize ( from: source. baseAddress!, count: source. count)
206
206
return start + source. count
@@ -224,7 +224,7 @@ struct _Deque<Element> {
224
224
225
225
internal func moveElements( minimumCapacity: Int ) -> _Storage {
226
226
let count = self . count
227
- assert ( minimumCapacity >= count)
227
+ _internalInvariant ( minimumCapacity >= count)
228
228
let object = _Storage. _DequeBuffer. create (
229
229
minimumCapacity: minimumCapacity,
230
230
makingHeaderWith: {
@@ -413,3 +413,13 @@ struct _Deque<Element> {
413
413
}
414
414
}
415
415
416
+ @_alwaysEmitIntoClient @_transparent
417
+ internal func _internalInvariant(
418
+ _ condition: @autoclosure ( ) -> Bool ,
419
+ _ message: @autoclosure ( ) -> String = String ( ) ,
420
+ file: StaticString = #file, line: UInt = #line
421
+ ) {
422
+ #if INTERNAL_CHECKS_ENABLED
423
+ assert ( condition ( ) , message ( ) , file: file, line: line)
424
+ #endif
425
+ }
0 commit comments