-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Vendors table faster, but code not DRY
- Loading branch information
Showing
11 changed files
with
180 additions
and
54 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) halo https://github.com/halo/LinkLiar | ||
// SPDX-License-Identifier: MIT | ||
|
||
import Foundation | ||
|
||
struct PopularVendorNames { | ||
// MARK: Class Properties | ||
|
||
/// | ||
/// Looks up a Vendor by its ID. | ||
/// If no vendor was found, or it has no valid prefixes, returns nil. | ||
/// | ||
/// The ID is really just a nickname as String, nothing official. | ||
/// It is used as a convenience shortcut in the LinkLiar config file. | ||
/// | ||
/// - parameter id: The ID of the vendor (e.g. "ibm"). | ||
/// | ||
/// - returns: A ``Vendor`` if found and `nil` if missing. | ||
/// | ||
static func find(_ id: String) -> Vendor? { | ||
let id = id.filter("0123456789abcdefghijklmnopqrstuvwxyz".contains) | ||
guard let vendorData = PopularVendorsDatabase.dictionaryWithCounts[id] else { return nil } | ||
|
||
guard let rawPrefixCount = vendorData.values.first else { return nil } | ||
guard let name = vendorData.keys.first else { return nil } | ||
|
||
return Vendor(id: id, name: name, prefixCount: rawPrefixCount) | ||
} | ||
|
||
static func find(_ ids: [String]) -> [Vendor] { | ||
ids.compactMap { find($0) }.sorted() | ||
} | ||
|
||
// MARK: Private Class Properties | ||
|
||
static var all: [Vendor] { | ||
PopularVendorsDatabase.dictionaryWithCounts.keys.reversed().compactMap { | ||
find($0) | ||
}.sorted() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters