mirror of
https://github.com/Expand-sys/CCash
synced 2026-03-22 12:37:08 +11:00
🐎 slightly faster when logs arent full
This commit is contained in:
parent
2dc1c0c369
commit
f58813606d
1 changed files with 51 additions and 62 deletions
15
src/bank.cpp
15
src/bank.cpp
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue