AstGen: avoid multiple dbg_stmt instructions in a row

This is purely an optimization to emit fewer ZIR instructions.
This commit is contained in:
Andrew Kelley 2022-08-08 20:29:22 -07:00
parent 3389890709
commit 0648177ed7

View File

@ -3071,6 +3071,19 @@ fn emitDbgNode(gz: *GenZir, node: Ast.Node.Index) !void {
const line = astgen.source_line - gz.decl_line;
const column = astgen.source_column;
if (gz.instructions.items.len > 0) {
const last = gz.instructions.items[gz.instructions.items.len - 1];
const zir_tags = astgen.instructions.items(.tag);
if (zir_tags[last] == .dbg_stmt) {
const zir_datas = astgen.instructions.items(.data);
zir_datas[last].dbg_stmt = .{
.line = line,
.column = column,
};
return;
}
}
_ = try gz.add(.{ .tag = .dbg_stmt, .data = .{
.dbg_stmt = .{
.line = line,