refactor: pass base::Value by value in JS API implementations (#20809)

* refactor: move the arg instead of const reference it

* refactor: avoid unnecessary copies of base::Value in arg

* refactor: pass-by-value in dict_util

* refactor: avoid unnecessary reference
This commit is contained in:
Cheng Zhao 2019-10-30 14:30:59 +09:00 committed by GitHub
parent c03ed6d3a1
commit 0ab9cc30d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 108 additions and 144 deletions

View file

@ -259,9 +259,8 @@ float NativeImage::GetAspectRatio() {
return static_cast<float>(size.width()) / static_cast<float>(size.height());
}
gin::Handle<NativeImage> NativeImage::Resize(
v8::Isolate* isolate,
const base::DictionaryValue& options) {
gin::Handle<NativeImage> NativeImage::Resize(v8::Isolate* isolate,
base::DictionaryValue options) {
gfx::Size size = GetSize();
int width = size.width();
int height = size.height();

View file

@ -87,7 +87,7 @@ class NativeImage : public mate::Wrappable<NativeImage> {
v8::Local<v8::Value> GetBitmap(gin::Arguments* args);
v8::Local<v8::Value> GetNativeHandle(gin_helper::ErrorThrower thrower);
gin::Handle<NativeImage> Resize(v8::Isolate* isolate,
const base::DictionaryValue& options);
base::DictionaryValue options);
gin::Handle<NativeImage> Crop(v8::Isolate* isolate, const gfx::Rect& rect);
std::string ToDataURL(gin::Arguments* args);
bool IsEmpty();

View file

@ -194,7 +194,7 @@ bool Archive::Init() {
header_size_ = 8 + size;
header_ = base::DictionaryValue::From(
std::make_unique<base::Value>(value->Clone()));
base::Value::ToUniquePtrValue(std::move(*value)));
return true;
}

View file

@ -216,7 +216,8 @@ class Invoker<IndicesHolder<indices...>, ArgTypes...>
void DispatchToCallback(base::Callback<ReturnType(ArgTypes...)> callback) {
v8::MicrotasksScope script_scope(args_->isolate(),
v8::MicrotasksScope::kRunMicrotasks);
args_->Return(callback.Run(ArgumentHolder<indices, ArgTypes>::value...));
args_->Return(
callback.Run(std::move(ArgumentHolder<indices, ArgTypes>::value)...));
}
// In C++, you can declare the function foo(void), but you can't pass a void
@ -225,7 +226,7 @@ class Invoker<IndicesHolder<indices...>, ArgTypes...>
void DispatchToCallback(base::Callback<void(ArgTypes...)> callback) {
v8::MicrotasksScope script_scope(args_->isolate(),
v8::MicrotasksScope::kRunMicrotasks);
callback.Run(ArgumentHolder<indices, ArgTypes>::value...);
callback.Run(std::move(ArgumentHolder<indices, ArgTypes>::value)...);
}
private:

View file

@ -5,6 +5,7 @@
#include "shell/common/native_mate_converters/value_converter.h"
#include <memory>
#include <utility>
#include "base/values.h"
#include "shell/common/native_mate_converters/v8_value_converter.h"
@ -39,7 +40,7 @@ bool Converter<base::Value>::FromV8(v8::Isolate* isolate,
std::unique_ptr<base::Value> value(
converter.FromV8Value(val, isolate->GetCurrentContext()));
if (value) {
*out = value->Clone();
*out = std::move(*value);
return true;
} else {
return false;