Modernize Objective-C
Via tools/mac/rewrite_modern_objc.py in the Chromium repo
Bug: chromium:324079
Change-Id: Ic2e27a1d25e937439b3e536c8eec533ea93b7421
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2904179
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Leonard Grey <lgrey@chromium.org>
GitOrigin-RevId: 3a112cfefdc636d2e937d665d85c3c9da181c9d7
diff --git a/tools/mac/on_demand_service_tool.mm b/tools/mac/on_demand_service_tool.mm
index 70de1b5..7b3e104 100644
--- a/tools/mac/on_demand_service_tool.mm
+++ b/tools/mac/on_demand_service_tool.mm
@@ -152,13 +152,12 @@
dictionaryWithCapacity:options.mach_services.size()];
for (std::string mach_service : options.mach_services) {
NSString* mach_service_ns = base::SysUTF8ToNSString(mach_service);
- [mach_services setObject:@YES forKey:mach_service_ns];
+ mach_services[mach_service_ns] = @YES;
}
NSMutableDictionary* mutable_job_dictionary =
[[job_dictionary mutableCopy] autorelease];
- [mutable_job_dictionary setObject:mach_services
- forKey:@LAUNCH_JOBKEY_MACHSERVICES];
+ mutable_job_dictionary[@LAUNCH_JOBKEY_MACHSERVICES] = mach_services;
job_dictionary = mutable_job_dictionary;
}
diff --git a/util/mac/launchd.mm b/util/mac/launchd.mm
index ef5a606..37748ee 100644
--- a/util/mac/launchd.mm
+++ b/util/mac/launchd.mm
@@ -45,7 +45,7 @@
}
CFPropertyListRef value_cf =
- implicit_cast<CFPropertyListRef>([dictionary_ns objectForKey:key]);
+ implicit_cast<CFPropertyListRef>(dictionary_ns[key]);
launch_data_t value_launch = CFPropertyToLaunchData(value_cf);
if (!value_launch) {
return nullptr;
diff --git a/util/mac/launchd_test.mm b/util/mac/launchd_test.mm
index b793a9b..6b51ee2 100644
--- a/util/mac/launchd_test.mm
+++ b/util/mac/launchd_test.mm
@@ -78,14 +78,14 @@
@0.0,
@1.0,
@-1.0,
- [NSNumber numberWithFloat:std::numeric_limits<float>::min()],
- [NSNumber numberWithFloat:std::numeric_limits<float>::max()],
- [NSNumber numberWithDouble:std::numeric_limits<double>::min()],
- [NSNumber numberWithDouble:std::numeric_limits<double>::max()],
+ @(std::numeric_limits<float>::min()),
+ @(std::numeric_limits<float>::max()),
+ @(std::numeric_limits<double>::min()),
+ @(std::numeric_limits<double>::max()),
@3.1415926535897932,
- [NSNumber numberWithDouble:std::numeric_limits<double>::infinity()],
- [NSNumber numberWithDouble:std::numeric_limits<double>::quiet_NaN()],
- [NSNumber numberWithDouble:std::numeric_limits<double>::signaling_NaN()],
+ @(std::numeric_limits<double>::infinity()),
+ @(std::numeric_limits<double>::quiet_NaN()),
+ @(std::numeric_limits<double>::signaling_NaN()),
};
for (size_t index = 0; index < base::size(double_nses); ++index) {
diff --git a/util/net/http_transport_mac.mm b/util/net/http_transport_mac.mm
index 8faa1b8..b9be11c 100644
--- a/util/net/http_transport_mac.mm
+++ b/util/net/http_transport_mac.mm
@@ -52,13 +52,11 @@
// CFNetwork would use the main bundle’s CFBundleName, or the main
// executable’s filename if none.
- user_agent = AppendEscapedFormat(
- user_agent, @"%@", [NSString stringWithUTF8String:PACKAGE_NAME]);
+ user_agent = AppendEscapedFormat(user_agent, @"%@", @PACKAGE_NAME);
// CFNetwork would use the main bundle’s CFBundleVersion, or the string
// “(unknown version)” if none.
- user_agent = AppendEscapedFormat(
- user_agent, @"/%@", [NSString stringWithUTF8String:PACKAGE_VERSION]);
+ user_agent = AppendEscapedFormat(user_agent, @"/%@", @PACKAGE_VERSION);
// Expected to be CFNetwork.
NSBundle* nsurl_bundle = [NSBundle bundleForClass:[NSURLRequest class]];
@@ -78,10 +76,8 @@
if (uname(&os) != 0) {
PLOG(WARNING) << "uname";
} else {
- user_agent = AppendEscapedFormat(
- user_agent, @" %@", [NSString stringWithUTF8String:os.sysname]);
- user_agent = AppendEscapedFormat(
- user_agent, @"/%@", [NSString stringWithUTF8String:os.release]);
+ user_agent = AppendEscapedFormat(user_agent, @" %@", @(os.sysname));
+ user_agent = AppendEscapedFormat(user_agent, @"/%@", @(os.release));
// CFNetwork just uses the equivalent of os.machine to obtain the native
// (kernel) architecture. Here, give the process’ architecture as well as
@@ -98,7 +94,7 @@
#endif
user_agent = AppendEscapedFormat(user_agent, @" (%@", arch);
- NSString* machine = [NSString stringWithUTF8String:os.machine];
+ NSString* machine = @(os.machine);
if (![machine isEqualToString:arch]) {
user_agent = AppendEscapedFormat(user_agent, @"; %@", machine);
}