Only call size() when actually needed

This would unfortunately result in adverse performance side effects because calling size() can be expensive.
This commit is contained in:
Scott Kyle 2016-01-08 15:52:08 -08:00
parent a0145df5e4
commit 58ef90dc53
2 changed files with 2 additions and 8 deletions

View File

@ -13,13 +13,10 @@ using namespace realm;
JSValueRef ListGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* jsException) {
try {
// index subscripting
List *list = RJSGetInternal<List *>(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))));

View File

@ -13,13 +13,10 @@ using namespace realm;
JSValueRef ResultsGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* jsException) {
try {
// index subscripting
Results *results = RJSGetInternal<Results *>(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));