🐎 slightly faster when logs arent full

This commit is contained in:
EntireTwix 2021-06-19 20:50:06 -07:00
parent 2dc1c0c369
commit f58813606d

View file

@ -32,13 +32,12 @@ int_fast8_t Bank::AdminAddUser(const std::string &attempt, std::string &&name, u
{
return ErrorResponse::WrongPassword;
}
{
std::shared_lock<std::shared_mutex> lock{size_l};
return (users.try_emplace_l(
name, [](User &) {}, init_bal, std::move(init_pass)))
? true
: ErrorResponse::UserAlreadyExists;
}
}
int_fast8_t Bank::DelUser(const std::string &name, const std::string &attempt) noexcept
{
@ -75,13 +74,12 @@ int_fast8_t Bank::SendFunds(const std::string &a_name, const std::string &b_name
return ErrorResponse::InvalidRequest;
}
//as first modify_if checks a_name and grabs unique lock
if (!Contains(b_name) || !Contains(a_name))
if (!Contains(b_name))
{
return ErrorResponse::UserNotFound;
}
int_fast8_t state = false;
{
if constexpr (max_log_size > 0)
{
Transaction temp(a_name, b_name, amount);
@ -110,13 +108,9 @@ int_fast8_t Bank::SendFunds(const std::string &a_name, const std::string &b_name
b.balance += amount;
b.log.AddTrans(std::move(temp));
});
return true;
}
else
{
return state;
}
}
else
{
std::shared_lock<std::shared_mutex> lock{send_funds_l};
@ -142,14 +136,9 @@ int_fast8_t Bank::SendFunds(const std::string &a_name, const std::string &b_name
users.modify_if(b_name, [&a_name, &b_name, amount](User &b) {
b.balance += amount;
});
return true;
}
else
{
return state;
}
}
}
}
int_fast8_t Bank::Contains(const std::string &name) const noexcept