You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ac...@apache.org on 2018/02/26 07:44:11 UTC

incubator-weex git commit: * [iOS] override allKeys and allValues method for safeDictionary

Repository: incubator-weex
Updated Branches:
  refs/heads/master 477e9a8ab -> 0e74f4f94


* [iOS] override allKeys and allValues method for safeDictionary


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

Branch: refs/heads/master
Commit: 0e74f4f94bb5d253342a02af4892eaf58258edc6
Parents: 477e9a8
Author: acton393 <zh...@gmail.com>
Authored: Mon Feb 26 15:43:34 2018 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Mon Feb 26 15:43:34 2018 +0800

----------------------------------------------------------------------
 .../Utility/WXThreadSafeMutableDictionary.m     | 42 ++++++++++++++++++++
 1 file changed, 42 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/0e74f4f9/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m b/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m
index 21da6a0..ae04bb0 100644
--- a/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m
+++ b/ios/sdk/WeexSDK/Sources/Utility/WXThreadSafeMutableDictionary.m
@@ -34,6 +34,34 @@
 
 @end
 
+#define OVERRIDE_METHOD(method,retValue) \
+do { \
+    _Pragma("clang diagnostic push") \
+    _Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
+    if (![WXUtility threadSafeCollectionUsingLock]) {\
+        dispatch_sync(_queue, ^{\
+            if ([_dict respondsToSelector:method]) {\
+            retValue = [_dict performSelector:method];\
+            }\
+        });\
+    } else {\
+        if (WX_SYS_VERSION_GREATER_THAN(@"10.0")) {\
+            os_unfair_lock_lock(&_unfairLock);\
+            if ([_dict respondsToSelector:method]) {\
+                retValue = [_dict performSelector:method];\
+            }\
+            os_unfair_lock_unlock(&_unfairLock);\
+        } else {\
+            pthread_mutex_lock(&_safeThreadDictionaryMutex);\
+            if ([_dict respondsToSelector:method]) {\
+                retValue = [_dict performSelector:method];\
+            }\
+            pthread_mutex_unlock(&_safeThreadDictionaryMutex);\
+        }\
+    }\
+    _Pragma("clang diagnostic pop")\
+} while (0)
+
 @implementation WXThreadSafeMutableDictionary
 
 - (instancetype)initCommon
@@ -187,6 +215,20 @@
     }
 }
 
+- (NSArray *)allKeys
+{
+    __block NSArray *allKeys = nil;
+    OVERRIDE_METHOD(_cmd, allKeys);
+    return allKeys;
+}
+
+- (NSArray *)allValues
+{
+    __block NSArray *allValues = nil;
+    OVERRIDE_METHOD(_cmd, allValues);
+    return allValues;
+}
+
 - (void)removeObjectForKey:(id)aKey
 {
     if (![WXUtility threadSafeCollectionUsingLock]) {