[ox] Correct bad bit_cast uses and improve constexpr-ness
This commit is contained in:
33
deps/ox/src/ox/fs/filesystem/filelocation.cpp
vendored
33
deps/ox/src/ox/fs/filesystem/filelocation.cpp
vendored
@@ -12,11 +12,6 @@
|
||||
|
||||
namespace ox {
|
||||
|
||||
FileAddress::FileAddress() noexcept {
|
||||
m_data.inode = 0;
|
||||
m_type = FileAddressType::Inode;
|
||||
}
|
||||
|
||||
FileAddress::FileAddress(const FileAddress &other) noexcept {
|
||||
operator=(other);
|
||||
}
|
||||
@@ -50,6 +45,9 @@ FileAddress::~FileAddress() noexcept {
|
||||
}
|
||||
|
||||
FileAddress &FileAddress::operator=(const FileAddress &other) noexcept {
|
||||
if (this == &other) {
|
||||
return *this;
|
||||
}
|
||||
cleanup();
|
||||
m_type = other.m_type;
|
||||
switch (m_type) {
|
||||
@@ -71,9 +69,26 @@ FileAddress &FileAddress::operator=(const FileAddress &other) noexcept {
|
||||
}
|
||||
|
||||
FileAddress &FileAddress::operator=(FileAddress &&other) noexcept {
|
||||
if (this == &other) {
|
||||
return *this;
|
||||
}
|
||||
cleanup();
|
||||
m_type = other.m_type;
|
||||
memcpy(this, &other, sizeof(*this));
|
||||
switch (m_type) {
|
||||
case FileAddressType::Path:
|
||||
{
|
||||
auto strSize = ox_strlen(other.m_data.path) + 1;
|
||||
m_data.path = new char[strSize];
|
||||
ox_memcpy(m_data.path, other.m_data.path, strSize);
|
||||
break;
|
||||
}
|
||||
case FileAddressType::ConstPath:
|
||||
case FileAddressType::Inode:
|
||||
m_data = other.m_data;
|
||||
break;
|
||||
case FileAddressType::None:
|
||||
break;
|
||||
}
|
||||
other.clear();
|
||||
return *this;
|
||||
}
|
||||
@@ -86,10 +101,8 @@ void FileAddress::cleanup() noexcept {
|
||||
}
|
||||
|
||||
void FileAddress::clear() noexcept {
|
||||
if (m_type == FileAddressType::Path) {
|
||||
m_data.path = nullptr;
|
||||
m_type = FileAddressType::None;
|
||||
}
|
||||
m_data.path = nullptr;
|
||||
m_type = FileAddressType::None;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user