Common/LinearDiskCache: Use unique_ptr instead of new/delete.
This commit is contained in:
parent
eb6fd56c1d
commit
e91a347a07
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
|
@ -72,7 +73,7 @@ public:
|
|||
// good header, read some key/value pairs
|
||||
K key;
|
||||
|
||||
V* value = nullptr;
|
||||
std::unique_ptr<V[]> value = nullptr;
|
||||
u32 value_size = 0;
|
||||
u32 entry_number = 0;
|
||||
|
||||
|
@ -82,14 +83,14 @@ public:
|
|||
if (next_extent > file_size)
|
||||
break;
|
||||
|
||||
delete[] value;
|
||||
value = new V[value_size];
|
||||
// TODO: use make_unique_for_overwrite in C++20
|
||||
value = std::unique_ptr<V[]>(new V[value_size]);
|
||||
|
||||
// read key/value and pass to reader
|
||||
if (m_file.ReadArray(&key, 1) && m_file.ReadArray(value, value_size) &&
|
||||
if (m_file.ReadArray(&key, 1) && m_file.ReadArray(value.get(), value_size) &&
|
||||
m_file.ReadArray(&entry_number, 1) && entry_number == m_num_entries + 1)
|
||||
{
|
||||
reader.Read(key, value, value_size);
|
||||
reader.Read(key, value.get(), value_size);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -100,7 +101,6 @@ public:
|
|||
}
|
||||
m_file.Clear();
|
||||
|
||||
delete[] value;
|
||||
return m_num_entries;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue