Remove unnecessary heap allocations of atom::V8ValueConverter instances (#12924)

This commit is contained in:
Milan Burda 2018-05-15 16:21:23 +02:00 committed by Charles Kerr
parent 9fc6b9dda2
commit 6a4d9309b2

View file

@ -12,9 +12,9 @@ namespace mate {
bool Converter<base::DictionaryValue>::FromV8(v8::Isolate* isolate, bool Converter<base::DictionaryValue>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val, v8::Local<v8::Value> val,
base::DictionaryValue* out) { base::DictionaryValue* out) {
std::unique_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter); atom::V8ValueConverter converter;
std::unique_ptr<base::Value> value( std::unique_ptr<base::Value> value(
converter->FromV8Value(val, isolate->GetCurrentContext())); converter.FromV8Value(val, isolate->GetCurrentContext()));
if (value && value->IsType(base::Value::Type::DICTIONARY)) { if (value && value->IsType(base::Value::Type::DICTIONARY)) {
out->Swap(static_cast<base::DictionaryValue*>(value.get())); out->Swap(static_cast<base::DictionaryValue*>(value.get()));
return true; return true;
@ -26,16 +26,16 @@ bool Converter<base::DictionaryValue>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> Converter<base::DictionaryValue>::ToV8( v8::Local<v8::Value> Converter<base::DictionaryValue>::ToV8(
v8::Isolate* isolate, v8::Isolate* isolate,
const base::DictionaryValue& val) { const base::DictionaryValue& val) {
std::unique_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter); atom::V8ValueConverter converter;
return converter->ToV8Value(&val, isolate->GetCurrentContext()); return converter.ToV8Value(&val, isolate->GetCurrentContext());
} }
bool Converter<base::ListValue>::FromV8(v8::Isolate* isolate, bool Converter<base::ListValue>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val, v8::Local<v8::Value> val,
base::ListValue* out) { base::ListValue* out) {
std::unique_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter); atom::V8ValueConverter converter;
std::unique_ptr<base::Value> value( std::unique_ptr<base::Value> value(
converter->FromV8Value(val, isolate->GetCurrentContext())); converter.FromV8Value(val, isolate->GetCurrentContext()));
if (value->IsType(base::Value::Type::LIST)) { if (value->IsType(base::Value::Type::LIST)) {
out->Swap(static_cast<base::ListValue*>(value.get())); out->Swap(static_cast<base::ListValue*>(value.get()));
return true; return true;
@ -47,8 +47,8 @@ bool Converter<base::ListValue>::FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> Converter<base::ListValue>::ToV8( v8::Local<v8::Value> Converter<base::ListValue>::ToV8(
v8::Isolate* isolate, v8::Isolate* isolate,
const base::ListValue& val) { const base::ListValue& val) {
std::unique_ptr<atom::V8ValueConverter> converter(new atom::V8ValueConverter); atom::V8ValueConverter converter;
return converter->ToV8Value(&val, isolate->GetCurrentContext()); return converter.ToV8Value(&val, isolate->GetCurrentContext());
} }
} // namespace mate } // namespace mate