Skip to content

Commit 275861f

Browse files
committed
FunctionUses: don't eagerly reserve array capacities in the initializer
Instead do it in `collect`. This allows creating a `FunctionUses` with zero cost - in case `collect` is never called.
1 parent 9795f4b commit 275861f

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

SwiftCompilerSources/Sources/Optimizer/DataStructures/FunctionUses.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ struct FunctionUses {
109109
// The use-list head for each function.
110110
private var uses: [Function: FirstUse] = [:]
111111

112-
init() {
113-
// Already start with a reasonable big capacity to reduce the number of
114-
// re-allocations when appending to the data structures.
115-
useStorage.reserveCapacity(128)
116-
uses.reserveCapacity(64)
117-
}
118-
119112
/// Returns the use-list of `function`.
120113
///
121114
/// Note that `collect` must be called before `getUses` can be used.
@@ -125,7 +118,12 @@ struct FunctionUses {
125118

126119
/// Collects all uses of all function in the module.
127120
mutating func collect(context: ModulePassContext) {
128-
121+
122+
// Already start with a reasonable big capacity to reduce the number of
123+
// re-allocations when appending to the data structures.
124+
useStorage.reserveCapacity(128)
125+
uses.reserveCapacity(64)
126+
129127
// Mark all functions, which are referenced from tables, to have "unknown" uses.
130128

131129
for vTable in context.vTables {

0 commit comments

Comments
 (0)