Remove unnecessary copy during CefBinaryValue creation (see #3502)

This commit is contained in:
Nik Pavlov 2023-10-05 16:57:01 +00:00 committed by Marshall Greenblatt
parent f8dd0dbfb4
commit d8ea7363f5
2 changed files with 8 additions and 9 deletions

View File

@ -493,8 +493,8 @@ CefRefPtr<CefBinaryValue> CefBinaryValue::Create(const void* data,
return nullptr; return nullptr;
} }
return new CefBinaryValueImpl(static_cast<char*>(const_cast<void*>(data)), const auto ptr = static_cast<const uint8_t*>(data);
data_size); return new CefBinaryValueImpl(base::make_span(ptr, data_size));
} }
// static // static
@ -525,9 +525,8 @@ CefBinaryValueImpl::CefBinaryValueImpl(base::Value* value, bool will_delete)
will_delete ? kOwnerWillDelete : kOwnerNoDelete, will_delete ? kOwnerWillDelete : kOwnerNoDelete,
nullptr) {} nullptr) {}
CefBinaryValueImpl::CefBinaryValueImpl(char* data, size_t data_size) CefBinaryValueImpl::CefBinaryValueImpl(base::span<const uint8_t> value)
: CefBinaryValueImpl( : CefBinaryValueImpl(new base::Value(value),
new base::Value(std::vector<char>(data, data + data_size)),
nullptr, nullptr,
kOwnerWillDelete, kOwnerWillDelete,
nullptr) {} nullptr) {}

View File

@ -151,7 +151,7 @@ class CefBinaryValueImpl : public CefValueBase<CefBinaryValue, base::Value> {
CefBinaryValueImpl(base::Value* value, bool will_delete); CefBinaryValueImpl(base::Value* value, bool will_delete);
// The data will always be copied. // The data will always be copied.
CefBinaryValueImpl(char* data, size_t data_size); explicit CefBinaryValueImpl(base::span<const uint8_t> value);
CefBinaryValueImpl(const CefBinaryValueImpl&) = delete; CefBinaryValueImpl(const CefBinaryValueImpl&) = delete;
CefBinaryValueImpl& operator=(const CefBinaryValueImpl&) = delete; CefBinaryValueImpl& operator=(const CefBinaryValueImpl&) = delete;