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

Changed the '_lines' data structure from Appender to built-in array, as the former leaks memory #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 6 additions & 10 deletions source/dpp/runtime/context.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ struct Context {

alias SeenCursors = bool[CursorId];

private auto lines(this This)() {
return _lines.data;
}

/**
The lines of output so far. This is needed in order to fix
any name collisions between functions or variables with aggregates
such as structs, unions and enums.
*/
private Appender!(string[]) _lines;
private string[] _lines;

/**
Structs can be anonymous in C, and it's even common
Expand Down Expand Up @@ -150,7 +146,7 @@ struct Context {

string translation() @safe pure nothrow const {
import std.array: join;
return lines.join("\n");
return _lines.join("\n");
}

/**
Expand All @@ -174,7 +170,7 @@ struct Context {
const spelling = maybeRename(cursor, this);
// since linkables produce one-line translations, the next
// will be the linkable
_linkableDeclarations[spelling] = Linkable(lines.length, cursor.mangling);
_linkableDeclarations[spelling] = Linkable(_lines.length, cursor.mangling);

return spelling;
}
Expand All @@ -191,7 +187,7 @@ struct Context {
// if there's a name clash, fix it
auto clashingLinkable = name in _linkableDeclarations;
if(clashingLinkable) {
resolveClash(lines[clashingLinkable.lineNumber], name, clashingLinkable.mangling);
resolveClash(_lines[clashingLinkable.lineNumber], name, clashingLinkable.mangling);
}
}
}
Expand All @@ -209,7 +205,7 @@ struct Context {
: spelling;
const renamed = rename(actual, this);
foreach (lineNumber; lineNumbers) {
lines[lineNumber] = lines[lineNumber]
_lines[lineNumber] = _lines[lineNumber]
// Member declaration
.replace(" " ~ actual ~ `;`, " " ~ renamed ~ `;`)
// Pointer declaration
Expand Down Expand Up @@ -246,7 +242,7 @@ struct Context {
because of elaborated names. We remember them here in case we need to fix them.
*/
void rememberField(scope const string spelling) @safe pure {
_fieldDeclarations[spelling] ~= lines.length;
_fieldDeclarations[spelling] ~= _lines.length;
}

/**
Expand Down