From 1d01a1db73b261cdf1cb1d75b73f20153da580d5 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Wed, 17 Feb 2016 20:48:27 -0800 Subject: [PATCH] don't copy query unnecessarily --- src/js_list.cpp | 8 ++------ src/js_results.cpp | 17 +++++++---------- src/js_results.hpp | 4 ++-- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/js_list.cpp b/src/js_list.cpp index 673bcb0b..ba5878c8 100644 --- a/src/js_list.cpp +++ b/src/js_list.cpp @@ -191,9 +191,7 @@ JSValueRef ListStaticResults(JSContextRef ctx, JSObjectRef function, JSObjectRef try { List *list = RJSGetInternal(thisObject); RJSValidateArgumentCount(argumentCount, 0); - - Query query = list->get_query(); - return RJSResultsCreate(ctx, list->realm(), list->get_object_schema(), query, false); + return RJSResultsCreate(ctx, list->realm(), list->get_object_schema(), std::move(list->get_query()), false); } catch (std::exception &exp) { if (jsException) { @@ -209,9 +207,7 @@ JSValueRef ListFiltered(JSContextRef ctx, JSObjectRef function, JSObjectRef this RJSValidateArgumentCountIsAtLeast(argumentCount, 1); SharedRealm sharedRealm = *RJSGetInternal(thisObject); - - Query query = list->get_query(); - return RJSResultsCreate(ctx, sharedRealm, list->get_object_schema(), query, argumentCount, arguments); + return RJSResultsCreate(ctx, sharedRealm, list->get_object_schema(), std::move(list->get_query()), argumentCount, arguments); } catch (std::exception &exp) { if (jsException) { diff --git a/src/js_results.cpp b/src/js_results.cpp index 8fae5e7f..8f154b8c 100644 --- a/src/js_results.cpp +++ b/src/js_results.cpp @@ -124,9 +124,7 @@ JSValueRef ResultsFiltered(JSContextRef ctx, JSObjectRef function, JSObjectRef t RJSValidateArgumentCountIsAtLeast(argumentCount, 1); SharedRealm sharedRealm = *RJSGetInternal(thisObject); - - Query query = results->get_query(); - return RJSResultsCreate(ctx, sharedRealm, results->get_object_schema(), query, argumentCount, arguments); + return RJSResultsCreate(ctx, sharedRealm, results->get_object_schema(), std::move(results->get_query()), argumentCount, arguments); } catch (std::exception &exp) { if (jsException) { @@ -160,23 +158,22 @@ JSObjectRef RJSResultsCreate(JSContextRef ctx, SharedRealm realm, std::string cl return RJSWrapObject(ctx, RJSResultsClass(), new Results(realm, *object_schema, std::move(query))); } -JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, const realm::ObjectSchema &objectSchema, realm::Query &query, size_t argumentCount, const JSValueRef arguments[]) { +JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, const realm::ObjectSchema &objectSchema, realm::Query query, size_t argumentCount, const JSValueRef arguments[]) { std::string queryString = RJSValidatedStringForValue(ctx, arguments[0], "predicate"); - std::vector args(argumentCount-1); + std::vector args( argumentCount - 1 ); for (size_t i = 1; i < argumentCount; i++) { args[i-1] = arguments[i]; } parser::Predicate predicate = parser::parse(queryString); query_builder::ArgumentConverter queryArgs(ctx, args); - query_builder::apply_predicate(query, predicate, queryArgs, *realm->config().schema, - objectSchema.name); + query_builder::apply_predicate(query, predicate, queryArgs, *realm->config().schema, objectSchema.name); - return RJSResultsCreate(ctx, realm, objectSchema, query); + return RJSResultsCreate(ctx, realm, objectSchema, std::move(query)); } -JSObjectRef RJSResultsCreate(JSContextRef ctx, SharedRealm realm, const ObjectSchema &objectSchema, const Query &query, bool live) { - Results *results = new Results(realm, objectSchema, query); +JSObjectRef RJSResultsCreate(JSContextRef ctx, SharedRealm realm, const ObjectSchema &objectSchema, Query query, bool live) { + Results *results = new Results(realm, objectSchema, std::move(query)); results->set_live(live); return RJSWrapObject(ctx, RJSResultsClass(), results); diff --git a/src/js_results.hpp b/src/js_results.hpp index cc4f0a8e..61ef0d07 100644 --- a/src/js_results.hpp +++ b/src/js_results.hpp @@ -16,6 +16,6 @@ namespace realm { JSClassRef RJSResultsClass(); JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, std::string className); JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, std::string className, std::string query, std::vector args); -JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, const realm::ObjectSchema &objectSchema, realm::Query &query, size_t argumentCount, const JSValueRef arguments[]); -JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, const realm::ObjectSchema &objectSchema, const realm::Query &query, bool live = true); +JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, const realm::ObjectSchema &objectSchema, realm::Query query, size_t argumentCount, const JSValueRef arguments[]); +JSObjectRef RJSResultsCreate(JSContextRef ctx, realm::SharedRealm realm, const realm::ObjectSchema &objectSchema, realm::Query query, bool live = true);