Skip to content

Commit

Permalink
Fix usage of push_back vs emplace_back
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Jan 16, 2025
1 parent 77ce195 commit 7767f7b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/config/internal/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace OpenShock::Config::Internal::Utils {
for (auto fbsItem : *fbsVec) {
T item;
if (item.FromFlatbuffers(fbsItem)) {
vec.emplace_back(std::move(item));
vec.push_back(std::move(item));
}
}
}
Expand Down Expand Up @@ -77,7 +77,7 @@ namespace OpenShock::Config::Internal::Utils {
{
T item;
if (item.FromJSON(jsonItem)) {
vec.emplace_back(std::move(item));
vec.push_back(std::move(item));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/config/WiFiConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ flatbuffers::Offset<OpenShock::Serialization::Configuration::WiFiConfig> WiFiCon
fbsCredentialsList.reserve(credentialsList.size());

for (auto& credentials : credentialsList) {
fbsCredentialsList.emplace_back(credentials.ToFlatbuffers(builder, withSensitiveData));
fbsCredentialsList.push_back(credentials.ToFlatbuffers(builder, withSensitiveData));
}

return Serialization::Configuration::CreateWiFiConfig(builder, builder.CreateString(accessPointSSID), builder.CreateString(hostname), builder.CreateVector(fbsCredentialsList));
Expand Down
2 changes: 1 addition & 1 deletion src/serial/command_handlers/networks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void _handleNetworksCommand(std::string_view arg, bool isAutomated)

OS_LOGI(TAG, "Adding network \"%s\" to config, id=%u", cred.ssid.c_str(), cred.id);

creds.emplace_back(std::move(cred));
creds.push_back(std::move(cred));
}

if (!OpenShock::Config::SetWiFiCredentials(creds)) {
Expand Down
4 changes: 2 additions & 2 deletions src/util/StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ std::vector<std::string_view> OpenShock::StringSplit(std::string_view view, bool
for (const char* ptr = view.begin(); ptr < view.end(); ++ptr) {
if (predicate(*ptr)) {
if (start != nullptr) {
result.emplace_back(std::string_view(start, ptr - start));
result.emplace_back(start, ptr - start);
start = nullptr;
}
} else if (start == nullptr) {
Expand All @@ -105,7 +105,7 @@ std::vector<std::string_view> OpenShock::StringSplit(std::string_view view, bool
}

if (start != nullptr) {
result.emplace_back(std::string_view(start, view.end() - start));
result.emplace_back(start, view.end() - start);
}

return result;
Expand Down

0 comments on commit 7767f7b

Please # to comment.