Proposal: static function cmGeneratorExpression::Evaluate()
A common pattern is the following (50+):
cmGeneratorExpression ge;
std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(str);
std::string evaluated = cge->Evaluate(lg, config);
I propose a static function which simplifies this:
std::string evaluated = cmGeneratorExpression::Evaluate(str, lg, config);
In addition to being shorter there are optimizations which can be applied:
-
cmCompiledGeneratorExpression
does not need to be allocated, it can stay on the heap - We could search for
'$'
and if not followed by'<'
go on searching for"$<"
first. If no potential start of a generator expression is found return the string as is. Otherwise the lexer can be initialized with the position of the first'$'
.
On the fast path without a generator expression there is just a linear sweep through the string followed by a copy or a move of the input string.