react-native-mmkv icon indicating copy to clipboard operation
react-native-mmkv copied to clipboard

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

Open arthurgeron opened this issue 2 years ago • 1 comments

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.

arthurgeron avatar Sep 01 '23 01:09 arthurgeron

Any updates?

miiguelperes avatar Jan 12 '24 20:01 miiguelperes

This is a warning. And can be ignored.

mrousavy avatar Jul 22 '24 15:07 mrousavy