Skip to content

Commit

Permalink
Preprocessor: clear temporary buffers after preprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas committed Feb 9, 2024
1 parent 58c2ba4 commit f21caa8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/aro/Hideset.zig
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ pub fn clearRetainingCapacity(self: *Hideset) void {
self.map.clearRetainingCapacity();
}

pub fn clearAndFree(self: *Hideset) void {
self.map.clearAndFree(self.comp.gpa);
self.intersection_map.clearAndFree(self.comp.gpa);
self.linked_list.shrinkAndFree(self.comp.gpa, 0);
}

/// Iterator is invalidated if the underlying MultiArrayList slice is reallocated due to resize
fn iterator(self: *const Hideset, idx: Index) Iterator {
return Iterator{
Expand Down
9 changes: 9 additions & 0 deletions src/aro/Preprocessor.zig
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ pub fn deinit(pp: *Preprocessor) void {
pp.expansion_entries.deinit(pp.gpa);
}

/// Free buffers that are not needed after preprocessing
fn clearBuffers(pp: *Preprocessor) void {
pp.token_buf.clearAndFree();
pp.char_buf.clearAndFree();
pp.top_expansion_buf.clearAndFree();
pp.hideset.clearAndFree();
}

pub fn expansionSlice(pp: *Preprocessor, tok: Tree.TokenIndex) []Source.Location {
const S = struct {
fn order_token_index(context: void, lhs: Tree.TokenIndex, rhs: Tree.TokenIndex) std.math.Order {
Expand Down Expand Up @@ -283,6 +291,7 @@ pub fn preprocessSources(pp: *Preprocessor, sources: []const Source) Error!void
try pp.addIncludeResume(first.id, 0, 1);
const eof = try pp.preprocess(first);
try pp.addToken(eof);
pp.clearBuffers();
}

/// Preprocess a source file, returns eof token.
Expand Down

0 comments on commit f21caa8

Please sign in to comment.