diff --git a/Android/MMKV/build.gradle b/Android/MMKV/build.gradle index 1343c61f..3d4589e0 100644 --- a/Android/MMKV/build.gradle +++ b/Android/MMKV/build.gradle @@ -8,7 +8,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.0' + classpath 'com.android.tools.build:gradle:3.2.1' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.1' classpath 'digital.wup:android-maven-publish:3.6.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" diff --git a/Android/MMKV/gradle.properties b/Android/MMKV/gradle.properties index 20e76bb1..58ee2ed4 100644 --- a/Android/MMKV/gradle.properties +++ b/Android/MMKV/gradle.properties @@ -12,6 +12,6 @@ org.gradle.jvmargs=-Xmx1536m # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -VERSION_NAME_PREFIX=1.0.11 +VERSION_NAME_PREFIX=1.0.12 #VERSION_NAME_SUFFIX=-SNAPSHOT VERSION_NAME_SUFFIX= \ No newline at end of file diff --git a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp index 939d2116..8cc72475 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp +++ b/Android/MMKV/mmkv/src/main/cpp/MMKV.cpp @@ -309,7 +309,8 @@ void MMKV::loadFromFile() { if (m_crypter) { decryptBuffer(*m_crypter, inputBuffer); } - m_dic = MiniPBCoder::decodeMap(inputBuffer); + m_dic.clear(); + MiniPBCoder::decodeMap(m_dic, inputBuffer); m_output = new CodedOutputData(m_ptr + Fixed32Size + m_actualSize, m_size - Fixed32Size - m_actualSize); loaded = true; @@ -358,7 +359,8 @@ void MMKV::loadFromAshmem() { if (m_crypter) { decryptBuffer(*m_crypter, inputBuffer); } - m_dic = MiniPBCoder::decodeMap(inputBuffer); + m_dic.clear(); + MiniPBCoder::decodeMap(m_dic, inputBuffer); m_output = new CodedOutputData(m_ptr + Fixed32Size + m_actualSize, m_size - Fixed32Size - m_actualSize); loaded = true; @@ -407,16 +409,7 @@ void MMKV::partialLoadFromFile() { if (m_crypter) { decryptBuffer(*m_crypter, inputBuffer); } - auto dic = MiniPBCoder::decodeMap(inputBuffer, bufferSize); - for (auto &itr : dic) { - //m_dic[itr.first] = std::move(itr.second); - auto target = m_dic.find(itr.first); - if (target == m_dic.end()) { - m_dic.emplace(itr.first, std::move(itr.second)); - } else { - target->second = std::move(itr.second); - } - } + MiniPBCoder::decodeMap(m_dic, inputBuffer, bufferSize); m_output->seek(bufferSize); MMKVDebug("partial loaded [%s] with %zu values", m_mmapID.c_str(), diff --git a/Android/MMKV/mmkv/src/main/cpp/MiniPBCoder.cpp b/Android/MMKV/mmkv/src/main/cpp/MiniPBCoder.cpp index 603260a2..d1544b41 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MiniPBCoder.cpp +++ b/Android/MMKV/mmkv/src/main/cpp/MiniPBCoder.cpp @@ -250,9 +250,7 @@ vector MiniPBCoder::decodeOneSet() { return v; } -unordered_map MiniPBCoder::decodeOneMap(size_t size) { - unordered_map dic; - +void MiniPBCoder::decodeOneMap(unordered_map &dic, size_t size) { if (size == 0) { auto length = m_inputData->readInt32(); } @@ -267,7 +265,6 @@ unordered_map MiniPBCoder::decodeOneMap(size_t size) { } } } - return dic; } string MiniPBCoder::decodeString(const MMBuffer &oData) { @@ -280,9 +277,11 @@ MMBuffer MiniPBCoder::decodeBytes(const MMBuffer &oData) { return oCoder.decodeOneBytes(); } -unordered_map MiniPBCoder::decodeMap(const MMBuffer &oData, size_t size) { +void MiniPBCoder::decodeMap(unordered_map &dic, + const MMBuffer &oData, + size_t size) { MiniPBCoder oCoder(&oData); - return oCoder.decodeOneMap(size); + oCoder.decodeOneMap(dic, size); } vector MiniPBCoder::decodeSet(const MMBuffer &oData) { diff --git a/Android/MMKV/mmkv/src/main/cpp/MiniPBCoder.h b/Android/MMKV/mmkv/src/main/cpp/MiniPBCoder.h index fd997ff4..d7706346 100644 --- a/Android/MMKV/mmkv/src/main/cpp/MiniPBCoder.h +++ b/Android/MMKV/mmkv/src/main/cpp/MiniPBCoder.h @@ -59,7 +59,7 @@ class MiniPBCoder { std::string decodeOneString(); MMBuffer decodeOneBytes(); std::vector decodeOneSet(); - std::unordered_map decodeOneMap(size_t size = 0); + void decodeOneMap(std::unordered_map &dic, size_t size = 0); public: template @@ -71,8 +71,9 @@ class MiniPBCoder { static std::string decodeString(const MMBuffer &oData); static MMBuffer decodeBytes(const MMBuffer &oData); static std::vector decodeSet(const MMBuffer &oData); - static std::unordered_map decodeMap(const MMBuffer &oData, - size_t size = 0); + static void decodeMap(std::unordered_map &dic, + const MMBuffer &oData, + size_t size = 0); }; #endif //MMKV_MINIPBCODER_H diff --git a/Android/MMKV/mmkvdemo/build.gradle b/Android/MMKV/mmkvdemo/build.gradle index 484e7465..37b4630c 100644 --- a/Android/MMKV/mmkvdemo/build.gradle +++ b/Android/MMKV/mmkvdemo/build.gradle @@ -55,7 +55,7 @@ repositories { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') // implementation project(':mmkv') - implementation 'com.tencent:mmkv:1.0.11' + implementation 'com.tencent:mmkv:1.0.12' // implementation 'com.tencent:mmkv:1.0.10-SNAPSHOT' implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' diff --git a/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/BenchMarkBaseService.java b/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/BenchMarkBaseService.java index d2cce35b..356bca8e 100644 --- a/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/BenchMarkBaseService.java +++ b/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/BenchMarkBaseService.java @@ -49,7 +49,7 @@ public abstract class BenchMarkBaseService extends Service { private String[] m_arrIntKeys; private static final int m_loops = 1000; - private static final String MMKV_ID = "benchmark_interprocess"; + public static final String MMKV_ID = "benchmark_interprocess"; private static final String SP_ID = "benchmark_interprocess_sp"; private static final String CryptKey = null; //private static final String CryptKey = "Tencent MMKV"; @@ -296,7 +296,7 @@ private void spBatchReadStrinfg(String caller) { MMKV m_ashmemMMKV; - private MMKV GetMMKV() { + protected MMKV GetMMKV() { if (m_ashmemMMKV != null) { return m_ashmemMMKV; } else { diff --git a/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java b/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java index 0f8315d3..7822bffc 100644 --- a/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java +++ b/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MainActivity.java @@ -22,8 +22,10 @@ import android.content.Intent; import android.content.SharedPreferences; +import android.os.SystemClock; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; @@ -100,7 +102,7 @@ public void onClick(View v) { KotlinUsecaseKt.kotlinFunctionalTest(); - //testInterProcessLock(); + //testInterProcessLogic(); //estImportSharedPreferences(); } @@ -110,9 +112,18 @@ protected void onDestroy() { MMKV.onExit(); } - private void testInterProcessLock() { + private void testInterProcessLogic() { + MMKV mmkv = MMKV.mmkvWithID(MyService.MMKV_ID, MMKV.MULTI_PROCESS_MODE); + mmkv.putInt(MyService.CMD_ID, 1024); + Log.d("mmkv in main", "" + mmkv.decodeInt(MyService.CMD_ID)); + Intent intent = new Intent(this, MyService.class); + intent.putExtra(BenchMarkBaseService.CMD_ID, MyService.CMD_REMOVE); startService(intent); + + SystemClock.sleep(1000 * 3); + int value = mmkv.decodeInt(MyService.CMD_ID); + Log.d("mmkv", "" + value); } private void testMMKV(String mmapID, String cryptKey, boolean decodeOnly) { diff --git a/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MyService.java b/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MyService.java index f1b0bbe6..7426b9e9 100644 --- a/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MyService.java +++ b/Android/MMKV/mmkvdemo/src/main/java/com/tencent/mmkvdemo/MyService.java @@ -21,9 +21,13 @@ package com.tencent.mmkvdemo; import android.content.Intent; +import android.util.Log; + +import com.tencent.mmkv.MMKV; public class MyService extends BenchMarkBaseService { private static final String CALLER = "MyService"; + public static final String CMD_REMOVE = "cmd_remove"; @Override public void onCreate() { @@ -53,9 +57,17 @@ public int onStartCommand(Intent intent, int flags, int startId) { super.batchWriteString(CALLER); } else if (cmd.equals(CMD_PREPARE_ASHMEM_BY_CP)) { super.prepareAshmemMMKVByCP(); + } else if (cmd.equals(CMD_REMOVE)) { + testRemove(); } } } return super.onStartCommand(intent, flags, startId); } + + private void testRemove() { + MMKV mmkv = GetMMKV(); + Log.d("mmkv in child", "" + mmkv.decodeInt(CMD_ID)); + mmkv.remove(CMD_ID); + } } diff --git a/readme.md b/readme.md index 89b9beb8..90f38dbe 100644 --- a/readme.md +++ b/readme.md @@ -75,8 +75,8 @@ Add the following lines to `build.gradle` on your app module: ```gradle dependencies { - implementation 'com.tencent:mmkv:1.0.11' - // replace "1.0.11" with any available version + implementation 'com.tencent:mmkv:1.0.12' + // replace "1.0.12" with any available version } ``` diff --git a/readme_cn.md b/readme_cn.md index ad6ac303..791bcbf6 100644 --- a/readme_cn.md +++ b/readme_cn.md @@ -59,8 +59,8 @@ NSString *str = [mmkv getObjectOfClass:NSString.class forKey:@"string"]; ```gradle dependencies { - implementation 'com.tencent:mmkv:1.0.11' - // replace "1.0.11" with any available version + implementation 'com.tencent:mmkv:1.0.12' + // replace "1.0.12" with any available version } ``` @@ -112,4 +112,4 @@ MMKV 以 BSD 3-Clause 证书开源,详情参见 [LICENSE.TXT](https://github.c ## 参与贡献 如果你有兴趣参与贡献,可以参考 [CONTRIBUTING.md](https://github.com/Tencent/MMKV/blob/master/CONTRIBUTING.md)。 [腾讯开源激励计划](https://opensource.tencent.com/contribution) 鼓励开发者的参与和贡献,期待你的加入。 ## 问题 & 反馈 -常见问题参见 [FAQ](https://github.com/Tencent/MMKV/wiki/FAQ_cn),欢迎提 [issues](https://github.com/Tencent/MMKV/issues) 提问反馈。 \ No newline at end of file +常见问题参见 [FAQ](https://github.com/Tencent/MMKV/wiki/FAQ_cn),欢迎提 [issues](https://github.com/Tencent/MMKV/issues) 提问反馈。