@@ -197,44 +197,38 @@ namespace cs::semantic {
197197 // try to find if the key has an associated instruction
198198 if (const auto candidate = flags_.lower_bound (key); flags_.end () != candidate) {
199199 // exact matches are preferred in all cases.
200- if (auto result = check_equal (key, candidate); result) {
200+ if (auto result = check_equal (key, * candidate); result) {
201201 return result;
202202 }
203203 // check if the argument is allowed to stick to the flag
204- if (auto result = check_partial (key, candidate); result) {
204+ if (auto result = check_partial (key, * candidate); result) {
205205 return result;
206206 }
207- // check if this is the first element or not.
208- if (flags_.begin () != candidate) {
209- const auto previous = std::prev (candidate);
210- if (auto result = check_partial (key, previous); result) {
211- return result;
212- }
213- }
214207 }
215- // check if the last element is not the one we are looking for.
216- // (this is a limitation of `lower_bound` method.)
217- const auto candidate = std::prev (flags_.end ());
218- if (auto result = check_partial (key, candidate); result) {
219- return result;
208+ // partial match is less likely to be a few steps away from the lower bound,
209+ // therefore search the whole flag list again.
210+ for (const auto candidate : flags_) {
211+ if (auto result = check_partial (key, candidate); result) {
212+ return result;
213+ }
220214 }
221215 return std::nullopt ;
222216 }
223217
224218 std::optional<FlagParser::Match>
225- FlagParser::check_equal (const std::string_view &key, FlagsByName::const_iterator candidate) {
226- const auto &flag_definition = candidate-> second ;
227- if ((is_exact_match_only (flag_definition.match ) || is_prefix_match (flag_definition.match )) && key == candidate-> first ) {
219+ FlagParser::check_equal (const std::string_view &key, const FlagsByName::value_type & candidate) {
220+ const auto &flag_definition = candidate. second ;
221+ if ((is_exact_match_only (flag_definition.match ) || is_prefix_match (flag_definition.match )) && key == candidate. first ) {
228222 const size_t count = count_of_arguments (flag_definition.match );
229223 return std::make_optional (std::make_tuple (count, flag_definition.type ));
230224 }
231225 return std::nullopt ;
232226 }
233227
234228 std::optional<FlagParser::Match>
235- FlagParser::check_partial (const std::string_view &key, FlagsByName::const_iterator candidate) {
236- const auto &flag_definition = candidate-> second ;
237- if (const auto extra = split_extra (candidate-> first , key); extra) {
229+ FlagParser::check_partial (const std::string_view &key, const FlagsByName::value_type & candidate) {
230+ const auto &flag_definition = candidate. second ;
231+ if (const auto extra = split_extra (candidate. first , key); extra) {
238232 const auto flag_matching = classify_flag_matching (extra.value ());
239233 switch (flag_matching) {
240234 case FlagMatch::GLUED:
0 commit comments