Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cubic runtime complexity for collecting source/import files. #1079

Merged
merged 2 commits into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions source/dub/compilers/buildsettings.d
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ struct BuildSettings {
// add string import files (avoids file name duplicates in addition to path duplicates)
private void addSI(ref string[] arr, in string[] vals)
{
outer:
bool[string] existing;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A next iteration could cache this as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I was a bit afraid to forget a place where it could get out of sync, because the arrays are public fields, so I wanted to leave that to a more in-depth optimization attempt.

foreach (v; arr) existing[Path(v).head.toString()] = true;
foreach (v; vals) {
auto vh = Path(v).head;
foreach (ve; arr) {
if (Path(ve).head == vh)
continue outer;
auto s = Path(v).head.toString();
if (s !in existing) {
existing[s] = true;
arr ~= v;
}
arr ~= v;
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/dub/internal/vibecompat/inet/path.d
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ struct Path {
}

/// The last entry of the path
@property ref immutable(PathEntry) head() const { enforce(m_nodes.length > 0); return m_nodes[$-1]; }
@property ref immutable(PathEntry) head() const { enforce(m_nodes.length > 0, "Getting head of empty path."); return m_nodes[$-1]; }

/// The parent path
@property Path parentPath() const { return this[0 .. length-1]; }
Expand Down
6 changes: 5 additions & 1 deletion source/dub/recipe/packagerecipe.d
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ struct BuildSettingsTemplate {

void collectFiles(string method)(in string[][string] paths_map, string pattern)
{
auto files = appender!(string[]);

foreach (suffix, paths; paths_map) {
if (!platform.matchesSpecification(suffix))
continue;
Expand All @@ -192,10 +194,12 @@ struct BuildSettingsTemplate {
import std.path : baseName;
if (baseName(d.name)[0] == '.' || isDir(d.name)) continue;
auto src = Path(d.name).relativeTo(base_path);
__traits(getMember, dst, method)(src.toNativeString());
files ~= src.toNativeString();
}
}
}

__traits(getMember, dst, method)(files.data);
}

// collect files from all source/import folders
Expand Down