From 1962c80ea8f90d6ed69ca93c6ffa40e5aa43626f Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Sun, 17 May 2015 11:46:19 +0200 Subject: [PATCH] Cache mangle string created from mangleExact to prevent multiple calls to C++/D mangle visitors --- src/declaration.h | 2 ++ src/func.c | 1 + src/mangle.c | 12 ++++++++---- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/declaration.h b/src/declaration.h index 3814a2ebfef1..c03086317ff2 100644 --- a/src/declaration.h +++ b/src/declaration.h @@ -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 diff --git a/src/func.c b/src/func.c index 78021f59a2b7..1bc03757ad78 100644 --- a/src/func.c +++ b/src/func.c @@ -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; diff --git a/src/mangle.c b/src/mangle.c index 6890a2cd5f00..e448a68ab452 100644 --- a/src/mangle.c +++ b/src/mangle.c @@ -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)