From c70748e1d69dbcbdfb80a01c245b8f9404fa655d Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <github@naumov.de>
Date: Sat, 15 Jul 2023 16:40:11 +0200
Subject: [PATCH] [BL] Use std::string::replace instead of substr +

This is more efficient.
---
 BaseLib/FileTools.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/BaseLib/FileTools.cpp b/BaseLib/FileTools.cpp
index fabf7b3da65..e5145ffc74f 100644
--- a/BaseLib/FileTools.cpp
+++ b/BaseLib/FileTools.cpp
@@ -111,9 +111,10 @@ bool substituteKeyword(std::string& result, std::string& parenthesized_string,
     std::string const generated_fmt_string =
         "{" + precision_specification +
         type_specification[std::type_index(typeid(data))] + "}";
-    result = result.substr(0, begin) +
-             fmt::vformat(generated_fmt_string, fmt::make_format_args(data)) +
-             result.substr(end + 1, result.length() - (end + 1));
+    result.replace(
+        begin, end - begin + 1,
+        fmt::vformat(generated_fmt_string, fmt::make_format_args(data)));
+
     return true;
 }
 
-- 
GitLab