aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-10-04 10:52:15 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-10-04 10:52:15 +0200
commit3d224bcb822081c4aa54a82d514bea07f7c459fe (patch)
tree66408aa900018ae81defb1f25ba08e9f615cacf4
parente1a1d978d364c723935acfc7b56fae8b8253d054 (diff)
Optimize internal scope implementation
-rw-r--r--libbuild2/c/init.cxx4
-rw-r--r--libbuild2/cc/common.hxx18
-rw-r--r--libbuild2/cc/common.ixx33
-rw-r--r--libbuild2/cc/compile-rule.cxx22
-rw-r--r--libbuild2/cc/module.cxx56
-rw-r--r--libbuild2/cc/module.hxx5
-rw-r--r--libbuild2/cxx/init.cxx4
7 files changed, 68 insertions, 74 deletions
diff --git a/libbuild2/c/init.cxx b/libbuild2/c/init.cxx
index 01b9ae7..be001a8 100644
--- a/libbuild2/c/init.cxx
+++ b/libbuild2/c/init.cxx
@@ -363,8 +363,8 @@ namespace build2
false, // No C modules yet.
false, // No __symexport support since no modules.
- cm.internal_scope,
- cm.internal_scope_current,
+ cm.iscope,
+ cm.iscope_current,
cast_null<strings> (rs["cc.internal.libs"]),
cast_null<strings> (rs[cm.x_internal_libs]),
diff --git a/libbuild2/cc/common.hxx b/libbuild2/cc/common.hxx
index 6e36f8e..7d8424f 100644
--- a/libbuild2/cc/common.hxx
+++ b/libbuild2/cc/common.hxx
@@ -180,14 +180,16 @@ namespace build2
bool modules; // x.features.modules
bool symexport; // x.features.symexport
- const string* internal_scope; // x.internal.scope
- const scope* internal_scope_current;
+ enum class internal_scope {current, base, root, bundle, strong, weak};
- const strings* c_internal_libs; // cc.internal.libs
- const strings* x_internal_libs; // x.internal.libs
+ optional<internal_scope> iscope; // x.internal.scope
+ const scope* iscope_current;
const scope*
- effective_internal_scope (const scope& bs) const;
+ effective_iscope (const scope& bs) const;
+
+ const strings* c_ilibs; // cc.internal.libs
+ const strings* x_ilibs; // x.internal.libs
build2::cc::importable_headers* importable_headers;
@@ -250,7 +252,7 @@ namespace build2
const string& env_cs,
bool fm,
bool fs,
- const string* ints, const scope* intsc,
+ optional<internal_scope> is, const scope* isc,
const strings* cils, const strings* xils,
const dir_paths& sld,
const dir_paths& shd,
@@ -274,8 +276,8 @@ namespace build2
env_checksum (env_cs),
modules (fm),
symexport (fs),
- internal_scope (ints), internal_scope_current (intsc),
- c_internal_libs (cils), x_internal_libs (xils),
+ iscope (is), iscope_current (isc),
+ c_ilibs (cils), x_ilibs (xils),
importable_headers (nullptr),
sys_lib_dirs (sld), sys_hdr_dirs (shd), sys_mod_dirs (smd),
sys_lib_dirs_mode (slm), sys_hdr_dirs_mode (shm),
diff --git a/libbuild2/cc/common.ixx b/libbuild2/cc/common.ixx
index ce28890..417efbd 100644
--- a/libbuild2/cc/common.ixx
+++ b/libbuild2/cc/common.ixx
@@ -6,29 +6,22 @@ namespace build2
namespace cc
{
inline const scope* data::
- effective_internal_scope (const scope& bs) const
+ effective_iscope (const scope& bs) const
{
- if (internal_scope == nullptr)
- return nullptr;
- else
+ if (iscope)
{
- const string& s (*internal_scope);
-
- if (s == "current")
- return internal_scope_current;
- else if (s == "base")
- return &bs;
- else if (s == "root")
- return bs.root_scope ();
- else if (s == "bundle")
- return bs.bundle_scope ();
- else if (s == "strong")
- return bs.strong_scope ();
- else if (s == "weak")
- return bs.weak_scope ();
- else
- return nullptr;
+ switch (*iscope)
+ {
+ case internal_scope::current: return iscope_current;
+ case internal_scope::base: return &bs;
+ case internal_scope::root: return bs.root_scope ();
+ case internal_scope::bundle: return bs.bundle_scope ();
+ case internal_scope::strong: return bs.strong_scope ();
+ case internal_scope::weak: return bs.weak_scope ();
+ }
}
+
+ return nullptr;
}
}
}
diff --git a/libbuild2/cc/compile-rule.cxx b/libbuild2/cc/compile-rule.cxx
index 9149f0c..c6ecf5e 100644
--- a/libbuild2/cc/compile-rule.cxx
+++ b/libbuild2/cc/compile-rule.cxx
@@ -509,22 +509,21 @@ namespace build2
// are outside of the internal scope provided the library is not
// whitelisted.
//
- auto whitelist = [&l] (const strings* pats)
+ auto whitelist = [&l] (const strings& pats)
{
- return (pats != nullptr &&
- find_if (pats->begin (), pats->end (),
+ return find_if (pats.begin (), pats.end (),
[&l] (const string& pat)
{
return path_match (l.name, pat);
- }) != pats->end ());
+ }) != pats.end ();
};
const scope* is (d.is);
- if (is != nullptr && whitelist (c_internal_libs))
+ if (is != nullptr && c_ilibs != nullptr && whitelist (*c_ilibs))
is = nullptr;
- if (is != nullptr && whitelist (x_internal_libs))
+ if (is != nullptr && x_ilibs != nullptr && whitelist (*x_ilibs))
is = nullptr;
for (auto i (ops->begin ()), e (ops->end ()); i != e; ++i)
@@ -654,10 +653,7 @@ namespace build2
const scope& bs,
action a, const file& l, bool la, linfo li) const
{
- const scope* is (isystem (*this)
- ? effective_internal_scope (bs)
- : nullptr);
-
+ const scope* is (isystem (*this) ? effective_iscope (bs) : nullptr);
append_library_options (ls, args, bs, is, a, l, la, li, nullptr);
}
@@ -667,10 +663,10 @@ namespace build2
const scope& bs,
action a, const target& t, linfo li) const
{
- auto internal_scope = [this, &bs, is = optional<const scope*> ()] () mutable
+ auto iscope = [this, &bs, is = optional<const scope*> ()] () mutable
{
if (!is)
- is = isystem (*this) ? effective_internal_scope (bs) : nullptr;
+ is = isystem (*this) ? effective_iscope (bs) : nullptr;
return *is;
};
@@ -698,7 +694,7 @@ namespace build2
{
append_library_options (ls,
args,
- bs, internal_scope (),
+ bs, iscope (),
a, *f, la, li,
&lc);
}
diff --git a/libbuild2/cc/module.cxx b/libbuild2/cc/module.cxx
index 117c8c9..871cfb6 100644
--- a/libbuild2/cc/module.cxx
+++ b/libbuild2/cc/module.cxx
@@ -473,17 +473,18 @@ namespace build2
// Note also that we only update x.internal.scope (and not cc.*) to
// reflect the effective value.
//
+ const string* iscope_str (nullptr);
{
if (lookup l = lookup_config (rs, config_x_internal_scope)) // 1
{
- internal_scope = &cast<string> (l);
+ iscope_str = &cast<string> (l);
- if (*internal_scope == "current")
+ if (*iscope_str == "current")
fail << "'current' value in " << config_x_internal_scope;
}
else if (lookup l = rs["config.cc.internal.scope"]) // 2
{
- internal_scope = &cast<string> (l);
+ iscope_str = &cast<string> (l);
}
else // 3
{
@@ -495,31 +496,31 @@ namespace build2
//
bool xl (cast_false<bool> (as[string (x) + ".config.loaded"]));
if (xl)
- internal_scope = cast_null<string> (as[x_internal_scope]);
+ iscope_str = cast_null<string> (as[x_internal_scope]);
- if (internal_scope == nullptr)
+ if (iscope_str == nullptr)
{
if (xl || cast_false<bool> (as["cc.core.config.loaded"]))
- internal_scope = cast_null<string> (as["cc.internal.scope"]);
+ iscope_str = cast_null<string> (as["cc.internal.scope"]);
}
- if (internal_scope != nullptr && *internal_scope == "current")
- internal_scope_current = &as;
+ if (iscope_str != nullptr && *iscope_str == "current")
+ iscope_current = &as;
}
}
lookup l;
- if (internal_scope == nullptr)
+ if (iscope_str == nullptr)
{
- internal_scope = cast_null<string> (l = rs[x_internal_scope]); // 4
+ iscope_str = cast_null<string> (l = rs[x_internal_scope]); // 4
- if (internal_scope == nullptr)
- internal_scope = cast_null<string> (rs["cc.internal.scope"]); // 5
+ if (iscope_str == nullptr)
+ iscope_str = cast_null<string> (rs["cc.internal.scope"]); // 5
}
- if (internal_scope != nullptr)
+ if (iscope_str != nullptr)
{
- const string& s (*internal_scope);
+ const string& s (*iscope_str);
// Assign effective.
//
@@ -528,17 +529,18 @@ namespace build2
if (s == "current")
{
- if (internal_scope_current == nullptr)
- internal_scope_current = &rs;
+ iscope = internal_scope::current;
+
+ if (iscope_current == nullptr)
+ iscope_current = &rs;
}
- else if (s == "base" ||
- s == "root" ||
- s == "bundle" ||
- s == "strong" ||
- s == "weak")
- ;
+ else if (s == "base") iscope = internal_scope::base;
+ else if (s == "root") iscope = internal_scope::root;
+ else if (s == "bundle") iscope = internal_scope::bundle;
+ else if (s == "strong") iscope = internal_scope::strong;
+ else if (s == "weak") iscope = internal_scope::weak;
else if (s == "global")
- internal_scope = nullptr; // Nothing to translate;
+ ; // Nothing to translate;
else
fail << "invalid " << x_internal_scope << " value '" << s << "'";
}
@@ -789,14 +791,14 @@ namespace build2
auto& incs (hdr_dirs.first);
auto& libs (lib_dirs.first);
- if (verb >= 3 && internal_scope != nullptr)
+ if (verb >= 3 && iscope)
{
dr << "\n int scope ";
- if (*internal_scope == "current")
- dr << internal_scope_current->out_path ();
+ if (*iscope == internal_scope::current)
+ dr << iscope_current->out_path ();
else
- dr << *internal_scope;
+ dr << *iscope_str;
}
if (verb >= 3 && !mods.empty ())
diff --git a/libbuild2/cc/module.hxx b/libbuild2/cc/module.hxx
index 5c68482..df7fc70 100644
--- a/libbuild2/cc/module.hxx
+++ b/libbuild2/cc/module.hxx
@@ -63,8 +63,9 @@ namespace build2
// Cached x.internal.scope value.
//
- const string* internal_scope = nullptr;
- const scope* internal_scope_current = nullptr;
+ using internal_scope = data::internal_scope;
+ optional<internal_scope> iscope;
+ const scope* iscope_current;
// Temporary storage for data::sys_*_dirs_*.
//
diff --git a/libbuild2/cxx/init.cxx b/libbuild2/cxx/init.cxx
index 0f99c3a..7e1bc4c 100644
--- a/libbuild2/cxx/init.cxx
+++ b/libbuild2/cxx/init.cxx
@@ -841,8 +841,8 @@ namespace build2
modules,
symexport,
- cm.internal_scope,
- cm.internal_scope_current,
+ cm.iscope,
+ cm.iscope_current,
cast_null<strings> (rs["cc.internal.libs"]),
cast_null<strings> (rs[cm.x_internal_libs]),