Skip to content

Commit

Permalink
Merge pull request #93 from Tencent/hotfix_android_1.0.12
Browse files Browse the repository at this point in the history
Hotfix android 1.0.12
  • Loading branch information
lingol authored Oct 24, 2018
2 parents ad2f90e + 70494c9 commit 9931600
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Android/MMKV/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Android/MMKV/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=
17 changes: 5 additions & 12 deletions Android/MMKV/mmkv/src/main/cpp/MMKV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down
11 changes: 5 additions & 6 deletions Android/MMKV/mmkv/src/main/cpp/MiniPBCoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,7 @@ vector<string> MiniPBCoder::decodeOneSet() {
return v;
}

unordered_map<string, MMBuffer> MiniPBCoder::decodeOneMap(size_t size) {
unordered_map<string, MMBuffer> dic;

void MiniPBCoder::decodeOneMap(unordered_map<string, MMBuffer> &dic, size_t size) {
if (size == 0) {
auto length = m_inputData->readInt32();
}
Expand All @@ -267,7 +265,6 @@ unordered_map<string, MMBuffer> MiniPBCoder::decodeOneMap(size_t size) {
}
}
}
return dic;
}

string MiniPBCoder::decodeString(const MMBuffer &oData) {
Expand All @@ -280,9 +277,11 @@ MMBuffer MiniPBCoder::decodeBytes(const MMBuffer &oData) {
return oCoder.decodeOneBytes();
}

unordered_map<string, MMBuffer> MiniPBCoder::decodeMap(const MMBuffer &oData, size_t size) {
void MiniPBCoder::decodeMap(unordered_map<string, MMBuffer> &dic,
const MMBuffer &oData,
size_t size) {
MiniPBCoder oCoder(&oData);
return oCoder.decodeOneMap(size);
oCoder.decodeOneMap(dic, size);
}

vector<string> MiniPBCoder::decodeSet(const MMBuffer &oData) {
Expand Down
7 changes: 4 additions & 3 deletions Android/MMKV/mmkv/src/main/cpp/MiniPBCoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MiniPBCoder {
std::string decodeOneString();
MMBuffer decodeOneBytes();
std::vector<std::string> decodeOneSet();
std::unordered_map<std::string, MMBuffer> decodeOneMap(size_t size = 0);
void decodeOneMap(std::unordered_map<std::string, MMBuffer> &dic, size_t size = 0);

public:
template <typename T>
Expand All @@ -71,8 +71,9 @@ class MiniPBCoder {
static std::string decodeString(const MMBuffer &oData);
static MMBuffer decodeBytes(const MMBuffer &oData);
static std::vector<std::string> decodeSet(const MMBuffer &oData);
static std::unordered_map<std::string, MMBuffer> decodeMap(const MMBuffer &oData,
size_t size = 0);
static void decodeMap(std::unordered_map<std::string, MMBuffer> &dic,
const MMBuffer &oData,
size_t size = 0);
};

#endif //MMKV_MINIPBCODER_H
2 changes: 1 addition & 1 deletion Android/MMKV/mmkvdemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,7 +102,7 @@ public void onClick(View v) {

KotlinUsecaseKt.kotlinFunctionalTest();

//testInterProcessLock();
//testInterProcessLogic();
//estImportSharedPreferences();
}

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand Down
6 changes: 3 additions & 3 deletions readme_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
```

Expand Down Expand Up @@ -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) 提问反馈。
常见问题参见 [FAQ](https://github.com/Tencent/MMKV/wiki/FAQ_cn),欢迎提 [issues](https://github.com/Tencent/MMKV/issues) 提问反馈。
Expand Down

0 comments on commit 9931600

Please sign in to comment.