-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass callback and user data by value in realm_mongo_collection_<func> #6307
Conversation
@@ -948,7 +948,7 @@ RLM_API bool realm_mongo_collection_find(realm_mongodb_collection_t* collection, | |||
return wrap_err([&] { | |||
collection->find_bson(convert_to_bson<bson::BsonDocument>(filter_ejson), | |||
to_mongodb_collection_find_options(options), | |||
[&](util::Optional<bson::Bson> bson, util::Optional<AppError> app_error) { | |||
[=](util::Optional<bson::Bson> bson, util::Optional<AppError> app_error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only a minimal thing, I think the only thing you need to capture by copy is the callback
, the rest of the data can be passed by reference. Although in 99% of the case, we are copying a ptr
(thus equivalent to passing the arguments by reference), for realm_string_t filter_ejson
we will be copying sizeof(ptr) + sizeof(size_t)
bytes.
Not a big issue, since the amount of data copied will always be constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to pass by value data
, delete_data
and callback
. Otherwise when I receive the callback I can't access the data
object. I can change it to [data, delete_data, callback]
instead of [=]
, if you say that it is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes the C-API functions like
realm_mongo_collection_find
,realm_mongo_collection_find_one
and so on.The callback can not be found if its pointer is passed by reference.
It was not handled because the tests in
realm-core
don't call these methods with passing callbacks as arguments.Related to the implementation in realm/realm-dart#1162
What, How & Why?
☑️ ToDos
[ ] 📝 Changelog update[ ] 🚦 Tests (or not relevant)[ ] C-API, if public C++ API changed.