| 397 | PrefixMatch::~PrefixMatch() {} |
| 398 | |
| 399 | PrefixMatch::Match PrefixMatch::MatchPrefix(const char* word, |
| 400 | size_t len) const { |
| 401 | if (singleDict != nullptr) { |
| 402 | struct MatchCache { |
| 403 | std::string key; |
| 404 | std::string value; |
| 405 | }; |
| 406 | // key/value pointers are valid until the next MatchPrefix() call on this |
| 407 | // thread. |
| 408 | static thread_local MatchCache matchCache; |
| 409 | const PrefixMatchView pv = singleDict->MatchPrefixValue(word, len); |
| 410 | if (pv.matched) { |
| 411 | matchCache.key = std::string(pv.key); |
| 412 | matchCache.value = std::string(pv.value); |
| 413 | return Match{true, pv.keyLength, &matchCache.key, &matchCache.value}; |
| 414 | } |
| 415 | return Match{false, 0, nullptr, nullptr}; |
| 416 | } |
| 417 | |
| 418 | const Tables::Matcher::Candidate candidate = |
| 419 | tables->matcher->MatchPrefixCandidate(word, len); |
| 420 | if (candidate.hasValue) { |
| 421 | return Match{true, candidate.keyLength, candidate.key, candidate.value}; |
| 422 | } |
| 423 | return Match{false, 0, nullptr, nullptr}; |
| 424 | } |
| 425 | |
| 426 | PrefixMatchView PrefixMatch::MatchPrefixView(const char* word, |
| 427 | size_t len) const { |
nothing calls this directly
no test coverage detected