Document rationale for Dart VM flag prefix match (flutter/engine#30195)

Dart VM flags are passed to Flutter via an fml::CommandLine::Option that
looks something like:

   {"dart-flags, "--max_profile_depth 1,--trace_service"}

We perform a prefix match to handle cases where Dart VM options take
arguments.

Adding the comment since in a recent review I found myself wondering why
we're using a prefix match to begin with. While the original author had
forgotten, the good news is, he wrote a test that covers this exact
case. This comment just removes one level of indirection for future
readers.
This commit is contained in:
Chris Bracken
2021-12-07 14:36:33 -08:00
committed by GitHub
parent 5c27f5db99
commit 4fd686f454

View File

@@ -168,7 +168,10 @@ static std::vector<std::string> ParseCommaDelimited(const std::string& input) {
static bool IsAllowedDartVMFlag(const std::string& flag) {
for (uint32_t i = 0; i < fml::size(gAllowedDartFlags); ++i) {
const std::string& allowed = gAllowedDartFlags[i];
// Check that the prefix of the flag matches one of the allowed flags.
// Check that the prefix of the flag matches one of the allowed flags. This
// is to handle cases where flags take arguments, such as in
// "--max_profile_depth 1".
//
// We don't need to worry about cases like "--safe --sneaky_dangerous" as
// the VM will discard these as a single unrecognized flag.
if (flag.length() >= allowed.length() &&