mirror of
https://github.com/diamante0018/master-tool.git
synced 2025-04-20 19:55:44 +00:00
refactor(memory): remove nullptr check before std::free
This commit is contained in:
parent
980b9303cd
commit
472d51a17b
@ -72,7 +72,7 @@ namespace console
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (count < 0) return {};
|
if (count < 0) return {};
|
||||||
return {buffer, static_cast<size_t>(count)};
|
return {buffer, static_cast<std::size_t>(count)};
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -91,7 +91,7 @@ namespace console
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool apply_color(const std::string& data, const size_t index, const color_type base_color)
|
bool apply_color(const std::string& data, const std::size_t index, const color_type base_color)
|
||||||
{
|
{
|
||||||
if (data[index] != '^' || (index + 1) >= data.size())
|
if (data[index] != '^' || (index + 1) >= data.size())
|
||||||
{
|
{
|
||||||
@ -122,7 +122,7 @@ namespace console
|
|||||||
lock _{};
|
lock _{};
|
||||||
set_color(base_color);
|
set_color(base_color);
|
||||||
|
|
||||||
for (size_t i = 0; i < line.size(); ++i)
|
for (std::size_t i = 0; i < line.size(); ++i)
|
||||||
{
|
{
|
||||||
if (apply_color(line, i, base_color))
|
if (apply_color(line, i, base_color))
|
||||||
{
|
{
|
||||||
|
@ -7,12 +7,12 @@ namespace utils
|
|||||||
{
|
{
|
||||||
bool remove_file(const std::string& file)
|
bool remove_file(const std::string& file)
|
||||||
{
|
{
|
||||||
return remove(file.data()) == 0;
|
return std::remove(file.data()) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool move_file(const std::string& src, const std::string& target)
|
bool move_file(const std::string& src, const std::string& target)
|
||||||
{
|
{
|
||||||
return rename(src.data(), target.data()) == 0;
|
return std::rename(src.data(), target.data()) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool file_exists(const std::string& file)
|
bool file_exists(const std::string& file)
|
||||||
|
@ -15,7 +15,7 @@ namespace utils
|
|||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> _(this->mutex_);
|
std::lock_guard<std::mutex> _(this->mutex_);
|
||||||
|
|
||||||
for (auto& data : this->pool_)
|
for (const auto& data : this->pool_)
|
||||||
{
|
{
|
||||||
memory::free(data);
|
memory::free(data);
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ namespace utils
|
|||||||
this->free(const_cast<void*>(data));
|
this->free(const_cast<void*>(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
void* memory::allocator::allocate(const size_t length)
|
void* memory::allocator::allocate(const std::size_t length)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> _(this->mutex_);
|
std::lock_guard<std::mutex> _(this->mutex_);
|
||||||
|
|
||||||
@ -63,9 +63,9 @@ namespace utils
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* memory::allocate(const size_t length)
|
void* memory::allocate(const std::size_t length)
|
||||||
{
|
{
|
||||||
return calloc(length, 1);
|
return std::calloc(length, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* memory::duplicate_string(const std::string& string)
|
char* memory::duplicate_string(const std::string& string)
|
||||||
@ -77,10 +77,7 @@ namespace utils
|
|||||||
|
|
||||||
void memory::free(void* data)
|
void memory::free(void* data)
|
||||||
{
|
{
|
||||||
if (data)
|
std::free(data);
|
||||||
{
|
|
||||||
::free(data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void memory::free(const void* data)
|
void memory::free(const void* data)
|
||||||
@ -88,11 +85,11 @@ namespace utils
|
|||||||
free(const_cast<void*>(data));
|
free(const_cast<void*>(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool memory::is_set(const void* mem, const char chr, const size_t length)
|
bool memory::is_set(const void* mem, const char chr, const std::size_t length)
|
||||||
{
|
{
|
||||||
auto* const mem_arr = static_cast<const char*>(mem);
|
auto* const mem_arr = static_cast<const char*>(mem);
|
||||||
|
|
||||||
for (size_t i = 0; i < length; ++i)
|
for (std::size_t i = 0; i < length; ++i)
|
||||||
{
|
{
|
||||||
if (mem_arr[i] != chr)
|
if (mem_arr[i] != chr)
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,7 @@ namespace utils
|
|||||||
|
|
||||||
void free(const void* data);
|
void free(const void* data);
|
||||||
|
|
||||||
void* allocate(size_t length);
|
void* allocate(std::size_t length);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T* allocate()
|
T* allocate()
|
||||||
@ -28,7 +28,7 @@ namespace utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T* allocate_array(const size_t count = 1)
|
T* allocate_array(const std::size_t count = 1)
|
||||||
{
|
{
|
||||||
return static_cast<T*>(this->allocate(count * sizeof(T)));
|
return static_cast<T*>(this->allocate(count * sizeof(T)));
|
||||||
}
|
}
|
||||||
@ -42,7 +42,7 @@ namespace utils
|
|||||||
std::vector<void*> pool_;
|
std::vector<void*> pool_;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void* allocate(size_t length);
|
static void* allocate(std::size_t length);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static T* allocate()
|
static T* allocate()
|
||||||
@ -51,7 +51,7 @@ namespace utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static T* allocate_array(const size_t count = 1)
|
static T* allocate_array(const std::size_t count = 1)
|
||||||
{
|
{
|
||||||
return static_cast<T*>(allocate(count * sizeof(T)));
|
return static_cast<T*>(allocate(count * sizeof(T)));
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ namespace utils
|
|||||||
static void free(void* data);
|
static void free(void* data);
|
||||||
static void free(const void* data);
|
static void free(const void* data);
|
||||||
|
|
||||||
static bool is_set(const void* mem, char chr, size_t length);
|
static bool is_set(const void* mem, char chr, std::size_t length);
|
||||||
|
|
||||||
static allocator* get_allocator();
|
static allocator* get_allocator();
|
||||||
|
|
||||||
|
@ -40,9 +40,9 @@ namespace utils
|
|||||||
std::string to_lower(std::string text)
|
std::string to_lower(std::string text)
|
||||||
{
|
{
|
||||||
std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input)
|
std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input)
|
||||||
{
|
{
|
||||||
return static_cast<char>(std::tolower(input));
|
return static_cast<char>(std::tolower(input));
|
||||||
});
|
});
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
@ -50,9 +50,9 @@ namespace utils
|
|||||||
std::string to_upper(std::string text)
|
std::string to_upper(std::string text)
|
||||||
{
|
{
|
||||||
std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input)
|
std::transform(text.begin(), text.end(), text.begin(), [](const unsigned char input)
|
||||||
{
|
{
|
||||||
return static_cast<char>(std::toupper(input));
|
return static_cast<char>(std::toupper(input));
|
||||||
});
|
});
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user