Skip to content

Commit faa535f

Browse files
authored
Merge pull request #20463 from lorentey/remove-random-fill
[stdib] Remove RandomNumberGenerator._fill(bytes:)
2 parents 877751a + 51be8c7 commit faa535f

File tree

3 files changed

+11
-28
lines changed

3 files changed

+11
-28
lines changed

stdlib/public/core/Random.swift

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,6 @@ public protocol RandomNumberGenerator {
6161
///
6262
/// - Returns: An unsigned 64-bit random value.
6363
mutating func next() -> UInt64
64-
65-
// FIXME: De-underscore after swift-evolution amendment
66-
mutating func _fill(bytes buffer: UnsafeMutableRawBufferPointer)
67-
}
68-
69-
extension RandomNumberGenerator {
70-
@inlinable
71-
public mutating func _fill(bytes buffer: UnsafeMutableRawBufferPointer) {
72-
// FIXME: Optimize
73-
var chunk: UInt64 = 0
74-
var chunkBytes = 0
75-
for i in 0..<buffer.count {
76-
if chunkBytes == 0 {
77-
chunk = next()
78-
chunkBytes = UInt64.bitWidth / 8
79-
}
80-
buffer[i] = UInt8(truncatingIfNeeded: chunk)
81-
chunk >>= UInt8.bitWidth
82-
chunkBytes -= 1
83-
}
84-
}
8564
}
8665

8766
extension RandomNumberGenerator {
@@ -167,11 +146,4 @@ public struct SystemRandomNumberGenerator : RandomNumberGenerator {
167146
swift_stdlib_random(&random, MemoryLayout<UInt64>.size)
168147
return random
169148
}
170-
171-
@inlinable
172-
public mutating func _fill(bytes buffer: UnsafeMutableRawBufferPointer) {
173-
if !buffer.isEmpty {
174-
swift_stdlib_random(buffer.baseAddress!, buffer.count)
175-
}
176-
}
177149
}

test/api-digester/Outputs/stability-stdlib-abi.swift.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,6 @@ Protocol _NSStringCore has been removed
7878

7979
Constructor ManagedBuffer.init(_doNotCallMe:) has been removed
8080
Func _makeAnyHashableUpcastingToHashableBaseType(_:storingResultInto:) has been removed
81+
82+
Func RandomNumberGenerator._fill(bytes:) has been removed
83+
Func SystemRandomNumberGenerator._fill(bytes:) has been removed

validation-test/stdlib/Random.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33

44
import StdlibUnittest
55
import StdlibCollectionUnittest
6+
import SwiftShims // for swift_stdlib_random
67

78
let RandomTests = TestSuite("Random")
89

910
// _fill(bytes:)
1011

12+
extension RandomNumberGenerator {
13+
func _fill(bytes buffer: UnsafeMutableRawBufferPointer) {
14+
guard let start = buffer.baseAddress else { return }
15+
swift_stdlib_random(start, buffer.count)
16+
}
17+
}
18+
1119
RandomTests.test("_fill(bytes:)") {
1220
for count in [100, 1000] {
1321
var bytes1 = [UInt8](repeating: 0, count: count)

0 commit comments

Comments
 (0)