Skip to content

Commit

Permalink
Optimize: Don't have to make initializer for zero-size field in struct
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jun 15, 2015
1 parent 5d70b1a commit ae2cd8c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -7870,7 +7870,7 @@ Expression *TypeStruct::defaultInitLiteral(Loc loc)
error(loc, "circular reference to '%s'", vd->toPrettyChars());
return new ErrorExp();
}
if (vd->offset < offset)
if (vd->offset < offset || vd->type->size() == 0)
e = NULL;
else if (vd->init)
{
Expand Down
6 changes: 5 additions & 1 deletion src/struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,11 @@ bool StructDeclaration::fill(Loc loc, Expressions *elements, bool ctorinit)
if (elements && vx)
{
Expression *e;
if (vx->init)
if (vx->type->size() == 0)
{
e = NULL;
}
else if (vx->init)
{
assert(!vx->init->isVoidInitializer());
e = vx->getConstInitializer(false);
Expand Down

0 comments on commit ae2cd8c

Please sign in to comment.