Skip to content

Commit 7baaeae

Browse files
authored
Merge pull request #7039 from briancroom/fix-XCTAssert-perf-regression-3.1
[3.1] [XCTest] Reduce bridging overhead from the exception-catching trampoline
2 parents 0d136dd + 4515ea0 commit 7baaeae

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

stdlib/public/SDK/XCTest/XCTest.swift

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,24 @@ enum _XCTThrowableBlockResult {
5353
/// and if it does consume the exception and return information about it.
5454
func _XCTRunThrowableBlock(_ block: () throws -> Void) -> _XCTThrowableBlockResult {
5555
var blockErrorOptional: Error?
56-
57-
let d = _XCTRunThrowableBlockBridge({
56+
57+
let exceptionResult = _XCTRunThrowableBlockBridge({
5858
do {
5959
try block()
6060
} catch {
6161
blockErrorOptional = error
6262
}
6363
})
64-
64+
6565
if let blockError = blockErrorOptional {
6666
return .failedWithError(error: blockError)
67-
} else if d.count > 0 {
68-
let t: String = d["type"]!
69-
70-
if t == "objc" {
67+
} else if let exceptionResult = exceptionResult {
68+
69+
if exceptionResult["type"] == "objc" {
7170
return .failedWithException(
72-
className: d["className"]!,
73-
name: d["name"]!,
74-
reason: d["reason"]!)
71+
className: exceptionResult["className"]!,
72+
name: exceptionResult["name"]!,
73+
reason: exceptionResult["reason"]!)
7574
} else {
7675
return .failedWithUnknownException
7776
}

stdlib/public/SDK/XCTest/XCTestCaseAdditions.mm

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,17 +133,15 @@ - (NSString *)className
133133
//
134134
// If no exception is thrown by the block, returns an empty dictionary.
135135

136-
XCT_EXPORT NSDictionary *_XCTRunThrowableBlockBridge(void (^block)());
136+
XCT_EXPORT NSDictionary<NSString *, NSString *> *_XCTRunThrowableBlockBridge(void (^block)());
137137

138-
NSDictionary *_XCTRunThrowableBlockBridge(void (^block)())
138+
NSDictionary<NSString *, NSString *> *_XCTRunThrowableBlockBridge(void (^block)())
139139
{
140-
NSDictionary *result;
140+
NSDictionary<NSString *, NSString *> *result = nil;
141141

142142
@try {
143143
block();
144-
result = @{};
145144
}
146-
147145
@catch (NSException *exception) {
148146
result = @{
149147
@"type": @"objc",
@@ -152,12 +150,11 @@ - (NSString *)className
152150
@"reason": exception.reason,
153151
};
154152
}
155-
156153
@catch (...) {
157154
result = @{
158155
@"type": @"unknown",
159156
};
160157
}
161158

162-
return [result retain];
159+
return result;
163160
}

stdlib/public/SwiftShims/XCTestOverlayShims.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
XCTestCase * _Nonnull _XCTCurrentTestCase(void);
2121

22-
NSDictionary<NSString *, NSString *> * _Nonnull
22+
NSDictionary<NSString *, NSString *> * _Nullable
2323
_XCTRunThrowableBlockBridge(void (^ _Nonnull NS_NOESCAPE block)());
2424

2525
#endif // SWIFT_STDLIB_SHIMS_XCTEST_OVERLAY_H

0 commit comments

Comments
 (0)