mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 23:04:29 +00:00
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) {
|
JSValueRef ListGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* jsException) {
|
||||||
try {
|
try {
|
||||||
// index subscripting
|
|
||||||
List *list = RJSGetInternal<List *>(object);
|
List *list = RJSGetInternal<List *>(object);
|
||||||
size_t size = list->size();
|
|
||||||
|
|
||||||
std::string indexStr = RJSStringForJSString(propertyName);
|
std::string indexStr = RJSStringForJSString(propertyName);
|
||||||
if (indexStr == "length") {
|
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))));
|
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) {
|
JSValueRef ResultsGetProperty(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* jsException) {
|
||||||
try {
|
try {
|
||||||
// index subscripting
|
|
||||||
Results *results = RJSGetInternal<Results *>(object);
|
Results *results = RJSGetInternal<Results *>(object);
|
||||||
size_t size = results->size();
|
|
||||||
|
|
||||||
std::string indexStr = RJSStringForJSString(propertyName);
|
std::string indexStr = RJSStringForJSString(propertyName);
|
||||||
if (indexStr == "length") {
|
if (indexStr == "length") {
|
||||||
return JSValueMakeNumber(ctx, size);
|
return JSValueMakeNumber(ctx, results->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto row = results->get(RJSValidatedPositiveIndex(indexStr));
|
auto row = results->get(RJSValidatedPositiveIndex(indexStr));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user