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.hxx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'libbuild2/context.hxx') diff --git a/libbuild2/context.hxx b/libbuild2/context.hxx index b71a068..27c3cc0 100644 --- a/libbuild2/context.hxx +++ b/libbuild2/context.hxx @@ -652,6 +652,15 @@ namespace build2 // Note: see also the trace_* data members that, if needed, must be set // separately, after construction. // + struct reserves + { + size_t targets; + size_t variables; + + reserves (): targets (0), variables (0) {} + reserves (size_t t, size_t v): targets (t), variables (v) {} + }; + explicit context (scheduler&, global_mutexes&, @@ -662,9 +671,17 @@ namespace build2 bool no_diag_buffer = false, bool keep_going = true, const strings& cmd_vars = {}, + reserves = {0, 160}, optional module_context = nullptr, const loaded_modules_lock* inherited_mudules_lock = nullptr); + // Reserve elements in containers to avoid re-allocation/re-hashing. Zero + // values are ignored (that is, the corresponding container reserve() + // function is not called). Can only be called in the load phase. + // + void + reserve (reserves); + // Enter project-wide (as opposed to global) variable overrides. // void -- cgit v1.1