From efdf0e01a9700f5536999eef32d01e02fbf72c14 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Tue, 31 May 2016 15:27:48 -0700 Subject: [PATCH 1/2] Avoid copying `List` unnecessarily. --- src/js_list.hpp | 6 +++--- src/js_object_accessor.hpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/js_list.hpp b/src/js_list.hpp index d936159c..52fe358c 100644 --- a/src/js_list.hpp +++ b/src/js_list.hpp @@ -41,7 +41,7 @@ struct ListClass : ClassDefinition> { using Value = js::Value; using ReturnValue = js::ReturnValue; - static ObjectType create_instance(ContextType, realm::List &); + static ObjectType create_instance(ContextType, realm::List); // properties static void get_length(ContextType, ObjectType, ReturnValue &); @@ -81,8 +81,8 @@ struct ListClass : ClassDefinition> { }; template -typename T::Object ListClass::create_instance(ContextType ctx, realm::List &list) { - return create_object>(ctx, new realm::List(list)); +typename T::Object ListClass::create_instance(ContextType ctx, realm::List list) { + return create_object>(ctx, new realm::List(std::move(list))); } template diff --git a/src/js_object_accessor.hpp b/src/js_object_accessor.hpp index 4809f23a..dead643e 100644 --- a/src/js_object_accessor.hpp +++ b/src/js_object_accessor.hpp @@ -135,7 +135,7 @@ struct NativeAccessor { return Object::validated_get_object(ctx, Value::validated_to_object(ctx, value), (uint32_t)index); } static ValueType from_list(ContextType ctx, realm::List list) { - return ListClass::create_instance(ctx, list); + return ListClass::create_instance(ctx, std::move(list)); } static Mixed to_mixed(ContextType ctx, ValueType &val) { From 344fc42d4e326a0e2f27fda80637a76663ad259b Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Tue, 31 May 2016 15:54:43 -0700 Subject: [PATCH 2/2] Avoid copying `Object` unnecessarily. --- src/js_list.hpp | 8 ++++---- src/js_object_accessor.hpp | 2 +- src/js_realm.hpp | 2 +- src/js_realm_object.hpp | 6 +++--- src/js_results.hpp | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/js_list.hpp b/src/js_list.hpp index 52fe358c..ad119f5b 100644 --- a/src/js_list.hpp +++ b/src/js_list.hpp @@ -96,7 +96,7 @@ void ListClass::get_index(ContextType ctx, ObjectType object, uint32_t index, auto list = get_internal>(object); auto realm_object = realm::Object(list->get_realm(), list->get_object_schema(), list->get(index)); - return_value.set(RealmObjectClass::create_instance(ctx, realm_object)); + return_value.set(RealmObjectClass::create_instance(ctx, std::move(realm_object))); } template @@ -132,7 +132,7 @@ void ListClass::pop(ContextType ctx, ObjectType this_object, size_t argc, con size_t index = size - 1; auto realm_object = realm::Object(list->get_realm(), list->get_object_schema(), list->get(index)); - return_value.set(RealmObjectClass::create_instance(ctx, realm_object)); + return_value.set(RealmObjectClass::create_instance(ctx, std::move(realm_object))); list->remove(index); } } @@ -161,7 +161,7 @@ void ListClass::shift(ContextType ctx, ObjectType this_object, size_t argc, c else { auto realm_object = realm::Object(list->get_realm(), list->get_object_schema(), list->get(0)); - return_value.set(RealmObjectClass::create_instance(ctx, realm_object)); + return_value.set(RealmObjectClass::create_instance(ctx, std::move(realm_object))); list->remove(0); } } @@ -192,7 +192,7 @@ void ListClass::splice(ContextType ctx, ObjectType this_object, size_t argc, for (size_t i = 0; i < remove; i++) { auto realm_object = realm::Object(list->get_realm(), list->get_object_schema(), list->get(index)); - removed_objects.push_back(RealmObjectClass::create_instance(ctx, realm_object)); + removed_objects.push_back(RealmObjectClass::create_instance(ctx, std::move(realm_object))); list->remove(index); } for (size_t i = 2; i < argc; i++) { diff --git a/src/js_object_accessor.hpp b/src/js_object_accessor.hpp index dead643e..b6e8eb40 100644 --- a/src/js_object_accessor.hpp +++ b/src/js_object_accessor.hpp @@ -125,7 +125,7 @@ struct NativeAccessor { throw std::runtime_error("object is not a Realm Object"); } static ValueType from_object(ContextType ctx, realm::Object realm_object) { - return RealmObjectClass::create_instance(ctx, realm_object); + return RealmObjectClass::create_instance(ctx, std::move(realm_object)); } static size_t list_size(ContextType ctx, ValueType &value) { diff --git a/src/js_realm.hpp b/src/js_realm.hpp index a3241c1e..ae2d6b08 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -491,7 +491,7 @@ void RealmClass::create(ContextType ctx, ObjectType this_object, size_t argc, } auto realm_object = realm::Object::create(ctx, realm, *object_schema, object, update); - return_value.set(RealmObjectClass::create_instance(ctx, realm_object)); + return_value.set(RealmObjectClass::create_instance(ctx, std::move(realm_object))); } template diff --git a/src/js_realm_object.hpp b/src/js_realm_object.hpp index 846d3388..e2e72658 100644 --- a/src/js_realm_object.hpp +++ b/src/js_realm_object.hpp @@ -40,7 +40,7 @@ struct RealmObjectClass : ClassDefinition { using Function = js::Function; using ReturnValue = js::ReturnValue; - static ObjectType create_instance(ContextType, realm::Object &); + static ObjectType create_instance(ContextType, realm::Object); static void get_property(ContextType, ObjectType, const String &, ReturnValue &); static bool set_property(ContextType, ObjectType, const String &, ValueType); @@ -67,12 +67,12 @@ void RealmObjectClass::is_valid(ContextType ctx, ObjectType this_object, size } template -typename T::Object RealmObjectClass::create_instance(ContextType ctx, realm::Object &realm_object) { +typename T::Object RealmObjectClass::create_instance(ContextType ctx, realm::Object realm_object) { static String prototype_string = "prototype"; auto delegate = get_delegate(realm_object.realm().get()); auto name = realm_object.get_object_schema().name; - auto object = create_object>(ctx, new realm::Object(realm_object)); + auto object = create_object>(ctx, new realm::Object(std::move(realm_object))); if (!delegate || !delegate->m_constructors.count(name)) { return object; diff --git a/src/js_results.hpp b/src/js_results.hpp index 9f021fb7..640d67fb 100644 --- a/src/js_results.hpp +++ b/src/js_results.hpp @@ -208,7 +208,7 @@ void ResultsClass::get_index(ContextType ctx, ObjectType object, uint32_t ind } auto realm_object = realm::Object(results->get_realm(), results->get_object_schema(), results->get(index)); - return_value.set(RealmObjectClass::create_instance(ctx, realm_object)); + return_value.set(RealmObjectClass::create_instance(ctx, std::move(realm_object))); } template