From 5554910ec2573282a85e61736e96f48e5f550066 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Mon, 10 Feb 2014 01:39:33 -0500 Subject: [PATCH] cmSourceFileLocation: Avoid string allocation in extension checking The substr call was causing excess allocations. Swap the cheaper character check to be before the longer string comparison, now using the prefix checking function. --- Source/cmSourceFileLocation.cxx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/cmSourceFileLocation.cxx b/Source/cmSourceFileLocation.cxx index c05020236..9c0b2c524 100644 --- a/Source/cmSourceFileLocation.cxx +++ b/Source/cmSourceFileLocation.cxx @@ -183,8 +183,9 @@ cmSourceFileLocation // Check if loc's name could possibly be extended to our name by // adding an extension. if(!(this->Name.size() > loc.Name.size() && - this->Name.substr(0, loc.Name.size()) == loc.Name && - this->Name[loc.Name.size()] == '.')) + this->Name[loc.Name.size()] == '.' && + cmHasLiteralPrefixImpl(this->Name.c_str(), + loc.Name.c_str(), loc.Name.size()))) { return false; }