Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: tools/gn/switches.cc

Issue 778513003: gn: Employ the same INSERT_VARIABLE macro trick for switches.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: empty string Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/gn/variables.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/switches.cc
diff --git a/tools/gn/switches.cc b/tools/gn/switches.cc
index 93c7f9870c38fe6ee2b899b2d64e7fc0c2a8637f..5e383e1c26fe67fdec0cbe29c5eb4532483c04fb 100644
--- a/tools/gn/switches.cc
+++ b/tools/gn/switches.cc
@@ -163,6 +163,8 @@ const char kVersion_HelpShort[] =
// immediately if this switch is used.
const char kVersion_Help[] = "";
+// -----------------------------------------------------------------------------
+
SwitchInfo::SwitchInfo()
: short_help(""),
long_help("") {
@@ -173,23 +175,26 @@ SwitchInfo::SwitchInfo(const char* short_help, const char* long_help)
long_help(long_help) {
}
+#define INSERT_VARIABLE(var) \
+ info_map[k##var] = SwitchInfo(k##var##_HelpShort, k##var##_Help);
+
const SwitchInfoMap& GetSwitches() {
- static SwitchInfoMap* switches = NULL;
- if (!switches) {
- switches = new SwitchInfoMap;
-
- (*switches)[kArgs] = SwitchInfo(kArgs_HelpShort, kArgs_Help);
- (*switches)[kColor] = SwitchInfo(kColor_HelpShort, kColor_Help);
- (*switches)[kDotfile] = SwitchInfo(kDotfile_HelpShort, kDotfile_Help);
- (*switches)[kNoColor] = SwitchInfo(kNoColor_HelpShort, kNoColor_Help);
- (*switches)[kRoot] = SwitchInfo(kRoot_HelpShort, kRoot_Help);
- (*switches)[kQuiet] = SwitchInfo(kQuiet_HelpShort, kQuiet_Help);
- (*switches)[kTime] = SwitchInfo(kTime_HelpShort, kTime_Help);
- (*switches)[kTracelog] = SwitchInfo(kTracelog_HelpShort, kTracelog_Help);
- (*switches)[kVerbose] = SwitchInfo(kVerbose_HelpShort, kVerbose_Help);
- (*switches)[kVersion] = SwitchInfo(kVersion_HelpShort, kVersion_Help);
+ static SwitchInfoMap info_map;
+ if (info_map.empty()) {
+ INSERT_VARIABLE(Args)
+ INSERT_VARIABLE(Color)
+ INSERT_VARIABLE(Dotfile)
+ INSERT_VARIABLE(NoColor)
+ INSERT_VARIABLE(Root)
+ INSERT_VARIABLE(Quiet)
+ INSERT_VARIABLE(Time)
+ INSERT_VARIABLE(Tracelog)
+ INSERT_VARIABLE(Verbose)
+ INSERT_VARIABLE(Version)
}
- return *switches;
+ return info_map;
}
+#undef INSERT_VARIABLE
+
} // namespace switches
« no previous file with comments | « no previous file | tools/gn/variables.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698