mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Cleans up header order/grouping for consistency: associated header, C/C++ system/standard library headers, library headers, platform-specific #includes. Adds <cstring> where strlen, memcpy are being used: there are a bunch of places we use them transitively. Applies linter-required cleanups. Disables linter on one file due to included RapidJson header. See https://github.com/flutter/flutter/issues/65676 This patch does not cover flutter/shell/platform/darwin. There's a separate, slightly more intensive cleanup for those in progress.
51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
// Copyright 2013 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "flutter/fml/ascii_trie.h"
|
|
|
|
#include "flutter/fml/logging.h"
|
|
|
|
namespace fml {
|
|
typedef AsciiTrie::TrieNode TrieNode;
|
|
typedef AsciiTrie::TrieNodePtr TrieNodePtr;
|
|
|
|
namespace {
|
|
void Add(TrieNodePtr* trie, const char* entry) {
|
|
int ch = entry[0];
|
|
FML_DCHECK(ch < AsciiTrie::kMaxAsciiValue);
|
|
if (ch != 0) {
|
|
if (!*trie) {
|
|
*trie = std::make_unique<TrieNode>();
|
|
}
|
|
Add(&(*trie)->children[ch], entry + 1);
|
|
}
|
|
}
|
|
|
|
TrieNodePtr MakeTrie(const std::vector<std::string>& entries) {
|
|
TrieNodePtr result;
|
|
for (const std::string& entry : entries) {
|
|
Add(&result, entry.c_str());
|
|
}
|
|
return result;
|
|
}
|
|
} // namespace
|
|
|
|
void AsciiTrie::Fill(const std::vector<std::string>& entries) {
|
|
node_ = MakeTrie(entries);
|
|
}
|
|
|
|
bool AsciiTrie::Query(TrieNode* trie, const char* query) {
|
|
FML_DCHECK(trie);
|
|
const char* char_position = query;
|
|
TrieNode* trie_position = trie;
|
|
TrieNode* child = nullptr;
|
|
int ch;
|
|
while ((ch = *char_position) && (child = trie_position->children[ch].get())) {
|
|
char_position++;
|
|
trie_position = child;
|
|
}
|
|
return !child && trie_position != trie;
|
|
}
|
|
} // namespace fml
|