Skip to content

Commit

Permalink
Simplify flags_ui::FeatureEntry() code.
Browse files Browse the repository at this point in the history
Avoid using base::ASCIIToUTF16(base::StringPiece(str)). Use
base::StrCat() in one case, and simply remove the base::StringPiece() in
another.

Make a constant truly const along the way.

Change-Id: I8545879ba575b3a93b53bfdaa6e7102aee8b6748
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3420961
Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#964791}
  • Loading branch information
leizleiz authored and Chromium LUCI CQ committed Jan 28, 2022
1 parent 3e17177 commit c06c844
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions components/flags_ui/feature_entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/check_op.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
Expand Down Expand Up @@ -87,8 +88,9 @@ std::u16string FeatureEntry::DescriptionForOption(int index) const {
const char* description = nullptr;
if (type == FeatureEntry::ENABLE_DISABLE_VALUE ||
type == FeatureEntry::FEATURE_VALUE) {
const char* kEnableDisableDescriptions[] = {
kGenericExperimentChoiceDefault, kGenericExperimentChoiceEnabled,
const char* const kEnableDisableDescriptions[] = {
kGenericExperimentChoiceDefault,
kGenericExperimentChoiceEnabled,
kGenericExperimentChoiceDisabled,
};
description = kEnableDisableDescriptions[index];
Expand All @@ -100,19 +102,17 @@ std::u16string FeatureEntry::DescriptionForOption(int index) const {
} else if (index < NumOptions() - 1) {
// First two options do not have variations params.
int variation_index = index - 2;
return base::ASCIIToUTF16(
base::StringPiece(kGenericExperimentChoiceEnabled)) +
u" " +
base::ASCIIToUTF16(
feature.feature_variations[variation_index].description_text);
return base::ASCIIToUTF16(base::StrCat(
{kGenericExperimentChoiceEnabled, " ",
feature.feature_variations[variation_index].description_text}));
} else {
DCHECK_EQ(NumOptions() - 1, index);
description = kGenericExperimentChoiceDisabled;
}
} else {
description = choices[index].description;
}
return base::ASCIIToUTF16(base::StringPiece(description));
return base::ASCIIToUTF16(description);
}

const FeatureEntry::Choice& FeatureEntry::ChoiceForOption(int index) const {
Expand Down

0 comments on commit c06c844

Please sign in to comment.