diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2022-11-30 11:49:56 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2022-11-30 11:49:56 +0200 |
commit | 59f70280dee90957a672810a3845af2dec8552e8 (patch) | |
tree | 609b729c394b44a38418a6f19d03893dbfbd0e9f /libbuild2/context.cxx | |
parent | 3bbbe09e8629ab5311a1bcbb9f56aa6a33e36f55 (diff) |
Reserve targets, variables to avoid rehashing
Diffstat (limited to 'libbuild2/context.cxx')
-rw-r--r-- | libbuild2/context.cxx | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libbuild2/context.cxx b/libbuild2/context.cxx index 1da6fd3..967577f 100644 --- a/libbuild2/context.cxx +++ b/libbuild2/context.cxx @@ -60,6 +60,18 @@ namespace build2 var_patterns (&c /* shared */, &var_pool) {} }; + void context:: + reserve (reserves res) + { + assert (phase == run_phase::load); + + if (res.targets != 0) + data_->targets.map_.reserve (res.targets); + + if (res.variables != 0) + data_->var_pool.map_.reserve (res.variables); + } + context:: context (scheduler& s, global_mutexes& ms, @@ -70,6 +82,7 @@ namespace build2 bool ndb, bool kg, const strings& cmd_vars, + reserves res, optional<context*> mc, const loaded_modules_lock* ml) : data_ (new data (*this)), @@ -102,6 +115,8 @@ namespace build2 l6 ([&]{trace << "initializing build state";}); + reserve (res); + scope_map& sm (data_->scopes); variable_pool& vp (data_->var_pool); variable_patterns& vpats (data_->var_patterns); |