Mark _Word.allBits as @inlinable

This commit is contained in:
David Nadoba committed 2026-08-14 16:32:50 -07:00
1 parent f3e778f17a
commit 962d21d92d
4 files changed
+160

No files matched your search

@@ -0,0 +1,90 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2021 - 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
//
//===----------------------------------------------------------------------===//
import CollectionsBenchmark
import BitCollections
extension Benchmark {
public mutating func addBitArrayBenchmarks() {
self.add(
title: "BitArray fill(with: true)",
input: Int.self
) { input in
guard input > 0 else { return nil }
return { timer in
var a = BitArray(repeating: false, count: input)
timer.measure {
a.fill(with: true)
}
blackHole(a)
}
}
self.add(
title: "BitArray init(repeating: true, count:)",
input: Int.self
) { input in
guard input > 0 else { return nil }
return { timer in
timer.measure {
blackHole(BitArray(repeating: true, count: input))
}
}
}
self.add(
title: "BitArray append(repeating: true, count:)",
input: Int.self
) { input in
guard input > 0 else { return nil }
return { timer in
var a = BitArray()
a.reserveCapacity(input)
timer.measure {
a.append(repeating: true, count: input)
}
blackHole(a)
}
}
self.add(
title: "BitArray insert(repeating: true, count:at:)",
input: Int.self
) { input in
guard input > 0 else { return nil }
return { timer in
var a = BitArray(repeating: false, count: 64)
timer.measure {
a.insert(repeating: true, count: input, at: 32)
}
blackHole(a)
}
}
self.add(
title: "BitArray truncateOrExtend(toCount:with: true)",
input: Int.self
) { input in
guard input > 0 else { return nil }
return { timer in
var a = BitArray()
a.reserveCapacity(input)
timer.measure {
a.truncateOrExtend(toCount: input, with: true)
}
blackHole(a)
}
}
}
}
@@ -383,5 +383,73 @@ extension Benchmark {
blackHole(a)
}
}
self.add(
title: "BitSet formUnion with Range",
input: Int.self
) { input in
guard input > 0 else { return nil }
return { timer in
var a = BitSet(reservingCapacity: input)
a.insert(input - 1)
timer.measure {
a.formUnion(0 ..< input)
}
blackHole(a)
}
}
self.add(
title: "BitSet init from Range",
input: Int.self
) { input in
guard input > 0 else { return nil }
return { timer in
timer.measure {
blackHole(BitSet(0 ..< input))
}
}
}
self.add(
title: "BitSet union with Range",
input: Int.self
) { input in
guard input > 0 else { return nil }
var a = BitSet(reservingCapacity: input)
a.insert(input - 1)
return { timer in
timer.measure {
blackHole(a.union(0 ..< input))
}
}
}
self.add(
title: "BitSet.Counted formUnion with Range",
input: Int.self
) { input in
guard input > 0 else { return nil }
return { timer in
var a = BitSet.Counted(reservingCapacity: input)
a.insert(input - 1)
timer.measure {
a.formUnion(0 ..< input)
}
blackHole(a)
}
}
self.add(
title: "BitSet.Counted init from Range",
input: Int.self
) { input in
guard input > 0 else { return nil }
return { timer in
timer.measure {
blackHole(BitSet.Counted(0 ..< input))
}
}
}
}
}
@@ -43,6 +43,7 @@ benchmark.addSortedDictionaryBenchmarks()
#endif
benchmark.addHeapBenchmarks()
benchmark.addBitSetBenchmarks()
benchmark.addBitArrayBenchmarks()
benchmark.addTreeSetBenchmarks()
benchmark.addCppBenchmarks()
#if EnableRustBenchmarks
@@ -250,6 +250,7 @@ extension _UnsafeBitSet._Word {
Self(0)
}
@inlinable
@inline(__always)
package static var allBits: Self {
Self(UInt.max)