Skip to content

Commit

Permalink
Merge pull request #4669 from ibuclaw/cache_mangle
Browse files Browse the repository at this point in the history
Cache mangle string created from mangleExact to prevent multiple calls to C++/D mangle visitors
  • Loading branch information
yebblies committed May 22, 2015
2 parents 2333e38 + 1962c80 commit e2106cb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/declaration.h
Expand Up @@ -514,6 +514,8 @@ class FuncDeclaration : public Declaration
FuncDeclaration *fdrequire; // function that does the in contract
FuncDeclaration *fdensure; // function that does the out contract

const char *mangleString; // mangled symbol created from mangleExact()

Identifier *outId; // identifier for out statement
VarDeclaration *vresult; // variable corresponding to outId
LabelDsymbol *returnLabel; // where the return goes
Expand Down
1 change: 1 addition & 0 deletions src/func.c
Expand Up @@ -289,6 +289,7 @@ FuncDeclaration::FuncDeclaration(Loc loc, Loc endloc, Identifier *id, StorageCla
frequire = NULL;
fdrequire = NULL;
fdensure = NULL;
mangleString = NULL;
outId = NULL;
vresult = NULL;
returnLabel = NULL;
Expand Down
12 changes: 8 additions & 4 deletions src/mangle.c
Expand Up @@ -870,10 +870,14 @@ const char *mangle(Dsymbol *s)
*/
const char *mangleExact(FuncDeclaration *fd)
{
OutBuffer buf;
Mangler v(&buf);
v.mangleExact(fd);
return buf.extractString();
if (!fd->mangleString)
{
OutBuffer buf;
Mangler v(&buf);
v.mangleExact(fd);
fd->mangleString = buf.extractString();
}
return fd->mangleString;
}

void mangleToBuffer(Type *t, OutBuffer *buf)
Expand Down

0 comments on commit e2106cb

Please sign in to comment.