refactor: simplify code by using base::Value::EnsureList() (#41162)

This commit is contained in:
Charles Kerr 2024-01-30 14:48:09 -06:00 committed by GitHub
parent 90c7d6c823
commit 08615b2d4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 13 deletions

View file

@ -114,10 +114,7 @@ v8::Local<v8::Value> HttpResponseHeadersToV8(
std::string filename = "\"" + header.filename() + "\""; std::string filename = "\"" + header.filename() + "\"";
value = decodedFilename + "; filename=" + filename; value = decodedFilename + "; filename=" + filename;
} }
base::Value::List* values = response_headers.FindList(key); response_headers.EnsureList(key)->Append(value);
if (!values)
values = &response_headers.Set(key, base::Value::List())->GetList();
values->Append(base::Value(value));
} }
} }
return gin::ConvertToV8(v8::Isolate::GetCurrent(), response_headers); return gin::ConvertToV8(v8::Isolate::GetCurrent(), response_headers);

View file

@ -49,15 +49,7 @@ void GPUInfoEnumerator::EndGPUDevice() {
auto& top_value = value_stack_.top(); auto& top_value = value_stack_.top();
// GPUDevice can be more than one. So create a list of all. // GPUDevice can be more than one. So create a list of all.
// The first one is the active GPU device. // The first one is the active GPU device.
if (base::Value* list_value = top_value.Find(kGPUDeviceKey)) { top_value.EnsureList(kGPUDeviceKey)->Append(std::move(current_));
DCHECK(list_value->is_list());
base::Value::List& list = list_value->GetList();
list.Append(std::move(current_));
} else {
base::Value::List gpus;
gpus.Append(std::move(current_));
top_value.Set(kGPUDeviceKey, std::move(gpus));
}
current_ = std::move(top_value); current_ = std::move(top_value);
value_stack_.pop(); value_stack_.pop();
} }