Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: change shared_ptrs from copy to reference #2863

Open
wants to merge 61 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
655ec2d
init
beats-dh Jul 28, 2024
470cc87
up
beats-dh Jul 30, 2024
37aa37c
test
beats-dh Jul 31, 2024
4053cf8
improve
beats-dh Aug 1, 2024
ef024cb
fix crash
beats-dh Aug 2, 2024
5042d46
up
beats-dh Aug 4, 2024
c74a062
?
beats-dh Aug 15, 2024
c1d38ce
fix warnig and ative SIMD
beats-dh Aug 16, 2024
3219358
fix crash
beats-dh Aug 17, 2024
a1eca9c
test
beats-dh Aug 17, 2024
0b985aa
improve
beats-dh Aug 18, 2024
e399679
init
beats-dh Aug 17, 2024
ec43734
test
beats-dh Aug 24, 2024
e108c96
teste
beats-dh Aug 27, 2024
bd821b8
Update events.cpp
beats-dh Aug 29, 2024
c5a2b08
remove opemtelemetry lib metrics off
beats-dh Aug 30, 2024
b735dc1
Code format - (Clang-format)
github-actions[bot] Aug 31, 2024
467210d
Update qodana.yml
beats-dh Aug 31, 2024
87714c7
update
beats-dh Sep 1, 2024
a927fc3
update
beats-dh Sep 1, 2024
555c59a
fix exploit login
beats-dh Sep 1, 2024
727ffd6
update
beats-dh Sep 2, 2024
082eb72
update 07/09/2024
beats-dh Sep 8, 2024
8ff19f3
add atomic-queue connection
beats-dh Sep 11, 2024
bd4ef8b
update avx2 encrypt, decrypt and fix crash convertIP function
beats-dh Sep 11, 2024
486e880
update player online cycle
beats-dh Sep 11, 2024
2e4c0e7
fix crash
beats-dh Sep 11, 2024
429bccf
remove SIMD condition
beats-dh Sep 12, 2024
09ee5aa
new use atomic_queue in getOutputMessage
beats-dh Sep 13, 2024
9211e68
restore changes
beats-dh Sep 14, 2024
304b93d
up
beats-dh Sep 14, 2024
ff9ea35
up
beats-dh Sep 16, 2024
0480fda
up
beats-dh Sep 17, 2024
c876ec8
Code format - (Clang-format)
github-actions[bot] Sep 19, 2024
67575ab
up
beats-dh Sep 25, 2024
03dca05
fix build
beats-dh Sep 28, 2024
7d43c43
Code format - (Clang-format)
github-actions[bot] Sep 28, 2024
d68524c
fix
beats-dh Sep 29, 2024
e05caee
fix build
beats-dh Sep 29, 2024
14433a6
up
beats-dh Oct 1, 2024
dad1025
fix: some reverts and adjustments
dudantas Oct 16, 2024
edbfb8f
Merge branch 'main' into beats-fixs
dudantas Oct 16, 2024
174a763
fix: compilation errors conflicts
dudantas Oct 16, 2024
6e10a67
feat: some adjustments
dudantas Oct 16, 2024
b0d8af6
feat: some reverts
dudantas Oct 16, 2024
81eb200
fix
beats-dh Oct 17, 2024
e1fe506
feat: convert SpawnMonster to shared_ptr
dudantas Oct 17, 2024
f3caa03
fix: client debug
dudantas Oct 17, 2024
35f07c9
improve: some reverts and adjustments
dudantas Oct 17, 2024
9c89b04
improve: some reverts and others shared_ptr to const reference
dudantas Oct 17, 2024
71599eb
improve: change filestream/fileloader to std::ranges::copy
dudantas Oct 17, 2024
77449e0
fix: revert wrong
dudantas Oct 17, 2024
9c67268
Merge branch 'main' into beats-fixs
dudantas Oct 18, 2024
2979ca2
Merge branch 'main' into beats-fixs
dudantas Oct 18, 2024
7e4b62d
fix: sonar check and enum forward declaration
dudantas Oct 18, 2024
4021fdf
improve: fix some sonar check and ubuntu compilation
dudantas Oct 18, 2024
e3a924e
Code format - (Clang-format)
github-actions[bot] Oct 18, 2024
fb8c8a4
fix: some sonar checks
dudantas Oct 18, 2024
a49ce33
fix: sonar
dudantas Oct 18, 2024
652b969
Merge branch 'main' into beats-fixs
beats-dh Oct 31, 2024
668528e
Merge branch 'main' into beats-fixs
dudantas Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve: some reverts and others shared_ptr to const reference
  • Loading branch information
