mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-11-03 14:39:58 +00:00
system_control: Make functions internally linked where applicable
These functions are only ever used internally as implementation details for GenerateRandomRange(), so these can be given internal linkage.
This commit is contained in:
parent
07691f994a
commit
87c64c41d2
2 changed files with 11 additions and 15 deletions
|
@ -7,22 +7,15 @@
|
||||||
#include "core/hle/kernel/memory/system_control.h"
|
#include "core/hle/kernel/memory/system_control.h"
|
||||||
|
|
||||||
namespace Kernel::Memory::SystemControl {
|
namespace Kernel::Memory::SystemControl {
|
||||||
|
namespace {
|
||||||
u64 GenerateRandomU64ForInit() {
|
|
||||||
static std::random_device device;
|
|
||||||
static std::mt19937 gen(device());
|
|
||||||
static std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max());
|
|
||||||
return distribution(gen);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
u64 GenerateUniformRange(u64 min, u64 max, F f) {
|
u64 GenerateUniformRange(u64 min, u64 max, F f) {
|
||||||
/* Handle the case where the difference is too large to represent. */
|
// Handle the case where the difference is too large to represent.
|
||||||
if (max == std::numeric_limits<u64>::max() && min == std::numeric_limits<u64>::min()) {
|
if (max == std::numeric_limits<u64>::max() && min == std::numeric_limits<u64>::min()) {
|
||||||
return f();
|
return f();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Iterate until we get a value in range. */
|
// Iterate until we get a value in range.
|
||||||
const u64 range_size = ((max + 1) - min);
|
const u64 range_size = ((max + 1) - min);
|
||||||
const u64 effective_max = (std::numeric_limits<u64>::max() / range_size) * range_size;
|
const u64 effective_max = (std::numeric_limits<u64>::max() / range_size) * range_size;
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -32,6 +25,14 @@ u64 GenerateUniformRange(u64 min, u64 max, F f) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u64 GenerateRandomU64ForInit() {
|
||||||
|
static std::random_device device;
|
||||||
|
static std::mt19937 gen(device());
|
||||||
|
static std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max());
|
||||||
|
return distribution(gen);
|
||||||
|
}
|
||||||
|
} // Anonymous namespace
|
||||||
|
|
||||||
u64 GenerateRandomRange(u64 min, u64 max) {
|
u64 GenerateRandomRange(u64 min, u64 max) {
|
||||||
return GenerateUniformRange(min, max, GenerateRandomU64ForInit);
|
return GenerateUniformRange(min, max, GenerateRandomU64ForInit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,6 @@
|
||||||
|
|
||||||
namespace Kernel::Memory::SystemControl {
|
namespace Kernel::Memory::SystemControl {
|
||||||
|
|
||||||
u64 GenerateRandomU64ForInit();
|
|
||||||
|
|
||||||
template <typename F>
|
|
||||||
u64 GenerateUniformRange(u64 min, u64 max, F f);
|
|
||||||
|
|
||||||
u64 GenerateRandomRange(u64 min, u64 max);
|
u64 GenerateRandomRange(u64 min, u64 max);
|
||||||
|
|
||||||
} // namespace Kernel::Memory::SystemControl
|
} // namespace Kernel::Memory::SystemControl
|
||||||
|
|
Loading…
Reference in a new issue