Skip to content

Commit f728466

Browse files
committed
[SwiftCompilerSources] Use interpolation instead of String(describing:)
`String(describing:)` does a bunch of dynamic casts that can be pretty slow. Use interpolation instead, which bypasses them. For `swift-frontend`, this brings the time taken for type-checking an empty file down from ~100ms to ~70ms. For `swift build`, this brings the time taken for a null build down from ~600ms to ~450ms (the larger delta is presumably due to the fact that there's much more Swift code in `swift-package`).
1 parent d2801ec commit f728466

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

SwiftCompilerSources/Sources/AST/Registration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public func registerAST() {
4949
}
5050

5151
private func registerDecl<T: AnyObject>(_ cl: T.Type) {
52-
String(describing: cl)._withBridgedStringRef { nameStr in
52+
"\(cl)"._withBridgedStringRef { nameStr in
5353
let metatype = unsafeBitCast(cl, to: SwiftMetatype.self)
5454
registerBridgedDecl(nameStr, metatype)
5555
}

SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private func run<InstType: SILCombineSimplifyable>(_ instType: InstType.Type,
5656
private func registerForSILCombine<InstType: SILCombineSimplifyable>(
5757
_ instType: InstType.Type,
5858
_ runFn: @escaping (@convention(c) (BridgedInstructionPassCtxt) -> ())) {
59-
String(describing: instType)._withBridgedStringRef { instClassStr in
59+
"\(instType)"._withBridgedStringRef { instClassStr in
6060
SILCombine_registerInstructionPass(instClassStr, runFn)
6161
}
6262
}

SwiftCompilerSources/Sources/SIL/Registration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Basic
1414
import SILBridging
1515

1616
private func register<T: AnyObject>(_ cl: T.Type) {
17-
String(describing: cl)._withBridgedStringRef { nameStr in
17+
"\(cl)"._withBridgedStringRef { nameStr in
1818
let metatype = unsafeBitCast(cl, to: SwiftMetatype.self)
1919
registerBridgedClass(nameStr, metatype)
2020
}

0 commit comments

Comments
 (0)