diff --git a/SystemTools.cxx b/SystemTools.cxx
index 53cd02cc59a286ef5265f422eeafca8f8b4beb73..2be4c988d52cffd36130b6f4958e2bda4f79c1e2 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -3200,6 +3200,7 @@ std::string SystemTools::CollapseFullPath(const std::string& in_path,
   // Split the input path components.
   std::vector<std::string> path_components;
   SystemTools::SplitPath(in_path, path_components);
+  out_components.reserve(path_components.size());
 
   // If the input path is relative, start with a base path.
   if (path_components[0].empty()) {
@@ -3262,6 +3263,7 @@ std::string SystemTools::CollapseFullPath(const std::string& in_path,
   // Split the input path components.
   std::vector<std::string> path_components;
   SystemTools::SplitPath(in_path, path_components);
+  out_components.reserve(path_components.size());
 
   // If the input path is relative, start with a base path.
   if (path_components[0].length() == 0) {