Skip to content

Commit b0de132

Browse files
committed
[stdlib-private][oslog] Remove OSLogArguments.serializeAt method
and instead directly access the array stored in OSLogArguments. This will make constant folding of the array possible when its contents are inferred at compile time by the OSLogOptimization pass.
1 parent 1a81074 commit b0de132

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

stdlib/private/OSLog/OSLog.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ internal func osLog(
6666
let preamble = message.interpolation.preamble
6767
let argumentCount = message.interpolation.argumentCount
6868
let bufferSize = message.bufferSize
69+
let argumentClosures = message.interpolation.arguments.argumentClosures
70+
6971
let formatStringPointer = _getGlobalStringTablePointer(formatString)
7072

7173
// Code that will execute at runtime.
7274
guard logObject.isEnabled(type: logLevel) else { return }
7375

74-
let arguments = message.interpolation.arguments
75-
7676
// Allocate a byte buffer to store the arguments. The buffer could be stack
7777
// allocated as it is local to this function and also its size is a
7878
// compile-time constant.
@@ -84,7 +84,7 @@ internal func osLog(
8484
var currentBufferPosition = bufferMemory
8585
serialize(preamble, at: &currentBufferPosition)
8686
serialize(argumentCount, at: &currentBufferPosition)
87-
arguments.serializeAt(&currentBufferPosition, using: &stringStorageObjects)
87+
argumentClosures.forEach { $0(&currentBufferPosition, &stringStorageObjects) }
8888

8989
___os_log_impl(UnsafeMutableRawPointer(mutating: #dsohandle),
9090
logObject,
@@ -120,6 +120,7 @@ func _checkFormatStringAndBuffer(
120120
let preamble = message.interpolation.preamble
121121
let argumentCount = message.interpolation.argumentCount
122122
let bufferSize = message.bufferSize
123+
let argumentClosures = message.interpolation.arguments.argumentClosures
123124

124125
// Code that will execute at runtime.
125126
let bufferMemory = UnsafeMutablePointer<UInt8>.allocate(capacity: bufferSize)
@@ -128,9 +129,7 @@ func _checkFormatStringAndBuffer(
128129
var currentBufferPosition = bufferMemory
129130
serialize(preamble, at: &currentBufferPosition)
130131
serialize(argumentCount, at: &currentBufferPosition)
131-
message.interpolation.arguments.serializeAt(
132-
&currentBufferPosition,
133-
using: &stringStorageObjects)
132+
argumentClosures.forEach { $0(&currentBufferPosition, &stringStorageObjects) }
134133

135134
assertion(
136135
formatString,

stdlib/private/OSLog/OSLogMessage.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -349,22 +349,6 @@ internal struct OSLogArguments {
349349
}
350350

351351
/// `append` for other types must be implemented by extensions.
352-
353-
/// Serialize the arguments tracked by self in a byte buffer.
354-
/// - Parameters:
355-
/// - bufferPosition: the pointer to a location within a byte buffer where
356-
/// the argument must be serialized. This will be incremented by the number
357-
/// of bytes used up to serialize the arguments.
358-
/// - storageObjects: An array to store references to objects representing
359-
/// auxiliary storage created during serialization. This is only used while
360-
/// serializing strings.
361-
@usableFromInline
362-
internal func serializeAt(
363-
_ bufferPosition: inout ByteBufferPointer,
364-
using storageObjects: inout StorageObjects
365-
) {
366-
argumentClosures.forEach { $0(&bufferPosition, &storageObjects) }
367-
}
368352
}
369353

370354
/// Serialize a UInt8 value at the buffer location pointed to by `bufferPosition`,

0 commit comments

Comments
 (0)