From 331c815490688e80a3a5fa0f1c28a271f857df71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=E4=BA=86=E4=B8=AAJ?= <199109106@qq.com> Date: Mon, 4 Nov 2019 12:06:08 +0800 Subject: [PATCH] Adjust lock --- CHANGELOG.md | 1 + Sources/KakaJSON/Metadata/Metadata.swift | 8 +++----- Sources/KakaJSON/Metadata/Type/ModelType.swift | 4 ---- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 640079a..eb04556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ --- ## [1.1.1](https://github.com/kakaopensource/KakaJSON/releases/tag/1.1.1) (2019-11-04) +- Adjust Lock - Closed issues - [iOS 9 Crash](https://github.com/kakaopensource/KakaJSON/issues/31) - Merged pull requests diff --git a/Sources/KakaJSON/Metadata/Metadata.swift b/Sources/KakaJSON/Metadata/Metadata.swift index 71acd95..6555a4b 100644 --- a/Sources/KakaJSON/Metadata/Metadata.swift +++ b/Sources/KakaJSON/Metadata/Metadata.swift @@ -13,6 +13,9 @@ public struct Metadata { private static var types = [TypeKey: BaseType]() public static func type(_ type: Any.Type) -> BaseType? { + typeLock.lock() + defer { typeLock.unlock() } + // get from cache let key = typeKey(type) if let mt = types[key] { return mt } @@ -23,11 +26,6 @@ public struct Metadata { || name == "NSObject" || name == "_TtCs12_SwiftObject" { return nil } - typeLock.lock() - defer { typeLock.unlock() } - // judge after lock - if let mt = types[key] { return mt } - // type judge var mtt: BaseType.Type let kind = Kind(type) diff --git a/Sources/KakaJSON/Metadata/Type/ModelType.swift b/Sources/KakaJSON/Metadata/Type/ModelType.swift index c428015..e07064c 100644 --- a/Sources/KakaJSON/Metadata/Type/ModelType.swift +++ b/Sources/KakaJSON/Metadata/Type/ModelType.swift @@ -18,8 +18,6 @@ public class ModelType: BaseType { func modelKey(from propertyName: String, _ createdKey: @autoclosure () -> ModelPropertyKey) -> ModelPropertyKey { - if let key = modelKeys[propertyName] { return key } - modelKeysLock.wait() defer { modelKeysLock.signal() } if let key = modelKeys[propertyName] { return key } @@ -31,8 +29,6 @@ public class ModelType: BaseType { func JSONKey(from propertyName: String, _ createdKey: @autoclosure () -> String) -> String { - if let key = jsonKeys[propertyName] { return key } - jsonKeysLock.wait() defer { jsonKeysLock.signal() } if let key = jsonKeys[propertyName] { return key }