Browse Source

cmGeneratorExpression: Use std::move to avoid vector copies

Use move semantics in GeneratorExpressionContent::SetIdentifier and
::SetParameters to avoid vector copies.
Frank Winklmeier 7 years ago
parent
commit
46436581c6
2 changed files with 10 additions and 9 deletions
  1. 6 6
      Source/cmGeneratorExpressionEvaluator.h
  2. 4 3
      Source/cmGeneratorExpressionParser.cxx

+ 6 - 6
Source/cmGeneratorExpressionEvaluator.h

@@ -7,6 +7,7 @@
 
 #include <stddef.h>
 #include <string>
+#include <utility>
 #include <vector>
 
 struct cmGeneratorExpressionContext;
@@ -64,17 +65,16 @@ private:
 struct GeneratorExpressionContent : public cmGeneratorExpressionEvaluator
 {
   GeneratorExpressionContent(const char* startContent, size_t length);
-  void SetIdentifier(
-    std::vector<cmGeneratorExpressionEvaluator*> const& identifier)
+
+  void SetIdentifier(std::vector<cmGeneratorExpressionEvaluator*> identifier)
   {
-    this->IdentifierChildren = identifier;
+    this->IdentifierChildren = std::move(identifier);
   }
 
   void SetParameters(
-    std::vector<std::vector<cmGeneratorExpressionEvaluator*>> const&
-      parameters)
+    std::vector<std::vector<cmGeneratorExpressionEvaluator*>> parameters)
   {
-    this->ParamChildren = parameters;
+    this->ParamChildren = std::move(parameters);
   }
 
   Type GetType() const override

+ 4 - 3
Source/cmGeneratorExpressionParser.cxx

@@ -6,6 +6,7 @@
 
 #include <assert.h>
 #include <stddef.h>
+#include <utility>
 
 cmGeneratorExpressionParser::cmGeneratorExpressionParser(
   const std::vector<cmGeneratorExpressionToken>& tokens)
@@ -92,7 +93,7 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression(
     assert(this->it != this->Tokens.end());
     ++this->it;
     --this->NestingLevel;
-    content->SetIdentifier(identifier);
+    content->SetIdentifier(std::move(identifier));
     result.push_back(content);
     return;
   }
@@ -198,8 +199,8 @@ void cmGeneratorExpressionParser::ParseGeneratorExpression(
     ((this->it - 1)->Content - startToken->Content) + (this->it - 1)->Length;
   GeneratorExpressionContent* content =
     new GeneratorExpressionContent(startToken->Content, contentLength);
-  content->SetIdentifier(identifier);
-  content->SetParameters(parameters);
+  content->SetIdentifier(std::move(identifier));
+  content->SetParameters(std::move(parameters));
   result.push_back(content);
 }