Skip to content
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

MMKV.cpp std::move on a temporary object - Copy Elision #577

Open
arthurgeron opened this issue Sep 1, 2023 · 1 comment
Open

MMKV.cpp std::move on a temporary object - Copy Elision #577

arthurgeron opened this issue Sep 1, 2023 · 1 comment

Comments

@arthurgeron
Copy link

The following warning is generated during build:
gradle warning: warning: moving a temporary object prevents copy elision [-Wpessimizing-move]

This occurs in the generated MMKV.cpp on the bool MMKV::getBytes method, calls std::move on a temporary object, which causes the warning. This potentially causes efficiency issues.

The fix would be:

diff --git a/node_modules/react-native-mmkv/MMKV/Core/MMKV.cpp b/node_modules/react-native-mmkv/MMKV/Core/MMKV.cpp
index eb5b708..a81fe6f 100755
--- a/node_modules/react-native-mmkv/MMKV/Core/MMKV.cpp
+++ b/node_modules/react-native-mmkv/MMKV/Core/MMKV.cpp
@@ -701,7 +701,7 @@ bool MMKV::getBytes(MMKVKey_t key, mmkv::MMBuffer &result) {
     if (data.length() > 0) {
         try {
             CodedInputData input(data.getPtr(), data.length());
-            result = std::move(input.readData());
+            result = input.readData();
             return true;
         } catch (std::exception &exception) {
             MMKVError("%s", exception.what());

But since it's a generated file I'm not sure how/if it could be fixed in the source code.

@miiguelperes
Copy link

Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants