diff options
author | Nico Weber <nicolasweber@gmx.de> | 2014-04-17 05:28:53 (GMT) |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2014-04-17 05:28:53 (GMT) |
commit | b121addcb6ac4a0e826b0c4270de9974222876ad (patch) | |
tree | 42631fc00f57018c139f6ab759b5ce0bb102a060 | |
parent | 0f81383d161dfcbff4347b7bb7fcdfc39090a7e1 (diff) | |
parent | dd8c1d84699bb6b45ffa1a529d53fe2273c8b427 (diff) | |
download | Ninja-b121addcb6ac4a0e826b0c4270de9974222876ad.zip Ninja-b121addcb6ac4a0e826b0c4270de9974222876ad.tar.gz Ninja-b121addcb6ac4a0e826b0c4270de9974222876ad.tar.bz2 |
Merge pull request #715 from nico/lazyenv
Allocate per-edge BindingEnvs lazily.
-rw-r--r-- | src/manifest_parser.cc | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/manifest_parser.cc b/src/manifest_parser.cc index 20be7f3..6fa4f7c 100644 --- a/src/manifest_parser.cc +++ b/src/manifest_parser.cc @@ -296,16 +296,17 @@ bool ManifestParser::ParseEdge(string* err) { if (!ExpectToken(Lexer::NEWLINE, err)) return false; - // XXX scoped_ptr to handle error case. - BindingEnv* env = new BindingEnv(env_); - - while (lexer_.PeekToken(Lexer::INDENT)) { + // Bindings on edges are rare, so allocate per-edge envs only when needed. + bool hasIdent = lexer_.PeekToken(Lexer::INDENT); + BindingEnv* env = hasIdent ? new BindingEnv(env_) : env_; + while (hasIdent) { string key; EvalString val; if (!ParseLet(&key, &val, err)) return false; env->AddBinding(key, val.Evaluate(env_)); + hasIdent = lexer_.PeekToken(Lexer::INDENT); } Edge* edge = state_->AddEdge(rule); |