perf: avoid unnecessary base value clone (#38537)

This commit is contained in:
Charles Kerr 2023-06-02 08:38:29 -05:00 committed by GitHub
parent d818f35ad4
commit f247ca3f62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 28 deletions

View file

@ -14,7 +14,7 @@ namespace electron {
NSArray* ListValueToNSArray(const base::Value::List& value) {
std::string json;
if (!base::JSONWriter::Write(base::Value(value.Clone()), &json))
if (!base::JSONWriter::Write(base::ValueView{value}, &json))
return nil;
NSData* jsonData = [NSData dataWithBytes:json.c_str() length:json.length()];
id obj = [NSJSONSerialization JSONObjectWithData:jsonData
@ -57,7 +57,7 @@ base::Value::List NSArrayToValue(NSArray* arr) {
NSDictionary* DictionaryValueToNSDictionary(const base::Value::Dict& value) {
std::string json;
if (!base::JSONWriter::Write(base::Value(value.Clone()), &json))
if (!base::JSONWriter::Write(base::ValueView{value}, &json))
return nil;
NSData* jsonData = [NSData dataWithBytes:json.c_str() length:json.length()];
id obj = [NSJSONSerialization JSONObjectWithData:jsonData