Skip to content

Commit

Permalink
Merge pull request #1066 from Tencent/dev
Browse files Browse the repository at this point in the history
for v1.2.16
  • Loading branch information
lingol authored Apr 20, 2023
2 parents c09632c + 5572507 commit dfb44db
Show file tree
Hide file tree
Showing 39 changed files with 477 additions and 434 deletions.
2 changes: 1 addition & 1 deletion Android/MMKV/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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.2.15
VERSION_NAME_PREFIX=1.2.16
#VERSION_NAME_SUFFIX=-SNAPSHOT
VERSION_NAME_SUFFIX=

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ public boolean onCreate() {
if (context == null) {
return false;
}
String authority = queryAuthority(context);
if (authority == null) {
return false;
}

if (MMKVContentProvider.gUri == null) {
MMKVContentProvider.gUri = Uri.parse(ContentResolver.SCHEME_CONTENT + "://" + authority);
}

return true;
}
Expand Down
6 changes: 3 additions & 3 deletions Android/MMKV/mmkvdemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ repositories {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':mmkv')
// implementation 'com.tencent:mmkv:1.2.15'
// implementation 'com.tencent:mmkv-static:1.2.15' // this is identical to 'com.tencent:mmkv'
// implementation 'com.tencent:mmkv-shared:1.2.15'
// implementation 'com.tencent:mmkv:1.2.16'
// implementation 'com.tencent:mmkv-static:1.2.16' // this is identical to 'com.tencent:mmkv'
// implementation 'com.tencent:mmkv-shared:1.2.16'
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ private void mmkvBatchDeleteString() {
public void sharedPreferencesBaselineTest() {
spBatchWriteInt();
spBatchReadInt();
spBatchWrieString();
spBatchReadStrinfg();
spBatchWriteString();
spBatchReadString();
}

private void spBatchWriteInt() {
Expand Down Expand Up @@ -181,7 +181,7 @@ private void spBatchReadInt() {
Log.i(TAG, "SharedPreferences read int: loop[" + m_loops + "]: " + m_formatter.format(endTime) + " ms");
}

private void spBatchWrieString() {
private void spBatchWriteString() {
long startTime = System.nanoTime();

SharedPreferences preferences = m_context.getSharedPreferences(MMKV_ID, MODE_PRIVATE);
Expand All @@ -197,7 +197,7 @@ private void spBatchWrieString() {
Log.i(TAG, "SharedPreferences write String: loop[" + m_loops + "]: " + m_formatter.format(endTime) + " ms");
}

private void spBatchReadStrinfg() {
private void spBatchReadString() {
long startTime = System.nanoTime();

SharedPreferences preferences = m_context.getSharedPreferences(MMKV_ID, MODE_PRIVATE);
Expand All @@ -220,17 +220,17 @@ private void sqliteWriteInt(boolean useTransaction) {
Random r = new Random();
long startTime = System.nanoTime();

SQLIteKV sqlIteKV = new SQLIteKV(m_context);
SQLiteKV sqliteKV = new SQLiteKV(m_context);
if (useTransaction) {
sqlIteKV.beginTransaction();
sqliteKV.beginTransaction();
}
for (int index = 0; index < m_loops; index++) {
int tmp = r.nextInt();
String key = m_arrIntKeys[index];
sqlIteKV.putInt(key, tmp);
sqliteKV.putInt(key, tmp);
}
if (useTransaction) {
sqlIteKV.endTransaction();
sqliteKV.endTransaction();
}
double endTime = (System.nanoTime() - startTime) / 1000000.0;
final String msg = useTransaction ? "sqlite transaction" : "sqlite";
Expand All @@ -240,16 +240,16 @@ private void sqliteWriteInt(boolean useTransaction) {
private void sqliteReadInt(boolean useTransaction) {
long startTime = System.nanoTime();

SQLIteKV sqlIteKV = new SQLIteKV(m_context);
SQLiteKV sqliteKV = new SQLiteKV(m_context);
if (useTransaction) {
sqlIteKV.beginTransaction();
sqliteKV.beginTransaction();
}
for (int index = 0; index < m_loops; index++) {
String key = m_arrIntKeys[index];
int tmp = sqlIteKV.getInt(key);
int tmp = sqliteKV.getInt(key);
}
if (useTransaction) {
sqlIteKV.endTransaction();
sqliteKV.endTransaction();
}
double endTime = (System.nanoTime() - startTime) / 1000000.0;
final String msg = useTransaction ? "sqlite transaction" : "sqlite";
Expand All @@ -259,17 +259,17 @@ private void sqliteReadInt(boolean useTransaction) {
private void sqliteWriteString(boolean useTransaction) {
long startTime = System.nanoTime();

SQLIteKV sqlIteKV = new SQLIteKV(m_context);
SQLiteKV sqliteKV = new SQLiteKV(m_context);
if (useTransaction) {
sqlIteKV.beginTransaction();
sqliteKV.beginTransaction();
}
for (int index = 0; index < m_loops; index++) {
final String value = m_arrStrings[index];
final String key = m_arrKeys[index];
sqlIteKV.putString(key, value);
sqliteKV.putString(key, value);
}
if (useTransaction) {
sqlIteKV.endTransaction();
sqliteKV.endTransaction();
}
double endTime = (System.nanoTime() - startTime) / 1000000.0;
final String msg = useTransaction ? "sqlite transaction" : "sqlite";
Expand All @@ -279,16 +279,16 @@ private void sqliteWriteString(boolean useTransaction) {
private void sqliteReadString(boolean useTransaction) {
long startTime = System.nanoTime();

SQLIteKV sqlIteKV = new SQLIteKV(m_context);
SQLiteKV sqliteKV = new SQLiteKV(m_context);
if (useTransaction) {
sqlIteKV.beginTransaction();
sqliteKV.beginTransaction();
}
for (int index = 0; index < m_loops; index++) {
final String key = m_arrKeys[index];
final String tmp = sqlIteKV.getString(key);
final String tmp = sqliteKV.getString(key);
}
if (useTransaction) {
sqlIteKV.endTransaction();
sqliteKV.endTransaction();
}
double endTime = (System.nanoTime() - startTime) / 1000000.0;
final String msg = useTransaction ? "sqlite transaction" : "sqlite";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import android.util.Log;
import androidx.annotation.Nullable;
import com.tencent.mmkv.MMKV;
import com.tencent.mmkv.MMKVLogLevel;
import com.tencent.mmkv.ParcelableMMKV;
import java.util.Random;

Expand Down Expand Up @@ -121,17 +120,17 @@ private void sqliteWriteInt(String caller, boolean useTransaction) {
Random r = new Random();
long startTime = System.currentTimeMillis();

SQLIteKV sqlIteKV = new SQLIteKV(this);
SQLiteKV sqliteKV = new SQLiteKV(this);
if (useTransaction) {
sqlIteKV.beginTransaction();
sqliteKV.beginTransaction();
}
for (int index = 0; index < m_loops; index++) {
int tmp = r.nextInt();
String key = m_arrIntKeys[index];
sqlIteKV.putInt(key, tmp);
sqliteKV.putInt(key, tmp);
}
if (useTransaction) {
sqlIteKV.endTransaction();
sqliteKV.endTransaction();
}
long endTime = System.currentTimeMillis();
final String msg = useTransaction ? " sqlite transaction " : " sqlite ";
Expand Down Expand Up @@ -178,16 +177,16 @@ private void mmkvBatchReadInt(String caller) {
private void sqliteReadInt(String caller, boolean useTransaction) {
long startTime = System.currentTimeMillis();

SQLIteKV sqlIteKV = new SQLIteKV(this);
SQLiteKV sqliteKV = new SQLiteKV(this);
if (useTransaction) {
sqlIteKV.beginTransaction();
sqliteKV.beginTransaction();
}
for (int index = 0; index < m_loops; index++) {
String key = m_arrIntKeys[index];
int tmp = sqlIteKV.getInt(key);
int tmp = sqliteKV.getInt(key);
}
if (useTransaction) {
sqlIteKV.endTransaction();
sqliteKV.endTransaction();
}
long endTime = System.currentTimeMillis();
final String msg = useTransaction ? " sqlite transaction " : " sqlite ";
Expand Down Expand Up @@ -230,17 +229,17 @@ private void mmkvBatchWriteString(String caller) {
private void sqliteWriteString(String caller, boolean useTransaction) {
long startTime = System.currentTimeMillis();

SQLIteKV sqlIteKV = new SQLIteKV(this);
SQLiteKV sqliteKV = new SQLiteKV(this);
if (useTransaction) {
sqlIteKV.beginTransaction();
sqliteKV.beginTransaction();
}
for (int index = 0; index < m_loops; index++) {
final String value = m_arrStrings[index];
final String key = m_arrKeys[index];
sqlIteKV.putString(key, value);
sqliteKV.putString(key, value);
}
if (useTransaction) {
sqlIteKV.endTransaction();
sqliteKV.endTransaction();
}
long endTime = System.currentTimeMillis();
final String msg = useTransaction ? " sqlite transaction " : " sqlite ";
Expand Down Expand Up @@ -286,16 +285,16 @@ private void mmkvBatchReadString(String caller) {
private void sqliteReadString(String caller, boolean useTransaction) {
long startTime = System.currentTimeMillis();

SQLIteKV sqlIteKV = new SQLIteKV(this);
SQLiteKV sqliteKV = new SQLiteKV(this);
if (useTransaction) {
sqlIteKV.beginTransaction();
sqliteKV.beginTransaction();
}
for (int index = 0; index < m_loops; index++) {
final String key = m_arrKeys[index];
final String tmp = sqlIteKV.getString(key);
final String tmp = sqliteKV.getString(key);
}
if (useTransaction) {
sqlIteKV.endTransaction();
sqliteKV.endTransaction();
}
long endTime = System.currentTimeMillis();
final String msg = useTransaction ? " sqlite transaction " : " sqlite ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public final class SQLIteKV {
private static class SQLIteKVDBHelper extends SQLiteOpenHelper {
public final class SQLiteKV {
private static class SQLiteKVDBHelper extends SQLiteOpenHelper {
private static final int DB_VERSION = 1;
private static final String DB_NAME = "kv.db";
public static final String TABLE_NAME_STR = "kv_str";
public static final String TABLE_NAME_INT = "kv_int";

public SQLIteKVDBHelper(Context context) {
public SQLiteKVDBHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}

Expand All @@ -55,12 +55,12 @@ public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVers
onCreate(sqLiteDatabase);
}
}
private SQLIteKVDBHelper m_dbHelper;
private SQLiteKVDBHelper m_dbHelper;
private SQLiteDatabase m_writetableDB;
private SQLiteDatabase m_readableDB;

public SQLIteKV(Context context) {
m_dbHelper = new SQLIteKVDBHelper(context);
public SQLiteKV(Context context) {
m_dbHelper = new SQLiteKVDBHelper(context);
m_dbHelper.setWriteAheadLoggingEnabled(true);
}

Expand Down Expand Up @@ -107,14 +107,14 @@ public boolean putInt(String key, int value) {
ContentValues contentValues = new ContentValues();
contentValues.put("k", key);
contentValues.put("v", value);
long rowID = getWritetableDB().insert(SQLIteKVDBHelper.TABLE_NAME_INT, null, contentValues);
long rowID = getWritetableDB().insert(SQLiteKVDBHelper.TABLE_NAME_INT, null, contentValues);
return rowID != -1;
}

public int getInt(String key) {
int value = 0;
Cursor cursor = getReadableDatabase().rawQuery(
"select v from " + SQLIteKVDBHelper.TABLE_NAME_INT + " where k=?", new String[] {key});
"select v from " + SQLiteKVDBHelper.TABLE_NAME_INT + " where k=?", new String[] {key});
if (cursor.moveToFirst()) {
value = cursor.getInt(cursor.getColumnIndex("v"));
}
Expand All @@ -126,14 +126,14 @@ public boolean putString(String key, String value) {
ContentValues contentValues = new ContentValues();
contentValues.put("k", key);
contentValues.put("v", value);
long rowID = getWritetableDB().insert(SQLIteKVDBHelper.TABLE_NAME_STR, null, contentValues);
long rowID = getWritetableDB().insert(SQLiteKVDBHelper.TABLE_NAME_STR, null, contentValues);
return rowID != -1;
}

public String getString(String key) {
String value = null;
Cursor cursor = getReadableDatabase().rawQuery(
"select v from " + SQLIteKVDBHelper.TABLE_NAME_STR + " where k=?", new String[] {key});
"select v from " + SQLiteKVDBHelper.TABLE_NAME_STR + " where k=?", new String[] {key});
if (cursor.moveToFirst()) {
value = cursor.getString(cursor.getColumnIndex("v"));
}
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# MMKV Change Log

## v1.2.16 / 2023-04-20
### Changes for All platforms
* Optimization: The actual file content is lazy loaded now, saving time on MMKV instance creation, and avoiding lock waiting when a lot of instances are created at the same time.
* Fix a bug when restoring a loaded MMKV instance the meta file might mistakenly report corrupted.

### Android
* Optimization: Remove unnecessary binder call on main process instantiation.

### Flutter
* Fix a crash on decoding an empty list.
* Remove deprecated dependence.
* Make the script more robust to fix the iOS Flutter plugin name.

### Win32
* Fix a string format bug on the MinGW64 environment.

### golang
* Fix a build error on 32-bit OS.

## v1.2.15 / 2023-01-12
### Changes for All platforms
* Log handler now handles all logs from the very beginning, especially the logs in initialization.
Expand All @@ -13,6 +32,7 @@
* Fix a compile error on macOS.
* Fix a bug that some ObjC exceptions are not being caught.
* Add assert on nil MMKV base path, protect from mis-using MMKV in global variable initialization.
* Starting from v1.2.15, one must call `+[MMKV initializeMMKV:]` manually before calling any MMKV methods.

### golang
* Fix a compile error on GCC.
Expand Down
Loading

0 comments on commit dfb44db

Please sign in to comment.