From 9e6a6a9104ff7fd0797f82fbf4097beb45a801cb Mon Sep 17 00:00:00 2001 From: rajanyadav0307 Date: Thu, 18 Dec 2025 12:25:03 -0600 Subject: [PATCH] Replace push_back with emplace_back to avoid unnecessary temporary construction and slightly improve performance. --- .../source/client/ClientConfiguration.cpp | 3 ++- .../source/text-to-speech/TextToSpeechManager.cpp | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp b/src/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp index fe21ba5de11..3b38c3a2b33 100644 --- a/src/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp +++ b/src/aws-cpp-sdk-core/source/client/ClientConfiguration.cpp @@ -196,8 +196,9 @@ Aws::Vector calculateAuthPreferences() { Aws::Vector res; auto prefs = Aws::Environment::GetEnv("AWS_AUTH_SCHEME_PREFERENCE"); Aws::Vector prefsList = Aws::Utils::StringUtils::Split(prefs, ','); + res.reserve(prefsList.size()); // avoid repeated allocations for (auto& pref : prefsList) { - res.push_back(Aws::Utils::StringUtils::Trim(pref.c_str())); + res.emplace_back(Aws::Utils::StringUtils::Trim(pref.c_str())); } return res; } diff --git a/src/aws-cpp-sdk-text-to-speech/source/text-to-speech/TextToSpeechManager.cpp b/src/aws-cpp-sdk-text-to-speech/source/text-to-speech/TextToSpeechManager.cpp index dcff692c06a..0cfa83411f8 100644 --- a/src/aws-cpp-sdk-text-to-speech/source/text-to-speech/TextToSpeechManager.cpp +++ b/src/aws-cpp-sdk-text-to-speech/source/text-to-speech/TextToSpeechManager.cpp @@ -93,8 +93,7 @@ namespace Aws for (auto& deviceInfo : driver->EnumerateDevices()) { AWS_LOGSTREAM_DEBUG(CLASS_TAG, "Adding device " << deviceInfo.deviceName << " for driver " << driver->GetName()); - OutputDevicePair device(deviceInfo, driver); - deviceDriverList.push_back(device); + deviceDriverList.emplace_back(deviceInfo, driver); } } @@ -120,9 +119,11 @@ namespace Aws auto voicesOutcome = m_pollyClient->DescribeVoices(describeVoices); if (voicesOutcome.IsSuccess()) { - for (auto& voice : voicesOutcome.GetResult().GetVoices()) + auto& voices = voicesOutcome.GetResult().GetVoices(); + m_voices.reserve(voices.size()); + for (const auto& voice : voices) { - m_voices.push_back(std::pair(voice.GetName(), voice.GetLanguageName())); + m_voices.emplace_back(voice.GetName(), voice.GetLanguageName()); } } else