From 58ef90dc538653856bfecb4fb6ee39bd3668ef99 Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Fri, 8 Jan 2016 15:52:08 -0800 Subject: [PATCH] Only call size() when actually needed This would unfortunately result in adverse performance side effects because calling size() can be expensive. --- src/js_list.cpp | 5 +---- src/js_results.cpp | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/js_list.cpp b/src/js_list.cpp index 79b7291c..42ecdf2d 100644 --- a/src/js_list.cpp +++ b/src/js_list.cpp @@ -13,13 +13,10 @@ using namespace realm; JSValueRef ListGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* jsException) { try { - // index subscripting List *list = RJSGetInternal(object); - size_t size = list->size(); - std::string indexStr = RJSStringForJSString(propertyName); if (indexStr == "length") { - return JSValueMakeNumber(ctx, size); + return JSValueMakeNumber(ctx, list->size()); } return RJSObjectCreate(ctx, Object(list->realm(), list->get_object_schema(), list->get(RJSValidatedPositiveIndex(indexStr)))); diff --git a/src/js_results.cpp b/src/js_results.cpp index d69afb0c..f30b7aa1 100644 --- a/src/js_results.cpp +++ b/src/js_results.cpp @@ -13,13 +13,10 @@ using namespace realm; JSValueRef ResultsGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* jsException) { try { - // index subscripting Results *results = RJSGetInternal(object); - size_t size = results->size(); - std::string indexStr = RJSStringForJSString(propertyName); if (indexStr == "length") { - return JSValueMakeNumber(ctx, size); + return JSValueMakeNumber(ctx, results->size()); } auto row = results->get(RJSValidatedPositiveIndex(indexStr));