Skip to content

Commit

Permalink
Cache mangle string created from mangleExact to prevent multiple call…
Browse files Browse the repository at this point in the history
…s to C++/D mangle visitors
  • Loading branch information
ibuclaw committed May 20, 2015
1 parent d872b5a commit 1962c80
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 1962c80

Please sign in to comment.