dudantas committed Oct 17, 2024
commit 9c89b045805a7abf72554b200cc05a8342848d4e
2 changes: 1 addition & 1 deletion src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ void Combat::combatTileEffects(const CreatureVector &spectators, const std::shar
}
}

const auto item = Item::CreateItem(itemId);
const auto &item = Item::CreateItem(itemId);
if (caster) {
item->setOwner(caster);
}
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1876,7 +1876,7 @@ bool ConditionFeared::getRandomDirection(const std::shared_ptr<Creature> &creatu

std::ranges::shuffle(directions, getRandomGenerator());

const auto &it = std::ranges::find_if(directions, [&](Direction dir) {
auto it = std::ranges::find_if(directions, [&](Direction dir) {
return canWalkTo(creature, pos, dir);
});

Expand Down
15 changes: 6 additions & 9 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ bool Creature::setMaster(const std::shared_ptr<Creature> &newMaster, bool reload
m_master = newMaster;

if (oldMaster) {
const auto &it = std::ranges::find(oldMaster->m_summons, self);
auto it = std::ranges::find(oldMaster->m_summons, self);
if (it != oldMaster->m_summons.end()) {
oldMaster->m_summons.erase(it);
}
Expand Down Expand Up @@ -1640,20 +1640,17 @@ bool Creature::unregisterCreatureEvent(const std::string &name) {

bool resetTypeBit = true;

auto it = eventsList.begin();
const auto end = eventsList.end();
while (it != end) {
const auto &curEvent = *it;
std::erase_if(eventsList, [&](const auto &curEvent) {
if (curEvent == event) {
it = eventsList.erase(it);
continue;
return true;
}

if (curEvent->getEventType() == type) {
resetTypeBit = false;
}
++it;
}

return false;
});

if (resetTypeBit) {
scriptEventsBitField &= ~(static_cast<uint32_t>(1) << type);
Expand Down
10 changes: 5 additions & 5 deletions src/creatures/interactions/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ std::shared_ptr<ChatChannel> Chat::getChannel(const std::shared_ptr<Player> &pla
case CHANNEL_GUILD: {
const auto &guild = player->getGuild();
if (guild != nullptr) {
const auto &it = guildChannels.find(guild->getId());
auto it = guildChannels.find(guild->getId());
if (it != guildChannels.end()) {
return it->second;
}
Expand All @@ -616,7 +616,7 @@ std::shared_ptr<ChatChannel> Chat::getChannel(const std::shared_ptr<Player> &pla
case CHANNEL_PARTY: {
const auto &party = player->getParty();
if (party != nullptr) {
const auto &it = partyChannels.find(party);
auto it = partyChannels.find(party);
if (it != partyChannels.end()) {
return it->second;
}
Expand All @@ -625,7 +625,7 @@ std::shared_ptr<ChatChannel> Chat::getChannel(const std::shared_ptr<Player> &pla
}

default: {
const auto &it = normalChannels.find(channelId);
auto it = normalChannels.find(channelId);
if (it != normalChannels.end()) {
const auto &channel = it->second;
if (!channel->executeCanJoinEvent(player)) {
Expand All @@ -645,15 +645,15 @@ std::shared_ptr<ChatChannel> Chat::getChannel(const std::shared_ptr<Player> &pla
}

std::shared_ptr<ChatChannel> Chat::getGuildChannelById(uint32_t guildId) {
const auto &it = guildChannels.find(guildId);
auto it = guildChannels.find(guildId);
if (it == guildChannels.end()) {
return nullptr;
}
return it->second;
}

std::shared_ptr<ChatChannel> Chat::getChannelById(uint16_t channelId) {
const auto &it = normalChannels.find(channelId);
auto it = normalChannels.find(channelId);
if (it == normalChannels.end()) {
return nullptr;
}
Expand Down
12 changes: 6 additions & 6 deletions src/creatures/monsters/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ double_t Monster::getReflectPercent(CombatType_t reflectType, bool useCharges) c
if (result != 0) {
g_logger().debug("[{}] before mtype reflect element {}, percent {}", __FUNCTION__, fmt::underlying(reflectType), result);
}
const auto &it = mType->info.reflectMap.find(reflectType);
auto it = mType->info.reflectMap.find(reflectType);
if (it != mType->info.reflectMap.end()) {
result += it->second;
}
Expand Down Expand Up @@ -157,7 +157,7 @@ void Monster::addDefense(int32_t defense) {
}

uint32_t Monster::getHealingCombatValue(CombatType_t healingType) const {
const auto &it = mType->info.healingMap.find(healingType);
auto it = mType->info.healingMap.find(healingType);
if (it != mType->info.healingMap.end()) {
return it->second;
}
Expand Down Expand Up @@ -430,7 +430,7 @@ bool Monster::addTarget(const std::shared_ptr<Creature> &creature, bool pushFron

assert(creature != getMonster());

const auto &it = getTargetIterator(creature);
auto it = getTargetIterator(creature);
if (it != targetList.end()) {
return false;
}
Expand All @@ -453,7 +453,7 @@ bool Monster::removeTarget(const std::shared_ptr<Creature> &creature) {
return false;
}

const auto &it = getTargetIterator(creature);
auto it = getTargetIterator(creature);
if (it == targetList.end()) {
return false;
}
Expand Down Expand Up @@ -781,7 +781,7 @@ bool Monster::selectTarget(const std::shared_ptr<Creature> &creature) {
return false;
}

const auto &it = getTargetIterator(creature);
auto it = getTargetIterator(creature);
if (it == targetList.end()) {
// Target not found in our target list.
return false;
Expand Down Expand Up @@ -842,7 +842,7 @@ void Monster::onAddCondition(ConditionType_t type) {
onConditionStatusChange(type);
}

void Monster::onConditionStatusChange(const ConditionType_t &type) {
void Monster::onConditionStatusChange(ConditionType_t type) {
if (type == CONDITION_FIRE || type == CONDITION_ENERGY || type == CONDITION_POISON) {
updateMapCache();
}
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/monsters/monster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,5 +496,5 @@ class Monster final : public Creature {
void doFollowCreature(uint32_t &flags, Direction &nextDirection, bool &result);
void doRandomStep(Direction &nextDirection, bool &result);

void onConditionStatusChange(const ConditionType_t &type);
void onConditionStatusChange(ConditionType_t type);
};
4 changes: 2 additions & 2 deletions src/creatures/monsters/monsters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ bool MonsterType::loadCallback(LuaScriptInterface* scriptInterface) {

std::shared_ptr<MonsterType> Monsters::getMonsterType(const std::string &name, bool silent /* = false*/) const {
std::string lowerCaseName = asLowerCaseString(name);
if (const auto &it = monsters.find(lowerCaseName);
if (auto it = monsters.find(lowerCaseName);
it != monsters.end()
// We will only return the MonsterType if it match the exact name of the monster
&& it->first.find(lowerCaseName) != std::basic_string<char>::npos) {
Expand All @@ -328,7 +328,7 @@ std::shared_ptr<MonsterType> Monsters::getMonsterTypeByRaceId(uint16_t raceId, b
}

const auto &monster_race_map = g_game().getBestiaryList();
const auto &it = monster_race_map.find(raceId);
auto it = monster_race_map.find(raceId);
if (it == monster_race_map.end()) {
return nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/npcs/npc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Npc final : public Creature {

const std::vector<ShopBlock> &getShopItemVector(uint32_t playerGUID) const {
if (playerGUID != 0) {
const auto &it = shopPlayers.find(playerGUID);
auto it = shopPlayers.find(playerGUID);
if (it != shopPlayers.end() && !it->second.empty()) {
return it->second;
}
Expand Down Expand Up @@ -137,7 +137,7 @@ class Npc final : public Creature {
}

bool isPlayerInteractingOnTopic(uint32_t playerId, uint16_t topicId) {
const auto &it = playerInteractions.find(playerId);
auto it = playerInteractions.find(playerId);
if (it == playerInteractions.end()) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/npcs/npcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ bool Npcs::reload() {

std::shared_ptr<NpcType> Npcs::getNpcType(const std::string &name, bool create /* = false*/) {
const std::string key = asLowerCaseString(name);
const auto &it = npcs.find(key);
auto it = npcs.find(key);

if (it != npcs.end()) {
return it->second;
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/players/achievement/player_achievement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool PlayerAchievement::remove(uint16_t id) {
return false;
}

if (const auto &it = std::ranges::find_if(m_achievementsUnlocked, [id](auto achievement_it) {
if (auto it = std::ranges::find_if(m_achievementsUnlocked, [id](auto achievement_it) {
return achievement_it.first == id;
});
it != m_achievementsUnlocked.end()) {
Expand All @@ -67,7 +67,7 @@ bool PlayerAchievement::isUnlocked(uint16_t id) const {
return false;
}

if (const auto &it = std::ranges::find_if(m_achievementsUnlocked, [id](auto achievement_it) {
if (auto it = std::ranges::find_if(m_achievementsUnlocked, [id](auto achievement_it) {
return achievement_it.first == id;
});
it != m_achievementsUnlocked.end()) {
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/players/cyclopedia/player_badge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bool PlayerBadge::hasBadge(uint8_t id) const {
return false;
}

if (const auto &it = std::ranges::find_if(m_badgesUnlocked, [id](auto badge_it) {
if (auto it = std::ranges::find_if(m_badgesUnlocked, [id](auto badge_it) {
return badge_it.first.m_id == id;
});
it != m_badgesUnlocked.end()) {
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/players/cyclopedia/player_title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ bool PlayerTitle::isTitleUnlocked(uint8_t id) const {
return false;
}

if (const auto &it = std::ranges::find_if(m_titlesUnlocked, [id](auto title_it) {
if (auto it = std::ranges::find_if(m_titlesUnlocked, [id](auto title_it) {
return title_it.first.m_id == id;
});
it != m_titlesUnlocked.end()) {
Expand Down Expand Up @@ -64,7 +64,7 @@ void PlayerTitle::remove(const Title &title) {
return;
}

const auto &it = std::ranges::find_if(m_titlesUnlocked, [id](auto title_it) {
auto it = std::ranges::find_if(m_titlesUnlocked, [id](auto title_it) {
return title_it.first.m_id == id;
});

Expand Down
2 changes: 1 addition & 1 deletion src/creatures/players/grouping/familiars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ bool Familiars::loadFromXml() {
}

std::shared_ptr<Familiar> Familiars::getFamiliarByLookType(uint16_t vocation, uint16_t lookType) const {
if (const auto &it = std::ranges::find_if(familiars[vocation], [lookType](const auto &familiar_it) {
if (auto it = std::ranges::find_if(familiars[vocation], [lookType](const auto &familiar_it) {
return familiar_it->lookType == lookType;
});
it != familiars[vocation].end()) {
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/players/grouping/groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ bool Groups::load() {
}

std::shared_ptr<Group> Groups::getGroup(uint16_t id) const {
if (const auto &it = std::ranges::find_if(groups_vector, [id](auto group_it) {
if (auto it = std::ranges::find_if(groups_vector, [id](auto group_it) {
return group_it->id == id;
});
it != groups_vector.end()) {
Expand Down
16 changes: 8 additions & 8 deletions src/creatures/players/grouping/party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool Party::leaveParty(const std::shared_ptr<Player> &player) {
}

// since we already passed the leadership, we remove the player from the list
const auto &it = std::ranges::find(memberList, player);
auto it = std::ranges::find(memberList, player);
if (it != memberList.end()) {
memberList.erase(it);
}
Expand Down Expand Up @@ -166,7 +166,7 @@ bool Party::passPartyLeadership(const std::shared_ptr<Player> &player) {
}

// Remove it before to broadcast the message correctly
const auto &it = std::ranges::find(memberList, player);
auto it = std::ranges::find(memberList, player);
if (it != memberList.end()) {
memberList.erase(it);
}
Expand Down Expand Up @@ -214,7 +214,7 @@ bool Party::joinParty(const std::shared_ptr<Player> &player) {
return false;
}

const auto &it = std::ranges::find(inviteList, player);
auto it = std::ranges::find(inviteList, player);
if (it == inviteList.end()) {
return false;
}
Expand Down Expand Up @@ -263,7 +263,7 @@ bool Party::removeInvite(const std::shared_ptr<Player> &player, bool removeFromP
return false;
}

const auto &it = std::ranges::find(inviteList, player);
auto it = std::ranges::find(inviteList, player);
if (it == inviteList.end()) {
return false;
}
Expand Down Expand Up @@ -530,7 +530,7 @@ uint32_t Party::getMaxLevel() {
}

bool Party::isPlayerActive(const std::shared_ptr<Player> &player) {
const auto &it = ticksMap.find(player->getID());
auto it = ticksMap.find(player->getID());
if (it == ticksMap.end()) {
return false;
}
Expand Down Expand Up @@ -565,7 +565,7 @@ void Party::updatePlayerTicks(const std::shared_ptr<Player> &player, uint32_t po
}

void Party::clearPlayerPoints(const std::shared_ptr<Player> &player) {
const auto &it = ticksMap.find(player->getID());
auto it = ticksMap.find(player->getID());
if (it != ticksMap.end()) {
ticksMap.erase(it);
updateSharedExperience();
Expand Down Expand Up @@ -747,7 +747,7 @@ void Party::addPlayerLoot(const std::shared_ptr<Player> &player, const std::shar
}

uint32_t count = std::max<uint32_t>(1, item->getItemCount());
if (const auto &it = playerAnalyzer->lootMap.find(item->getID()); it != playerAnalyzer->lootMap.end()) {
if (auto it = playerAnalyzer->lootMap.find(item->getID()); it != playerAnalyzer->lootMap.end()) {
it->second += count;
} else {
playerAnalyzer->lootMap.insert({ item->getID(), count });
Expand All @@ -774,7 +774,7 @@ void Party::addPlayerSupply(const std::shared_ptr<Player> &player, const std::sh
membersData.emplace_back(playerAnalyzer);
}

if (const auto &it = playerAnalyzer->supplyMap.find(item->getID()); it != playerAnalyzer->supplyMap.end()) {
if (auto it = playerAnalyzer->supplyMap.find(item->getID()); it != playerAnalyzer->supplyMap.end()) {
it->second += 1;
} else {
playerAnalyzer->supplyMap.insert({ item->getID(), 1 });
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/players/grouping/party.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Party final : public SharedObject {
void reloadPrices() const;

std::shared_ptr<PartyAnalyzer> getPlayerPartyAnalyzerStruct(uint32_t playerId) const {
if (const auto &it = std::ranges::find_if(membersData, [playerId](const std::shared_ptr<PartyAnalyzer> &preyIt) {
if (auto it = std::ranges::find_if(membersData, [playerId](const std::shared_ptr<PartyAnalyzer> &preyIt) {
return preyIt->id == playerId;
});
it != membersData.end()) {
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/players/imbuements/imbuements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Imbuement* Imbuements::getImbuement(uint16_t id) {
return nullptr;
}

const auto &it = imbuementMap.find(id);
auto it = imbuementMap.find(id);
if (it == imbuementMap.end()) {
g_logger().warn("Imbuement {} not found", id);
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/creatures/players/management/ban.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bool Ban::acceptConnection(uint32_t clientIP) {

const uint64_t currentTime = OTSYS_TIME();

const auto &it = ipConnectMap.find(clientIP);
auto it = ipConnectMap.find(clientIP);
if (it == ipConnectMap.end()) {
ipConnectMap.emplace(clientIP, ConnectBlock(currentTime, 0, 1));
return true;
Expand Down
Loading
Loading