mirror of
https://github.com/apple/swift.git
synced 2026-03-04 18:24:35 +01:00
Removes redundant ObjectiveC <-> Swift bridging calls. Basically, if a value is bridged from ObjectiveC to Swift an then back to ObjectiveC again, then just re-use the original ObjectiveC value. Also in this commit: add an additional DCE pass before ownership elimination. It can cleanup dead code which is left behind by the ObjCBridgingOptimization. rdar://89987440
44 lines
886 B
Objective-C
44 lines
886 B
Objective-C
#include "objc.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
void useNSString(NSString * _Nonnull s) {
|
|
const char *str = [s cStringUsingEncoding: NSUTF8StringEncoding];
|
|
if (str[0] == '\0') {
|
|
puts("<empty>");
|
|
} else {
|
|
puts(str);
|
|
}
|
|
}
|
|
|
|
void useOptNSString(NSString * _Nullable s) {
|
|
if (s) {
|
|
const char *str = [s cStringUsingEncoding: NSUTF8StringEncoding];
|
|
puts(str);
|
|
} else {
|
|
puts("NULL");
|
|
}
|
|
}
|
|
|
|
NSString * _Nonnull returnNSString() {
|
|
NSString *str = [[NSString alloc] initWithCString: "This is an ObjectiveC string!" encoding: NSUTF8StringEncoding];
|
|
return str;
|
|
}
|
|
|
|
NSString *g;
|
|
|
|
NSString * _Nonnull returnNullNSString() {
|
|
return g;
|
|
}
|
|
|
|
NSString * _Nullable returnOptNSString(BOOL some) {
|
|
if (some) {
|
|
NSString *str = [[NSString alloc] initWithCString: "This is an optional ObjectiveC string!" encoding: NSUTF8StringEncoding];
|
|
return str;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|