mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 17:15:09 +00:00
AK: Make MappedFile heap-allocated and ref-counted
Let's adapt this class a bit better to how it's actually being used. Instead of having valid/invalid states and storing an error in case it's invalid, a MappedFile is now always valid, and the factory function that creates it will return an OSError if mapping fails.
This commit is contained in:
parent
70fce5c4c7
commit
2f3b901f7f
36 changed files with 184 additions and 199 deletions
|
@ -34,7 +34,10 @@ namespace PCIDB {
|
|||
|
||||
RefPtr<Database> Database::open(const StringView& file_name)
|
||||
{
|
||||
auto res = adopt(*new Database(file_name));
|
||||
auto file_or_error = MappedFile::map(file_name);
|
||||
if (file_or_error.is_error())
|
||||
return nullptr;
|
||||
auto res = adopt(*new Database(file_or_error.release_value()));
|
||||
if (res->init() != 0)
|
||||
return nullptr;
|
||||
return res;
|
||||
|
@ -131,10 +134,7 @@ int Database::init()
|
|||
if (m_ready)
|
||||
return 0;
|
||||
|
||||
if (!m_file.is_valid())
|
||||
return -1;
|
||||
|
||||
m_view = StringView((const char*)m_file.data(), m_file.size());
|
||||
m_view = StringView { m_file->bytes() };
|
||||
|
||||
ParseMode mode = ParseMode::UnknownMode;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue