Skip to content

Commit

Permalink
Merge pull request #3059 from ibuclaw/cacheispod
Browse files Browse the repository at this point in the history
Cache the returned result of isPOD
  • Loading branch information
yebblies committed Jan 4, 2014
2 parents e8cb0de + 7c618ef commit e9021a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/aggregate.h
Expand Up @@ -42,6 +42,13 @@ enum Sizeok
SIZEOKfwd, // error in computing size of aggregate
};

enum StructPOD
{
ISPODno, // struct is not POD
ISPODyes, // struct is POD
ISPODfwd, // POD not yet computed
};

class AggregateDeclaration : public ScopeDsymbol
{
public:
Expand Down Expand Up @@ -152,6 +159,7 @@ class StructDeclaration : public AggregateDeclaration
static FuncDeclaration *xerrcmp; // object.xopCmp

structalign_t alignment; // alignment applied outside of the struct
StructPOD ispod; // if struct is POD

// For 64 bit Efl function call/return ABI
Type *arg1type;
Expand Down
23 changes: 16 additions & 7 deletions src/struct.c
Expand Up @@ -560,6 +560,7 @@ StructDeclaration::StructDeclaration(Loc loc, Identifier *id)
xeq = NULL;
xcmp = NULL;
alignment = 0;
ispod = ISPODfwd;
arg1type = NULL;
arg2type = NULL;

Expand Down Expand Up @@ -978,7 +979,7 @@ bool StructDeclaration::fill(Loc loc, Expressions *elements, bool ctorinit)
* This is defined as:
* not nested
* no postblits, constructors, destructors, or assignment operators
* no fields with with any of those
* no fields that are themselves non-POD
* The idea being these are compatible with C structs.
*
* Note that D struct constructors can mean POD, since there is always default
Expand All @@ -987,12 +988,16 @@ bool StructDeclaration::fill(Loc loc, Expressions *elements, bool ctorinit)
*/
bool StructDeclaration::isPOD()
{
// If we've already determined whether this struct is POD.
if (ispod != ISPODfwd)
return (ispod == ISPODyes);

ispod = ISPODyes;

if (enclosing || cpctor || postblit || ctor || dtor)
return false;
ispod = ISPODno;

/* Recursively check any fields have a constructor.
* We should cache the results of this.
*/
// Recursively check all fields are POD.
for (size_t i = 0; i < fields.dim; i++)
{
VarDeclaration *v = fields[i];
Expand All @@ -1004,10 +1009,14 @@ bool StructDeclaration::isPOD()
TypeStruct *ts = (TypeStruct *)tv;
StructDeclaration *sd = ts->sym;
if (!sd->isPOD())
return false;
{
ispod = ISPODno;
break;
}
}
}
return true;

return (ispod == ISPODyes);
}

void StructDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
Expand Down

0 comments on commit e9021a5

Please sign in to comment.