From 3eeb051e40f099342222852bff8b591200a57f90 Mon Sep 17 00:00:00 2001 From: Jakub Staszak Date: Tue, 16 Oct 2012 19:32:31 +0000 Subject: [PATCH] Simplify potentially quadratic behavior while erasing elements from std::vector. llvm-svn: 166045 --- lib/Transforms/Scalar/DCE.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp index 086f0a1a714..8d53443b389 100644 --- a/lib/Transforms/Scalar/DCE.cpp +++ b/lib/Transforms/Scalar/DCE.cpp @@ -118,13 +118,7 @@ bool DCE::runOnFunction(Function &F) { I->eraseFromParent(); // Remove the instruction from the worklist if it still exists in it. - for (std::vector::iterator WI = WorkList.begin(); - WI != WorkList.end(); ) { - if (*WI == I) - WI = WorkList.erase(WI); - else - ++WI; - } + WorkList.erase(std::remove(WorkList.begin(), WorkList.end(), I), WorkList.end()); MadeChange = true; ++DCEEliminated;