From 59f70280dee90957a672810a3845af2dec8552e8 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 30 Nov 2022 11:49:56 +0200 Subject: Reserve targets, variables to avoid rehashing --- libbuild2/context.cxx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libbuild2/context.cxx') 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 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); -- cgit v1.1