Optimize container insertions using emplace_back instead of push_back
This commit is contained in:
parent
f25a425cb9
commit
e98fb9a1a7
@ -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]);
|
||||
|
||||
@ -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++) {
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user