Skip to content

Commit 875fba3

Browse files
committed
Reserve A Bit of Scratch Space In The RecordBuffer
This improves the performance of appending strings to the bitstream writer somewhat by giving us some room to work with.
1 parent fe1a84f commit 875fba3

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

Sources/TSCUtility/BitstreamReader.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ private struct BitstreamReader {
148148
}
149149
}
150150

151+
/// Computes a non-owning view of a `BitcodeElement.Record` that is valid for
152+
/// the lifetime of the call to `body`.
153+
///
154+
/// - Warning: If this function throws, the `body` block will not be called.
151155
mutating func withAbbreviatedRecord(
152156
_ abbrev: Bitstream.Abbreviation,
153157
body: (BitcodeElement.Record) throws -> Void

Sources/TSCUtility/BitstreamWriter.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ extension BitstreamWriter {
338338

339339
fileprivate init() {
340340
self.values = []
341+
self.values.reserveCapacity(8)
341342
}
342343

343344
fileprivate init<CodeType>(recordID: CodeType)
@@ -367,6 +368,7 @@ extension BitstreamWriter {
367368
}
368369

369370
public mutating func append(_ string: String) {
371+
self.values.reserveCapacity(self.values.capacity + string.utf8.count)
370372
for byte in string.utf8 {
371373
values.append(UInt32(byte))
372374
}

0 commit comments

Comments
 (0)