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:
parent
a0145df5e4
commit
58ef90dc53
|
@ -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))));
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue