diff --git a/src/js_list.hpp b/src/js_list.hpp index ad119f5b..de840554 100644 --- a/src/js_list.hpp +++ b/src/js_list.hpp @@ -207,7 +207,7 @@ void ListClass::snapshot(ContextType ctx, ObjectType this_object, size_t argc validate_argument_count(argc, 0); auto list = get_internal>(this_object); - return_value.set(ResultsClass::create_instance(ctx, *list, false)); + return_value.set(ResultsClass::create_instance(ctx, realm::Results(list->get_realm(), list->get_query()).snapshot())); } template diff --git a/src/js_object_accessor.hpp b/src/js_object_accessor.hpp index 512de6ce..bce1089d 100644 --- a/src/js_object_accessor.hpp +++ b/src/js_object_accessor.hpp @@ -147,7 +147,7 @@ struct NativeAccessor { return ListClass::create_instance(ctx, std::move(list)); } static ValueType from_results(ContextType ctx, realm::Results results) { - return ResultsClass::create_instance(ctx, results); + return ResultsClass::create_instance(ctx, std::move(results)); } static Mixed to_mixed(ContextType ctx, ValueType &val) { throw std::runtime_error("'Any' type is unsupported"); diff --git a/src/js_results.hpp b/src/js_results.hpp index 08991f46..3913bb83 100644 --- a/src/js_results.hpp +++ b/src/js_results.hpp @@ -38,10 +38,8 @@ struct ResultsClass : ClassDefinition> { using Value = js::Value; using ReturnValue = js::ReturnValue; - static ObjectType create_instance(ContextType, const realm::Results &, bool live = true); - static ObjectType create_instance(ContextType, const realm::List &, bool live = true); - static ObjectType create_instance(ContextType, SharedRealm, const ObjectSchema &, bool live = true); - static ObjectType create_instance(ContextType, SharedRealm, const ObjectSchema &, Query, bool live = true); + static ObjectType create_instance(ContextType, realm::Results); + static ObjectType create_instance(ContextType, SharedRealm, const ObjectSchema &); template static ObjectType create_filtered(ContextType, const U &, size_t, const ValueType[]); @@ -74,33 +72,14 @@ struct ResultsClass : ClassDefinition> { }; template -typename T::Object ResultsClass::create_instance(ContextType ctx, const realm::Results &results, bool live) { - auto new_results = new realm::Results(results); - new_results->set_live(live); - - return create_object>(ctx, new_results); +typename T::Object ResultsClass::create_instance(ContextType ctx, realm::Results results) { + return create_object>(ctx, new realm::Results(std::move(results))); } template -typename T::Object ResultsClass::create_instance(ContextType ctx, const realm::List &list, bool live) { - return create_instance(ctx, list.get_realm(), list.get_object_schema(), list.get_query(), live); -} - -template -typename T::Object ResultsClass::create_instance(ContextType ctx, SharedRealm realm, const ObjectSchema &object_schema, bool live) { +typename T::Object ResultsClass::create_instance(ContextType ctx, SharedRealm realm, const ObjectSchema &object_schema) { auto table = ObjectStore::table_for_object_type(realm->read_group(), object_schema.name); - auto results = new realm::Results(realm, object_schema, *table); - results->set_live(live); - - return create_object>(ctx, results); -} - -template -typename T::Object ResultsClass::create_instance(ContextType ctx, SharedRealm realm, const ObjectSchema &object_schema, Query query, bool live) { - auto results = new realm::Results(realm, object_schema, std::move(query)); - results->set_live(live); - - return create_object>(ctx, results); + return create_object>(ctx, new realm::Results(realm, *table)); } template @@ -111,18 +90,13 @@ typename T::Object ResultsClass::create_filtered(ContextType ctx, const U &co auto const &realm = collection.get_realm(); auto const &object_schema = collection.get_object_schema(); - std::vector args; - args.reserve(argc - 1); - - for (size_t i = 1; i < argc; i++) { - args.push_back(arguments[i]); - } + std::vector args(&arguments[1], &arguments[argc]); parser::Predicate predicate = parser::parse(query_string); query_builder::ArgumentConverter converter(ctx, realm, args); query_builder::apply_predicate(query, predicate, converter, *realm->config().schema, object_schema.name); - return create_instance(ctx, realm, object_schema, std::move(query)); + return create_instance(ctx, realm::Results(realm, std::move(query))); } template @@ -179,7 +153,7 @@ typename T::Object ResultsClass::create_sorted(ContextType ctx, const U &coll columns.push_back(prop->table_column); } - auto results = new realm::Results(realm, object_schema, collection.get_query(), {std::move(columns), std::move(ascending)}); + auto results = new realm::Results(realm, collection.get_query(), {std::move(columns), std::move(ascending)}); return create_object>(ctx, results); } @@ -209,7 +183,7 @@ void ResultsClass::snapshot(ContextType ctx, ObjectType this_object, size_t a validate_argument_count(argc, 0); auto results = get_internal>(this_object); - return_value.set(ResultsClass::create_instance(ctx, *results, false)); + return_value.set(ResultsClass::create_instance(ctx, results->snapshot())); } template