You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ky...@apache.org on 2018/05/26 13:33:10 UTC

incubator-weex git commit: * Fix string cache problem

Repository: incubator-weex
Updated Branches:
  refs/heads/master 8838d6c2a -> ad1d9b4f9


* Fix string cache problem


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/ad1d9b4f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/ad1d9b4f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/ad1d9b4f

Branch: refs/heads/master
Commit: ad1d9b4f9ab4f476f07451f956cc5d8fad4c8ae4
Parents: 8838d6c
Author: YorkShen <sh...@gmail.com>
Authored: Sat May 26 21:32:43 2018 +0800
Committer: YorkShen <sh...@gmail.com>
Committed: Sat May 26 21:32:43 2018 +0800

----------------------------------------------------------------------
 android/sdk/libs/armeabi/libweexcore.so         | Bin 640884 -> 644980 bytes
 .../android/base/string/jstring_cache.cpp       |  13 ++++++++-----
 .../Source/android/base/string/jstring_cache.h  |   2 +-
 3 files changed, 9 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/ad1d9b4f/android/sdk/libs/armeabi/libweexcore.so
----------------------------------------------------------------------
diff --git a/android/sdk/libs/armeabi/libweexcore.so b/android/sdk/libs/armeabi/libweexcore.so
index 936a639..cb2c4b0 100644
Binary files a/android/sdk/libs/armeabi/libweexcore.so and b/android/sdk/libs/armeabi/libweexcore.so differ

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/ad1d9b4f/weex_core/Source/android/base/string/jstring_cache.cpp
----------------------------------------------------------------------
diff --git a/weex_core/Source/android/base/string/jstring_cache.cpp b/weex_core/Source/android/base/string/jstring_cache.cpp
index 13044f4..009997e 100644
--- a/weex_core/Source/android/base/string/jstring_cache.cpp
+++ b/weex_core/Source/android/base/string/jstring_cache.cpp
@@ -33,11 +33,12 @@ void JStringCache::clearRefCache(JNIEnv *env) {
     cacheList.clear();
 }
 
-void JStringCache::put(std::string key, jobject value) {
+void JStringCache::put(JNIEnv *env, std::string key, jobject value) {
 //    LOGD("Remove cache jstring_cache key: %s, find: %s, max: %s", key.c_str(), posMap.find(key) != posMap.end() ? "TRUE" : "FALSE", cacheList.size() >= capacity ? "TRUE" : "FALSE");
     if (posMap.find(key) != posMap.end()) {
         cacheList.erase(posMap[key]);
     } else if (cacheList.size() >= capacity) {
+        env->DeleteWeakGlobalRef(cacheList.back().second);
         posMap.erase(cacheList.back().first);
         cacheList.pop_back();
     }
@@ -51,19 +52,21 @@ jstring JStringCache::GetString(JNIEnv *env, std::string key) {
         jobject obj = posMap[key]->second;
         if (env->IsSameObject(obj, NULL) == JNI_FALSE) {
             // JObject is still active
-            put(key, obj);
+            put(env, key, obj);
 //            LOGE("FOUND cache jstring_cache GetString key: %s,for cache key: %s", key.c_str(), env->GetStringUTFChars((jstring) obj, JNI_FALSE));
             return (jstring) posMap[key]->second;
         }
-        if (env->IsSameObject(obj, NULL) == JNI_TRUE) {
+        else if (env->IsSameObject(obj, NULL) == JNI_TRUE) {
             // Should delete WeakGlobalRef.
 //            LOGD("delete WeakGlobalRef: key: %s", key.c_str());
-            env->DeleteWeakGlobalRef(obj);
+          cacheList.erase(posMap[key]);
+          posMap.erase(key);
+          env->DeleteWeakGlobalRef(obj);
         }
     }
     const jstring jRef = env->NewStringUTF(key.c_str());
     const jobject jGlobalRef = env->NewWeakGlobalRef(jRef);
-    put(key, jGlobalRef);
+    put(env, key, jGlobalRef);
     env->DeleteLocalRef(jRef);
     return (jstring) jGlobalRef;
 }

http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/ad1d9b4f/weex_core/Source/android/base/string/jstring_cache.h
----------------------------------------------------------------------
diff --git a/weex_core/Source/android/base/string/jstring_cache.h b/weex_core/Source/android/base/string/jstring_cache.h
index f279a99..74f0bed 100644
--- a/weex_core/Source/android/base/string/jstring_cache.h
+++ b/weex_core/Source/android/base/string/jstring_cache.h
@@ -40,7 +40,7 @@ public:
     void clearRefCache(JNIEnv *env);
 
 private:
-    void put(std::string key, jobject value);
+    void put(JNIEnv *env, std::string key, jobject value);
 };
 
 #endif