Skip to content

Commit

Permalink
Merge pull request #234 from Pugemon/optimize-1
Browse files Browse the repository at this point in the history
Optimize container insertions using emplace_back instead of push_back
  • Loading branch information
MihailRis authored Jun 7, 2024
2 parents 1b3dee4 + e98fb9a commit 9fc6d2c
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/audio/AL/ALAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ std::vector<std::string> ALAudio::getAvailableDevices() const {

const char* ptr = devices;
do {
devicesVec.push_back(std::string(ptr));
devicesVec.emplace_back(ptr);
ptr += devicesVec.back().size() + 1;
}
while (ptr[0]);
Expand Down
4 changes: 2 additions & 2 deletions src/content/ContentLUT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ContentLUT::ContentLUT(const Content* content, size_t blocksCount, size_t itemsC
blockNames.push_back(indices->getBlockDef(i)->name);
}
for (size_t i = indices->countBlockDefs(); i < blocksCount; i++) {
blockNames.push_back("");
blockNames.emplace_back("");
}

for (size_t i = 0; i < itemsCount; i++) {
Expand All @@ -29,7 +29,7 @@ ContentLUT::ContentLUT(const Content* content, size_t blocksCount, size_t itemsC
itemNames.push_back(indices->getItemDef(i)->name);
}
for (size_t i = indices->countItemDefs(); i < itemsCount; i++) {
itemNames.push_back("");
itemNames.emplace_back();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/content/ContentLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void ContentLoader::loadCustomBlockModel(Block& def, dynamic::Map* primitives) {
}
else
for (uint j = 6; j < 12; j++) {
def.modelTextures.push_back("notfound");
def.modelTextures.emplace_back("notfound");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ void Hud::add(const HudElement& element) {
if (document) {
auto inventory = invview ? invview->getInventory() : nullptr;
std::vector<Value> args;
args.push_back(inventory ? inventory.get()->getId() : 0);
args.emplace_back(inventory ? inventory.get()->getId() : 0);
for (int i = 0; i < 3; i++) {
args.push_back(static_cast<integer_t>(blockPos[i]));
args.emplace_back(static_cast<integer_t>(blockPos[i]));
}
scripting::on_ui_open(
element.getDocument(),
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ gui::page_loader_func menus::create_page_loader(Engine* engine) {
auto value = std::string(parser.readUntil('&'));
map->put(key, value);
}
args.push_back(map);
args.emplace_back(map);
} else {
name = query;
}
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/ui/gui_xml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ static std::shared_ptr<UINode> readPageBox(UiXmlReader& reader, const xml::xmlel
}

UiXmlReader::UiXmlReader(const scriptenv& env) : env(env) {
contextStack.push("");
contextStack.emplace("");
add("image", readImage);
add("label", readLabel);
add("panel", readPanel);
Expand Down
2 changes: 1 addition & 1 deletion src/items/Inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void Inventory::deserialize(dynamic::Map* src) {
auto slotsarr = src->list("slots");
size_t slotscount = slotsarr->size();
while (slots.size() < slotscount) {
slots.push_back(ItemStack());
slots.emplace_back();
}
for (size_t i = 0; i < slotscount; i++) {
auto item = slotsarr->map(i);
Expand Down
4 changes: 2 additions & 2 deletions src/logic/scripting/lua/libcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static int l_reconfig_packs(lua_State* L) {
int addLen = lua_objlen(L, 1);
for (int i = 0; i < addLen; i++) {
lua_rawgeti(L, 1, i+1);
addPacks.push_back(lua_tostring(L, -1));
addPacks.emplace_back(lua_tostring(L, -1));
lua_pop(L, 1);
}

Expand All @@ -92,7 +92,7 @@ static int l_reconfig_packs(lua_State* L) {
int remLen = lua_objlen(L, 2);
for (int i = 0; i < remLen; i++) {
lua_rawgeti(L, 2, i+1);
remPacks.push_back(lua_tostring(L, -1));
remPacks.emplace_back(lua_tostring(L, -1));
lua_pop(L, 1);
}
auto controller = scripting::engine->getController();
Expand Down
4 changes: 2 additions & 2 deletions src/util/stringutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ std::vector<std::string> util::split(const std::string& str, char delimiter) {
result.push_back(tmp);
}
if (result.empty()) {
result.push_back("");
result.emplace_back("");
}
return result;
}
Expand All @@ -420,7 +420,7 @@ std::vector<std::wstring> util::split(const std::wstring& str, char delimiter) {
result.push_back(tmp);
}
if (result.empty()) {
result.push_back(L"");
result.emplace_back(L"");
}
return result;
}
Expand Down

0 comments on commit 9fc6d2c

Please sign in to comment.