From 18453deafb34fcd911195bcebc01ec0bf8bb801f Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Thu, 3 Aug 2017 15:17:35 +0200 Subject: [PATCH] Utils: Cleanup SmallString::replace Improve the naming of the variables. Change-Id: I125f3451e0e6a7437909067e9bff06cbeac111a0 Reviewed-by: Tim Jenssen --- src/libs/utils/smallstring.h | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/libs/utils/smallstring.h b/src/libs/utils/smallstring.h index 467a68f626c..df17b7f30c9 100644 --- a/src/libs/utils/smallstring.h +++ b/src/libs/utils/smallstring.h @@ -866,32 +866,30 @@ private: auto foundIndex = found - begin(); if (found != end()) { - startIndex = foundIndex + fromText.size(); + size_type startNextSearchIndex = foundIndex + fromText.size(); + size_type newSizeDifference = sizeDifference + (toText.size() - fromText.size()); - size_type newSizeDifference = sizeDifference + toText.size() - fromText.size(); - - auto nextFound = replaceLargerSizedRecursive(startIndex, + auto nextFound = replaceLargerSizedRecursive(startNextSearchIndex, fromText, toText, newSizeDifference); - found = begin() + foundIndex; - auto start = begin() + startIndex; - - auto replacedTextEndPosition = found + fromText.size(); - auto replacementTextEndPosition = found + fromText.size() + newSizeDifference; - auto replacementTextStartPosition = found + sizeDifference; + auto startFound = begin() + foundIndex; + auto endOfFound = begin() + startNextSearchIndex; + auto replacedTextEndPosition = endOfFound; + auto replacementTextEndPosition = endOfFound + newSizeDifference; + auto replacementTextStartPosition = startFound + sizeDifference; std::memmove(replacementTextEndPosition.data(), replacedTextEndPosition.data(), - nextFound - start); + std::distance(endOfFound, nextFound)); std::memcpy(replacementTextStartPosition.data(), toText.data(), toText.size()); } else { size_type newSize = size() + sizeDifference; reserve(optimalCapacity(newSize)); setSize(newSize); - *end() = 0; + at(newSize) = 0; } return begin() + foundIndex;