Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix perfomance issue caused by Dictionary's swift_dynamicCast #177

Merged
merged 7 commits into from Jun 2, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions Sources/Extractor.swift
Expand Up @@ -8,13 +8,22 @@

import class Foundation.NSNull

// swiftlint:disable type_name
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
import class Foundation.NSDictionary
private typealias _Dictionary = NSDictionary
#else
private typealias _Dictionary = [String: Any]
#endif
// swiftlint:enable type_name

public struct Extractor {
public let rawValue: Any
private let dictionary: [String: Any]?
private let dictionary: _Dictionary?

internal init(_ rawValue: Any) {
self.rawValue = rawValue
self.dictionary = rawValue as? [String: Any]
self.dictionary = rawValue as? _Dictionary
}

// If we use `rawValue` here, that would conflict with `let rawValue: Any`
Expand Down Expand Up @@ -95,7 +104,7 @@ extension Extractor: CustomStringConvertible {
private func valueFor(_ keyPath: KeyPath, _ json: Any) -> Any? {
var result = json
for key in keyPath.components {
if let object = result as? [String: Any], let value = object[key] {
if let object = result as? _Dictionary, let value = object[key] {
result = value
} else {
return nil
Expand Down