From 6a9f150024a795bcf050c004efb1d96c8408306b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 15 Apr 2022 11:37:17 +0200 Subject: Adjust small vector limit in process_libraries() --- libbuild2/cc/common.cxx | 106 ++++++++++++++++++++++++++++++------------------ libbuild2/cc/common.hxx | 23 +++++++++-- 2 files changed, 86 insertions(+), 43 deletions(-) diff --git a/libbuild2/cc/common.cxx b/libbuild2/cc/common.cxx index 8cce132..f7f15aa 100644 --- a/libbuild2/cc/common.cxx +++ b/libbuild2/cc/common.cxx @@ -103,23 +103,49 @@ namespace build2 bool com, // cc. or x. bool exp)>& proc_opt, // *.export. bool self /*= false*/, // Call proc_lib on l? - library_cache* cache, - small_vector* chain, - vector* dedup) const + library_cache* cache) const { library_cache cache_storage; if (cache == nullptr) cache = &cache_storage; - small_vector chain_storage; - if (chain == nullptr) - { - chain = &chain_storage; + small_vector chain; - if (proc_lib) - chain->push_back (nullptr); - } + if (proc_lib) + chain.push_back (nullptr); + process_libraries_impl (a, top_bs, top_li, top_sysd, + l, la, lf, + proc_impl, proc_lib, proc_opt, self, + cache, &chain, nullptr); + } + + void common:: + process_libraries_impl ( + action a, + const scope& top_bs, + optional top_li, + const dir_paths& top_sysd, + const mtime_target& l, + bool la, + lflags lf, + const function& proc_impl, + const function, 2>&, + lflags, + const string* type, + bool sys)>& proc_lib, + const function& proc_opt, + bool self, + library_cache* cache, + small_vector* chain, + small_vector* dedup) const + { // Add the library to the chain. // if (self && proc_lib) @@ -357,10 +383,10 @@ namespace build2 if (sysd == nullptr) find_sysd (); if (!li) find_linfo (); - process_libraries (a, bs, *li, *sysd, - *f, la, pt.data, - proc_impl, proc_lib, proc_opt, true, - cache, chain); + process_libraries_impl (a, bs, *li, *sysd, + *f, la, pt.data, + proc_impl, proc_lib, proc_opt, true, + cache, chain, nullptr); } } } @@ -460,8 +486,8 @@ namespace build2 &find_sysd, &find_linfo, &sense_fragment, &bs, a, &li, impl, this] ( const lookup& lu, - vector* dedup, - size_t dedup_start) + small_vector* dedup, + size_t dedup_start) // Start of our deps. { const vector* ns (cast_null> (lu)); if (ns == nullptr || ns->empty ()) @@ -571,16 +597,26 @@ namespace build2 // them in the library's prerequisites? What about // installed stuff? // - process_libraries (a, bs, *li, *sysd, - t, t.is_a () || t.is_a (), 0, - proc_impl, proc_lib, proc_opt, true, - cache, chain, dedup); + process_libraries_impl ( + a, bs, *li, *sysd, + t, t.is_a () || t.is_a (), 0, + proc_impl, proc_lib, proc_opt, true, + cache, chain, dedup); } ++i; } }; + auto proc_intf_storage = [&proc_intf] (const lookup& lu1, + const lookup& lu2 = lookup ()) + { + small_vector dedup_storage; + + if (lu1) proc_intf (lu1, &dedup_storage, 0); + if (lu2) proc_intf (lu2, &dedup_storage, 0); + }; + // Process libraries from *.libs (of type strings). // auto proc_impl = [&proc_lib, &proc_lib_name, @@ -624,17 +660,10 @@ namespace build2 { if (c_e_libs) { - size_t start; - vector storage; - if (dedup == nullptr) - { - start = 0; - dedup = &storage; - } + if (dedup != nullptr) + proc_intf (c_e_libs, dedup, dedup->size ()); else - start = dedup->size (); // Start of our interface deps. - - proc_intf (c_e_libs, dedup, start); + proc_intf_storage (c_e_libs); } } } @@ -681,18 +710,15 @@ namespace build2 // if (c_e_libs.defined () || x_e_libs.defined ()) { - size_t start; - vector storage; - if (dedup == nullptr) + if (dedup != nullptr) { - start = 0; - dedup = &storage; + size_t s (dedup->size ()); // Start of our interface deps. + + if (c_e_libs) proc_intf (c_e_libs, dedup, s); + if (x_e_libs) proc_intf (x_e_libs, dedup, s); } else - start = dedup->size (); // Start of our interface deps. - - if (c_e_libs) proc_intf (c_e_libs, dedup, start); - if (x_e_libs) proc_intf (x_e_libs, dedup, start); + proc_intf_storage (c_e_libs, x_e_libs); } } } @@ -1221,7 +1247,7 @@ namespace build2 if (a != nullptr) {lt->a = a; mt = a->mtime ();} // Mark the group since sometimes we use it itself instead of one of - // the liba/libs{} members (see process_libraries() for details). + // the liba/libs{} members (see process_libraries_impl() for details). // mark_cc (*lt); } diff --git a/libbuild2/cc/common.hxx b/libbuild2/cc/common.hxx index 2d2145a..1e74b22 100644 --- a/libbuild2/cc/common.hxx +++ b/libbuild2/cc/common.hxx @@ -319,9 +319,26 @@ namespace build2 lflags, const string*, bool)>&, const function&, bool = false, - library_cache* = nullptr, - small_vector* = nullptr, - vector* = nullptr) const; + library_cache* = nullptr) const; + + void + process_libraries_impl ( + action, + const scope&, + optional, + const dir_paths&, + const mtime_target&, + bool, + lflags, + const function&, + const function, 2>&, + lflags, const string*, bool)>&, + const function&, + bool, + library_cache*, + small_vector*, + small_vector*) const; const target* search_library (action a, -- cgit v1.1