@@ -40,7 +40,7 @@ extension ManagedBufferPointer
40
40
41
41
struct CountAndCapacity {
42
42
var count : LifetimeTracked
43
- var capacity : Int
43
+ let capacity : Int
44
44
}
45
45
46
46
// An example of ManagedBuffer, very similar to what Array will use.
@@ -96,23 +96,6 @@ final class TestManagedBuffer<T> : ManagedBuffer<CountAndCapacity, T> {
96
96
}
97
97
self . count = count + 2
98
98
}
99
-
100
- class func tryGrow( _ buffer: inout TestManagedBuffer < T > , newCapacity: Int ) -> Bool {
101
- guard isKnownUniquelyReferenced ( & buffer) else {
102
- return false
103
- }
104
- guard newCapacity > buffer. capacity else {
105
- return false
106
- }
107
-
108
- if tryReallocateUniquelyReferenced ( buffer: & buffer,
109
- newMinimumCapacity: newCapacity) {
110
- buffer. header. capacity = newCapacity
111
- return true
112
- } else {
113
- return false
114
- }
115
- }
116
99
}
117
100
118
101
class MyBuffer < T> {
@@ -258,35 +241,4 @@ tests.test("isKnownUniquelyReferenced") {
258
241
_fixLifetime ( s2)
259
242
}
260
243
261
- tests. test ( " canGrowUsingRealloc " ) {
262
- #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
263
- return // realloc currently unsupported on Darwin
264
- #endif
265
- func testGrow( _ buffer: inout TestManagedBuffer < LifetimeTracked > ,
266
- newCapacity: Int ,
267
- shouldSucceed: Bool = true ) {
268
- let s = TestManagedBuffer . tryGrow ( & buffer, newCapacity: newCapacity)
269
- expectEqual ( s, shouldSucceed)
270
- if shouldSucceed {
271
- expectLE ( newCapacity, buffer. myCapacity)
272
- expectGE ( ( newCapacity + 1 ) * 2 , buffer. myCapacity)
273
- }
274
- repeat {
275
- buffer. append ( LifetimeTracked ( buffer. count) )
276
- } while buffer. count < buffer. myCapacity - 2
277
- }
278
-
279
- var b = TestManagedBuffer< LifetimeTracked> . create( 0 )
280
- // allow some over-allocation
281
- expectLE ( 0 , b. myCapacity)
282
- expectGE ( 3 , b. myCapacity)
283
-
284
- testGrow ( & b, newCapacity: 5 )
285
- testGrow ( & b, newCapacity: 8 )
286
- testGrow ( & b, newCapacity: 1000 )
287
- testGrow ( & b, newCapacity: 16000 )
288
- var b2 = b
289
- testGrow ( & b, newCapacity: 2000 , shouldSucceed: false )
290
- }
291
-
292
244
runAllTests ( )
0 commit comments