Skip to content

Commit 9e6a6a9

Browse files
Replace push_back with emplace_back to avoid unnecessary temporary construction and slightly improve performance.
1 parent 033391a commit 9e6a6a9

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,9 @@ Aws::Vector<Aws::String> calculateAuthPreferences() {
196196
Aws::Vector<Aws::String> res;
197197
auto prefs = Aws::Environment::GetEnv("AWS_AUTH_SCHEME_PREFERENCE");
198198
Aws::Vector<Aws::String> prefsList = Aws::Utils::StringUtils::Split(prefs, ',');
199+
res.reserve(prefsList.size()); // avoid repeated allocations
199200
for (auto& pref : prefsList) {
200-
res.push_back(Aws::Utils::StringUtils::Trim(pref.c_str()));
201+
res.emplace_back(Aws::Utils::StringUtils::Trim(pref.c_str()));
201202
}
202203
return res;
203204
}

src/aws-cpp-sdk-text-to-speech/source/text-to-speech/TextToSpeechManager.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ namespace Aws
9393
for (auto& deviceInfo : driver->EnumerateDevices())
9494
{
9595
AWS_LOGSTREAM_DEBUG(CLASS_TAG, "Adding device " << deviceInfo.deviceName << " for driver " << driver->GetName());
96-
OutputDevicePair device(deviceInfo, driver);
97-
deviceDriverList.push_back(device);
96+
deviceDriverList.emplace_back(deviceInfo, driver);
9897
}
9998
}
10099

@@ -120,9 +119,11 @@ namespace Aws
120119
auto voicesOutcome = m_pollyClient->DescribeVoices(describeVoices);
121120
if (voicesOutcome.IsSuccess())
122121
{
123-
for (auto& voice : voicesOutcome.GetResult().GetVoices())
122+
auto& voices = voicesOutcome.GetResult().GetVoices();
123+
m_voices.reserve(voices.size());
124+
for (const auto& voice : voices)
124125
{
125-
m_voices.push_back(std::pair<Aws::String, Aws::String>(voice.GetName(), voice.GetLanguageName()));
126+
m_voices.emplace_back(voice.GetName(), voice.GetLanguageName());
126127
}
127128
}
128129
else

0 commit comments

Comments
 (0)