From 344fc42d4e326a0e2f27fda80637a76663ad259b Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Tue, 31 May 2016 15:54:43 -0700 Subject: [PATCH] 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