From 1a5b12aa5da2c718848d3cc5d9bce7bfcdeacf54 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 18 Apr 2019 15:13:19 +0200 Subject: optimise find/insert pattern if we're doing a find/insert on a set or a map, it is better to just do a conditional insert/emplace operation than triggering two lookups. Change-Id: I80da5097f5a89fe30fa348ce5b6e747c34287a8d Reviewed-on: https://gerrit.libreoffice.org/70937 Tested-by: Jenkins Reviewed-by: Noel Grandin --- compilerplugins/clang/cstylecast.cxx | 6 ++---- compilerplugins/clang/memoryvar.cxx | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'compilerplugins') diff --git a/compilerplugins/clang/cstylecast.cxx b/compilerplugins/clang/cstylecast.cxx index 253f19ef651c..fe3b2a19c561 100644 --- a/compilerplugins/clang/cstylecast.cxx +++ b/compilerplugins/clang/cstylecast.cxx @@ -603,8 +603,7 @@ bool CStyleCast::rewriteArithmeticCast(CStyleCastExpr const * expr, char const * secondBegin = l; ++secondLen; } - if (rewritten_.find(firstBegin) == rewritten_.end()) { - rewritten_.insert(firstBegin); + if (rewritten_.insert(firstBegin).second) { if (!replaceText(firstBegin, firstLen, functional ? "" : "static_cast<")) { if (isDebugMode()) { report( @@ -630,8 +629,7 @@ bool CStyleCast::rewriteArithmeticCast(CStyleCastExpr const * expr, char const * } } if (third.isValid()) { - if (rewritten_.find(third) == rewritten_.end()) { - rewritten_.insert(third); + if (rewritten_.insert(third).second) { if (!insertTextBefore(third, "(")) { //TODO: roll back if (isDebugMode()) { diff --git a/compilerplugins/clang/memoryvar.cxx b/compilerplugins/clang/memoryvar.cxx index d3842f4f3eb5..9cd723cf2bf8 100644 --- a/compilerplugins/clang/memoryvar.cxx +++ b/compilerplugins/clang/memoryvar.cxx @@ -130,8 +130,7 @@ bool MemoryVar::VisitCXXDeleteExpr(const CXXDeleteExpr *deleteExpr) SourceLocation loc = varDecl->getLocation(); - if (maVarUsesSet.find(loc) == maVarUsesSet.end()) { - maVarUsesSet.insert(loc); + if (maVarUsesSet.insert(loc).second) { maVarDeclSourceRangeMap[loc] = varDecl->getSourceRange(); maVarDeleteSourceRangeMap[loc] = declRefExpr->getSourceRange(); } -- cgit