Avoid copying `Object` unnecessarily.
This commit is contained in:
parent
efdf0e01a9
commit
344fc42d4e
|
@ -96,7 +96,7 @@ void ListClass<T>::get_index(ContextType ctx, ObjectType object, uint32_t index,
|
|||
auto list = get_internal<T, ListClass<T>>(object);
|
||||
auto realm_object = realm::Object(list->get_realm(), list->get_object_schema(), list->get(index));
|
||||
|
||||
return_value.set(RealmObjectClass<T>::create_instance(ctx, realm_object));
|
||||
return_value.set(RealmObjectClass<T>::create_instance(ctx, std::move(realm_object)));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -132,7 +132,7 @@ void ListClass<T>::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<T>::create_instance(ctx, realm_object));
|
||||
return_value.set(RealmObjectClass<T>::create_instance(ctx, std::move(realm_object)));
|
||||
list->remove(index);
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ void ListClass<T>::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<T>::create_instance(ctx, realm_object));
|
||||
return_value.set(RealmObjectClass<T>::create_instance(ctx, std::move(realm_object)));
|
||||
list->remove(0);
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ void ListClass<T>::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<T>::create_instance(ctx, realm_object));
|
||||
removed_objects.push_back(RealmObjectClass<T>::create_instance(ctx, std::move(realm_object)));
|
||||
list->remove(index);
|
||||
}
|
||||
for (size_t i = 2; i < argc; i++) {
|
||||
|
|
|
@ -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<T>::create_instance(ctx, realm_object);
|
||||
return RealmObjectClass<T>::create_instance(ctx, std::move(realm_object));
|
||||
}
|
||||
|
||||
static size_t list_size(ContextType ctx, ValueType &value) {
|
||||
|
|
|
@ -491,7 +491,7 @@ void RealmClass<T>::create(ContextType ctx, ObjectType this_object, size_t argc,
|
|||
}
|
||||
|
||||
auto realm_object = realm::Object::create<ValueType>(ctx, realm, *object_schema, object, update);
|
||||
return_value.set(RealmObjectClass<T>::create_instance(ctx, realm_object));
|
||||
return_value.set(RealmObjectClass<T>::create_instance(ctx, std::move(realm_object)));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
|
@ -40,7 +40,7 @@ struct RealmObjectClass : ClassDefinition<T, realm::Object> {
|
|||
using Function = js::Function<T>;
|
||||
using ReturnValue = js::ReturnValue<T>;
|
||||
|
||||
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<T>::is_valid(ContextType ctx, ObjectType this_object, size
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
typename T::Object RealmObjectClass<T>::create_instance(ContextType ctx, realm::Object &realm_object) {
|
||||
typename T::Object RealmObjectClass<T>::create_instance(ContextType ctx, realm::Object realm_object) {
|
||||
static String prototype_string = "prototype";
|
||||
|
||||
auto delegate = get_delegate<T>(realm_object.realm().get());
|
||||
auto name = realm_object.get_object_schema().name;
|
||||
auto object = create_object<T, RealmObjectClass<T>>(ctx, new realm::Object(realm_object));
|
||||
auto object = create_object<T, RealmObjectClass<T>>(ctx, new realm::Object(std::move(realm_object)));
|
||||
|
||||
if (!delegate || !delegate->m_constructors.count(name)) {
|
||||
return object;
|
||||
|
|
|
@ -208,7 +208,7 @@ void ResultsClass<T>::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<T>::create_instance(ctx, realm_object));
|
||||
return_value.set(RealmObjectClass<T>::create_instance(ctx, std::move(realm_object)));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
Loading…
Reference in New Issue