Skip to content

Commit d96b051

Browse files
author
Dave Abrahams
committed
stdlib: initializePointee(_) => initialize(with:)
Tacking "Pointee" on just for unary operations (and especially operations with an optional count) created inconsistency.
1 parent 423b6ab commit d96b051

30 files changed

+67
-67
lines changed

Diff for: stdlib/private/StdlibUnittest/OpaqueIdentityFunctions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func _stdlib_getPointer(x: OpaquePointer) -> OpaquePointer
1515

1616
public func _opaqueIdentity<T>(x: T) -> T {
1717
let ptr = UnsafeMutablePointer<T>(allocatingCapacity: 1)
18-
ptr.initializePointee(x)
18+
ptr.initialize(with: x)
1919
let result =
2020
UnsafeMutablePointer<T>(_stdlib_getPointer(OpaquePointer(ptr))).pointee
2121
ptr.deinitializePointee()

Diff for: stdlib/private/SwiftPrivate/ShardedAtomicCounter.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public struct _stdlib_ShardedAtomicCounter {
3535
let count = max(8, hardwareConcurrency * hardwareConcurrency)
3636
let shards = UnsafeMutablePointer<Int>(allocatingCapacity: count)
3737
for i in 0..<count {
38-
(shards + i).initializePointee(0)
38+
(shards + i).initialize(with: 0)
3939
}
4040
self._shardsPtr = shards
4141
self._shardsCount = count

Diff for: stdlib/private/SwiftPrivatePthreadExtras/SwiftPrivatePthreadExtras.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal class PthreadBlockContextImpl<Argument, Result>: PthreadBlockContext {
4242

4343
override func run() -> UnsafeMutablePointer<Void> {
4444
let result = UnsafeMutablePointer<Result>(allocatingCapacity: 1)
45-
result.initializePointee(block(arg))
45+
result.initialize(with: block(arg))
4646
return UnsafeMutablePointer(result)
4747
}
4848
}

Diff for: stdlib/public/SDK/Foundation/NSError.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public func _stdlib_bridgeNSErrorToErrorProtocol<
4646
T : _ObjectiveCBridgeableErrorProtocol
4747
>(error: NSError, out: UnsafeMutablePointer<T>) -> Bool {
4848
if let bridged = T(_bridgedNSError: error) {
49-
out.initializePointee(bridged)
49+
out.initialize(with: bridged)
5050
return true
5151
} else {
5252
return false

Diff for: stdlib/public/core/ArrayBuffer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ extension _ArrayBuffer {
224224
// Make another pass to retain the copied objects
225225
var result = target
226226
for _ in bounds {
227-
result.initializePointee(result.pointee)
227+
result.initialize(with: result.pointee)
228228
result += 1
229229
}
230230
return result

Diff for: stdlib/public/core/ArrayBufferProtocol.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ extension _ArrayBufferProtocol {
169169
}
170170
// Initialize the hole left by sliding the tail forward
171171
for j in oldTailIndex..<newTailIndex {
172-
(elements + j).initializePointee(newValues[i])
172+
(elements + j).initialize(with: newValues[i])
173173
i._successorInPlace()
174174
}
175175
_expectEnd(i, newValues)

Diff for: stdlib/public/core/ArrayCast.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public func _arrayForceCast<SourceElement, TargetElement>(
8282
_precondition(
8383
bridged != nil, "array element cannot be bridged to Objective-C")
8484
// FIXME: should be an unsafeDowncast.
85-
p.initializePointee(unsafeBitCast(bridged!, to: TargetElement.self))
85+
p.initialize(with: unsafeBitCast(bridged!, to: TargetElement.self))
8686
p += 1
8787
}
8888
}
@@ -162,7 +162,7 @@ ElementwiseBridging:
162162
if _slowPath(value == nil) {
163163
break ElementwiseBridging
164164
}
165-
p.initializePointee(value!)
165+
p.initialize(with: value!)
166166
p += 1
167167
}
168168
return Array(_ArrayBuffer(buf, shiftedToStartIndex: 0))

Diff for: stdlib/public/core/Arrays.swift.gyb

+5-5
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ extension ${Self} : _ArrayProtocol {
510510
var p: UnsafeMutablePointer<Element>
511511
(self, p) = ${Self}._allocateUninitialized(count)
512512
for _ in 0..<count {
513-
p.initializePointee(repeatedValue)
513+
p.initialize(with: repeatedValue)
514514
p += 1
515515
}
516516
}
@@ -676,7 +676,7 @@ extension ${Self} : _ArrayProtocol {
676676
_sanityCheck(_buffer.capacity >= _buffer.count + 1)
677677

678678
_buffer.count = oldCount + 1
679-
(_buffer.firstElementAddress + oldCount).initializePointee(newElement)
679+
(_buffer.firstElementAddress + oldCount).initialize(with: newElement)
680680
}
681681

682682
/// Append `newElement` to the ${Self}.
@@ -904,7 +904,7 @@ internal struct _InitializeMemoryFromCollection<
904904
var p = rawMemory
905905
var q = newValues.startIndex
906906
for _ in 0..<count {
907-
p.initializePointee(newValues[q])
907+
p.initialize(with: newValues[q])
908908
q = q.successor()
909909
p += 1
910910
}
@@ -1172,7 +1172,7 @@ internal struct _InitializePointer<T> : _PointerFunction {
11721172
internal func call(rawMemory: UnsafeMutablePointer<T>, count: Int) {
11731173
_sanityCheck(count == 1)
11741174
// FIXME: it would be better if we could find a way to move, here
1175-
rawMemory.initializePointee(newValue)
1175+
rawMemory.initialize(with: newValue)
11761176
}
11771177

11781178
@_transparent
@@ -1249,7 +1249,7 @@ internal func _arrayAppendSequence<
12491249
let base = buffer.firstElementAddress
12501250

12511251
while (nextItem != nil) && count < capacity {
1252-
(base + count).initializePointee(nextItem!)
1252+
(base + count).initialize(with: nextItem!)
12531253
count += 1
12541254
nextItem = stream.next()
12551255
}

Diff for: stdlib/public/core/Collection.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ extension Sequence
602602
} else {
603603
var p = ptr
604604
for x in self {
605-
p.initializePointee(x)
605+
p.initialize(with: x)
606606
p += 1
607607
}
608608
return p

Diff for: stdlib/public/core/ContiguousArrayBuffer.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
149149
let resultPtr = result.baseAddress
150150
let p = __manager._elementPointer
151151
for i in 0..<count {
152-
(resultPtr + i).initializePointee(_bridgeToObjectiveCUnconditional(p[i]))
152+
(resultPtr + i).initialize(with: _bridgeToObjectiveCUnconditional(p[i]))
153153
}
154154
_fixLifetime(__manager)
155155
return result
@@ -242,7 +242,7 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
242242
let verbatim = false
243243
#endif
244244

245-
__bufferPointer._valuePointer.initializePointee(
245+
__bufferPointer._valuePointer.initialize(with:
246246
_ArrayBody(
247247
count: count,
248248
capacity: capacity,
@@ -614,7 +614,7 @@ internal func _copyCollectionToNativeArrayBuffer<
614614
var i = source.startIndex
615615
for _ in 0..<count {
616616
// FIXME(performance): use _initializeTo().
617-
p.initializePointee(source[i])
617+
p.initialize(with: source[i])
618618
i._successorInPlace()
619619
p._successorInPlace()
620620
}
@@ -674,7 +674,7 @@ internal struct _UnsafePartiallyInitializedContiguousArrayBuffer<Element> {
674674
"_UnsafePartiallyInitializedContiguousArrayBuffer has no more capacity")
675675
remainingCapacity -= 1
676676

677-
p.initializePointee(element)
677+
p.initialize(with: element)
678678
p += 1
679679
}
680680

Diff for: stdlib/public/core/HashedCollections.swift.gyb

+10-10
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ internal struct _BitMap {
16411641

16421642
internal func initializeToZero() {
16431643
for i in 0 ..< numberOfWords {
1644-
(values + i).initializePointee(0)
1644+
(values + i).initialize(with: 0)
16451645
}
16461646
}
16471647

@@ -1981,7 +1981,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
19811981
internal func initializeKey(k: Key, at i: Int) {
19821982
_sanityCheck(!isInitializedEntry(at: i))
19831983

1984-
(keys + i).initializePointee(k)
1984+
(keys + i).initialize(with: k)
19851985
initializedEntries[i] = true
19861986
_fixLifetime(self)
19871987
}
@@ -1991,7 +1991,7 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
19911991
from from: Storage, at: Int, toEntryAt: Int
19921992
) {
19931993
_sanityCheck(!isInitializedEntry(at: toEntryAt))
1994-
(keys + toEntryAt).initializePointee((from.keys + at).move())
1994+
(keys + toEntryAt).initialize(with: (from.keys + at).move())
19951995
from.initializedEntries[at] = false
19961996
initializedEntries[toEntryAt] = true
19971997
}
@@ -2009,8 +2009,8 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
20092009
internal func initializeKey(k: Key, value v: Value, at i: Int) {
20102010
_sanityCheck(!isInitializedEntry(at: i))
20112011

2012-
(keys + i).initializePointee(k)
2013-
(values + i).initializePointee(v)
2012+
(keys + i).initialize(with: k)
2013+
(values + i).initialize(with: v)
20142014
initializedEntries[i] = true
20152015
_fixLifetime(self)
20162016
}
@@ -2020,8 +2020,8 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
20202020
from from: Storage, at: Int, toEntryAt: Int
20212021
) {
20222022
_sanityCheck(!isInitializedEntry(at: toEntryAt))
2023-
(keys + toEntryAt).initializePointee((from.keys + at).move())
2024-
(values + toEntryAt).initializePointee((from.values + at).move())
2023+
(keys + toEntryAt).initialize(with: (from.keys + at).move())
2024+
(values + toEntryAt).initialize(with: (from.values + at).move())
20252025
from.initializedEntries[at] = false
20262026
initializedEntries[toEntryAt] = true
20272027
}
@@ -2340,7 +2340,7 @@ internal struct _BridgedNative${Self}Storage {
23402340
internal func initializeKey(k: AnyObject, at i: Int) {
23412341
_sanityCheck(!isInitializedEntry(at: i))
23422342

2343-
(keys + i).initializePointee(k)
2343+
(keys + i).initialize(with: k)
23442344
initializedEntries[i] = true
23452345
_fixLifetime(self)
23462346
}
@@ -2350,8 +2350,8 @@ internal struct _BridgedNative${Self}Storage {
23502350
) {
23512351
_sanityCheck(!isInitializedEntry(at: i))
23522352

2353-
(keys + i).initializePointee(k)
2354-
(values + i).initializePointee(v)
2353+
(keys + i).initialize(with: k)
2354+
(values + i).initialize(with: v)
23552355
initializedEntries[i] = true
23562356
_fixLifetime(self)
23572357
}

Diff for: stdlib/public/core/HeapBuffer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ struct _HeapBuffer<Value, Element> : Equatable {
181181
size: totalSize,
182182
alignmentMask: alignMask)
183183
self._storage = Builtin.castToNativeObject(object)
184-
self._value.initializePointee(initializer)
184+
self._value.initialize(with: initializer)
185185
}
186186

187187
public // @testable

Diff for: stdlib/public/core/ManagedBuffer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public struct ManagedBufferPointer<Value, Element> : Equatable {
190190

191191
// initialize the value field
192192
withUnsafeMutablePointerToValue {
193-
$0.initializePointee(
193+
$0.initialize(with:
194194
initialValue(
195195
buffer: self.buffer,
196196
capacity: {

Diff for: stdlib/public/core/Reflection.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public protocol _Mirror {
138138
@_silgen_name("swift_getSummary")
139139
public // COMPILER_INTRINSIC
140140
func _getSummary<T>(out: UnsafeMutablePointer<String>, x: T) {
141-
out.initializePointee(String(reflecting: x))
141+
out.initialize(with: String(reflecting: x))
142142
}
143143

144144
/// Produce a mirror for any value. If the value's type conforms to

Diff for: stdlib/public/core/Sequence.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ extension Sequence {
609609
-> UnsafeMutablePointer<Iterator.Element> {
610610
var p = UnsafeMutablePointer<Iterator.Element>(ptr)
611611
for x in IteratorSequence(self.iterator()) {
612-
p.initializePointee(x)
612+
p.initialize(with: x)
613613
p += 1
614614
}
615615
return p

Diff for: stdlib/public/core/String.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ extension String {
529529
start: UnsafeMutablePointer<UTF8.CodeUnit>,
530530
utf8CodeUnitCount: Int
531531
) {
532-
resultStorage.initializePointee(
532+
resultStorage.initialize(with:
533533
String._fromWellFormedCodeUnitSequence(
534534
UTF8.self,
535535
input: UnsafeBufferPointer(start: start, count: utf8CodeUnitCount)))

Diff for: stdlib/public/core/UnsafePointer.swift.gyb

+6-6
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ public struct ${Self}<Pointee>
143143
/// - Postcondition: The pointee is initialized; the value should eventually
144144
/// be destroyed or moved from to avoid leaks.
145145
// FIXME: add tests (since the `count` has been added)
146-
public func initializePointee(newValue: Pointee, count: Int = 1) {
146+
public func initialize(with: newValue: Pointee, count: Int = 1) {
147147
_stdlibAssert(count >= 0,
148-
"${Self}.initializePointee with negative count")
148+
"${Self}.initialize(with:): negative count")
149149
// Must not use `initializeFrom` with a `Collection` as that will introduce
150150
// a cycle.
151151
for offset in 0..<count {
@@ -243,7 +243,7 @@ public struct ${Self}<Pointee>
243243
Pointee.self, self._rawValue, source._rawValue, count._builtinWordValue)
244244
// This builtin is equivalent to:
245245
// for i in 0..<count {
246-
// (self + i).initializePointee((source + i).move())
246+
// (self + i).initialize(with: (source + i).move())
247247
// }
248248
}
249249

@@ -276,7 +276,7 @@ public struct ${Self}<Pointee>
276276
// var src = source + count
277277
// var dst = self + count
278278
// while dst != self {
279-
// (--dst).initializePointee((--src).move())
279+
// (--dst).initialize(with: (--src).move())
280280
// }
281281
}
282282

@@ -305,7 +305,7 @@ public struct ${Self}<Pointee>
305305
Pointee.self, self._rawValue, source._rawValue, count._builtinWordValue)
306306
// This builtin is equivalent to:
307307
// for i in 0..<count {
308-
// (self + i).initializePointee(source[i])
308+
// (self + i).initialize(with: source[i])
309309
// }
310310
}
311311

@@ -569,7 +569,7 @@ extension ${Self} {
569569
}
570570
}
571571

572-
@available(*, unavailable, renamed="initializePointee")
572+
@available(*, unavailable, renamed="initialize(with:)")
573573
public func initialize(newvalue: Pointee) {
574574
fatalError("unavailable function can't be called")
575575
}

Diff for: test/1_stdlib/Builtins.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ struct ContainsP { var p: P }
139139
func exerciseArrayValueWitnesses<T>(value: T) {
140140
let buf = UnsafeMutablePointer<T>(allocatingCapacity: 5)
141141

142-
(buf + 0).initializePointee(value)
143-
(buf + 1).initializePointee(value)
142+
(buf + 0).initialize(with: value)
143+
(buf + 1).initialize(with: value)
144144

145145
Builtin.copyArray(T.self, (buf + 2)._rawValue, buf._rawValue, 2._builtinWordValue)
146146
Builtin.takeArrayBackToFront(T.self, (buf + 1)._rawValue, buf._rawValue, 4._builtinWordValue)

Diff for: test/1_stdlib/HeapBuffer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ a.value.name = "DaveA"
2020
a.value.locations.append("Princeton")
2121
a.value.locations.append("San Jose")
2222
for x in 0..<10 {
23-
(a.baseAddress + x).initializePointee(x)
23+
(a.baseAddress + x).initialize(with: x)
2424
}
2525

2626
print("buffer has storage: \(a.storage != nil)")

Diff for: test/1_stdlib/ManagedBuffer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ final class TestManagedBuffer<T> : ManagedBuffer<CountAndCapacity, T> {
117117

118118
withUnsafeMutablePointerToElements {
119119
(p: UnsafeMutablePointer<T>) -> () in
120-
(p + count).initializePointee(x)
120+
(p + count).initialize(with: x)
121121
}
122122
self.count = count + 2
123123
}

Diff for: test/1_stdlib/Reflection.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ dump(randomUnsafeMutablePointerString)
204204

205205
// CHECK-NEXT: Hello panda
206206
var sanePointerString = UnsafeMutablePointer<String>(allocatingCapacity: 1)
207-
sanePointerString.initializePointee("Hello panda")
207+
sanePointerString.initialize(with: "Hello panda")
208208
dump(sanePointerString.pointee)
209209
sanePointerString.deinitializePointee()
210210
sanePointerString.deallocateCapacity(1)

0 commit comments

Comments
 (0)