unify fastReadNum
This commit is contained in:
@@ -22,18 +22,16 @@ ssize_t readFile(const std::string& path, char* buffer, size_t maxlen);
|
||||
ssize_t readFile(const char* path, char* buffer, size_t maxlen);
|
||||
std::string getFirstDir(const std::string_view& path);
|
||||
|
||||
/* reads a number from file REALLY fast */
|
||||
template <typename T, size_t N>
|
||||
/* reads a number fast and divides it if needed */
|
||||
template <uint32_t Divider = 1, typename T, size_t N>
|
||||
inline void fastReadNum(const std::string& path, char (&buf)[N], T& result) {
|
||||
readFile(path, buf, N);
|
||||
std::from_chars(buf, buf + N, result);
|
||||
}
|
||||
|
||||
/* reads a number slightly slower and divides it */
|
||||
template <uint32_t Divider, typename T, size_t N>
|
||||
inline void fastReadNumDiv(const std::string& path, char (&buf)[N], T& result) {
|
||||
if constexpr (Divider == 1) {
|
||||
std::from_chars(buf, buf + N, result);
|
||||
return;
|
||||
}
|
||||
uint64_t temp{};
|
||||
fastReadNum(path, buf, temp);
|
||||
std::from_chars(buf, buf + N, temp);
|
||||
if constexpr (std::is_floating_point_v<T>)
|
||||
result = temp / static_cast<T>(Divider);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user