Skip to content

Commit

Permalink
Common/LinearDiskCache: Use unique_ptr instead of new/delete.
Browse files Browse the repository at this point in the history
  • Loading branch information
AdmiralCurtiss committed Dec 19, 2020
1 parent eb6fd56 commit e91a347
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Source/Core/Common/LinearDiskCache.h
Expand Up @@ -6,6 +6,7 @@

#include <algorithm>
#include <cstring>
#include <memory>
#include <string>
#include <type_traits>

Expand Down Expand Up @@ -72,7 +73,7 @@ class LinearDiskCache
// 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;

Expand All @@ -82,14 +83,14 @@ class LinearDiskCache
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
{
Expand All @@ -100,7 +101,6 @@ class LinearDiskCache
}
m_file.Clear();

delete[] value;
return m_num_entries;
}

Expand Down

0 comments on commit e91a347

Please sign in to comment.