Skip to content

Commit

Permalink
Adjust lock
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderMJLee committed Nov 4, 2019
1 parent 12e7191 commit 331c815
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions Sources/KakaJSON/Metadata/Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions Sources/KakaJSON/Metadata/Type/ModelType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down

0 comments on commit 331c815

Please sign in to comment.