Skip to content

Commit

Permalink
Reduce allocation overhead in determineDependencyConfigs.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-ludwig committed May 3, 2024
1 parent 449d412 commit e479113
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions source/dub/project.d
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ class Project {
string[string] getPackageConfigs(in BuildPlatform platform, string config, bool allow_non_library = true)
const {
import std.typecons : Rebindable, rebindable;
import std.range : only;

struct Vertex { size_t pack = size_t.max; string config; }
struct Edge { size_t from, to; }
Expand Down Expand Up @@ -775,24 +776,28 @@ class Project {
auto dp = package_map.get(d.name.toString(), size_t.max);
if (dp == size_t.max) continue;

depconfigs[dp] = null;
depconfigs[dp].length = 0;
depconfigs[dp].assumeSafeAppend;

string[] cfgs;
if (auto pc = package_names[dp] in m_overriddenConfigs) cfgs = [*pc];
else {
void setConfigs(R)(R configs) {
configs
.filter!(c => haveConfig(dp, c))
.each!((c) { depconfigs[dp] ~= c; });
}
if (auto pc = package_names[dp] in m_overriddenConfigs) {
setConfigs(only(*pc));
} else {
auto subconf = p.getSubConfiguration(c, package_list[dp], platform);
if (!subconf.empty) cfgs = [subconf];
else cfgs = package_list[dp].getPlatformConfigurations(platform);
if (!subconf.empty) setConfigs(only(subconf));
else setConfigs(package_list[dp].getPlatformConfigurations(platform));
}
cfgs = cfgs.filter!(c => haveConfig(dp, c)).array;

// if no valid configuration was found for a dependency, don't include the
// current configuration
if (!cfgs.length) {
if (!depconfigs[dp].length) {
logDebug("Skip %s %s (missing configuration for %s)", pname, c, package_names[dp]);
return;
}
depconfigs[dp] = cfgs;
}

// add this configuration to the graph
Expand Down

0 comments on commit e479113

Please sign in to comment.