Skip to content

Commit 331c815

Browse files
committed
Adjust lock
1 parent 12e7191 commit 331c815

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
---
44

55
## [1.1.1](https://github.com/kakaopensource/KakaJSON/releases/tag/1.1.1) (2019-11-04)
6+
- Adjust Lock
67
- Closed issues
78
- [iOS 9 Crash](https://github.com/kakaopensource/KakaJSON/issues/31)
89
- Merged pull requests

Sources/KakaJSON/Metadata/Metadata.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public struct Metadata {
1313
private static var types = [TypeKey: BaseType]()
1414

1515
public static func type(_ type: Any.Type) -> BaseType? {
16+
typeLock.lock()
17+
defer { typeLock.unlock() }
18+
1619
// get from cache
1720
let key = typeKey(type)
1821
if let mt = types[key] { return mt }
@@ -23,11 +26,6 @@ public struct Metadata {
2326
|| name == "NSObject"
2427
|| name == "_TtCs12_SwiftObject" { return nil }
2528

26-
typeLock.lock()
27-
defer { typeLock.unlock() }
28-
// judge after lock
29-
if let mt = types[key] { return mt }
30-
3129
// type judge
3230
var mtt: BaseType.Type
3331
let kind = Kind(type)

Sources/KakaJSON/Metadata/Type/ModelType.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ public class ModelType: BaseType {
1818

1919
func modelKey(from propertyName: String,
2020
_ createdKey: @autoclosure () -> ModelPropertyKey) -> ModelPropertyKey {
21-
if let key = modelKeys[propertyName] { return key }
22-
2321
modelKeysLock.wait()
2422
defer { modelKeysLock.signal() }
2523
if let key = modelKeys[propertyName] { return key }
@@ -31,8 +29,6 @@ public class ModelType: BaseType {
3129

3230
func JSONKey(from propertyName: String,
3331
_ createdKey: @autoclosure () -> String) -> String {
34-
if let key = jsonKeys[propertyName] { return key }
35-
3632
jsonKeysLock.wait()
3733
defer { jsonKeysLock.signal() }
3834
if let key = jsonKeys[propertyName] { return key }

0 commit comments

Comments
 (0)