Address clang-tidy warning.

This is performance lint, which is useless in tests, but let's burn it.

Also, slightly updated the code to make it look more pretty (and that's how I silenced the lint).

PiperOrigin-RevId: 727725125
This commit is contained in:
Tomoki Nakagawa
2025-02-17 07:10:01 +00:00
committed by Hiroyuki Komatsu
parent 4c86252df2
commit 080eddd316

View File

@ -28,6 +28,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <algorithm>
#include <array>
#include <cmath>
#include <cstddef>
#include <cstdint>
@ -45,6 +46,7 @@
#include "absl/algorithm/container.h"
#include "absl/flags/flag.h"
#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
@ -245,25 +247,24 @@ void CreatePredictionKeys(PredictionRequestType type,
CHECK(request_keys);
request_keys->clear();
const char *kVoels[] = {"a", "i", "u", "e", "o"};
const char *kConsonant[] = {"k", "s", "t", "n", "h", "m", "y", "r", "w"};
std::vector<std::string> one_chars;
for (size_t i = 0; i < std::size(kVoels); ++i) {
one_chars.push_back(kVoels[i]);
}
constexpr std::array<absl::string_view, 5> kVoels = {"a", "i", "u", "e", "o"};
constexpr std::array<absl::string_view, 10> kConsonants = {
"", "k", "s", "t", "n", "h", "m", "y", "r", "w"};
for (size_t i = 0; i < std::size(kConsonant); ++i) {
for (size_t j = 0; j < std::size(kVoels); ++j) {
one_chars.push_back(std::string(kConsonant[i]) + std::string(kVoels[j]));
std::vector<std::string> one_chars;
for (absl::string_view c : kConsonants) {
for (absl::string_view v : kVoels) {
one_chars.push_back(absl::StrCat(c, v));
}
}
std::vector<std::string> two_chars;
for (size_t i = 0; i < one_chars.size(); ++i) {
for (size_t j = 0; j < one_chars.size(); ++j) {
two_chars.push_back(one_chars[i] + one_chars[j]);
for (absl::string_view c1 : one_chars) {
for (absl::string_view c2 : one_chars) {
two_chars.push_back(absl::StrCat(c1, c2));
}
}
switch (type) {
case ONE_CHAR:
std::copy(one_chars.begin(), one_chars.end(),