Skip to content

Significantly improve prefix trie performance and memory usage #109

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/SwiftOptions/OptionParsing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ extension OptionTable {
/// Throws an error if the command line contains any errors.
public func parse(_ arguments: [String],
for driverKind: DriverKind) throws -> ParsedOptions {
var trie = PrefixTrie<String.UTF8View, Option>()
var trie = PrefixTrie<Option>()
for opt in options {
trie[opt.spelling.utf8] = opt
trie[opt.spelling] = opt
}

var parsedOptions = ParsedOptions()
Expand Down Expand Up @@ -71,7 +71,7 @@ extension OptionTable {
// match -- if the option is a `.flag`, we'll explicitly check to see if
// there's an unmatched suffix at the end, and pop an error. Otherwise,
// we'll treat the unmatched suffix as the argument to the option.
guard let option = trie[argument.utf8] else {
guard let option = trie[argument] else {
throw OptionParseError.unknownOption(
index: index - 1, argument: argument)
}
Expand Down
Loading