Skip to content

Commit

Permalink
Merge pull request #7767 from Tilka/chunkfile
Browse files Browse the repository at this point in the history
ChunkFile: treat vectors/strings as sized arrays
  • Loading branch information
Tilka committed Feb 2, 2019
2 parents 363ce67 + 04a9248 commit 0115906
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions Source/Core/Common/ChunkFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class PointerWrap
template <typename T>
void Do(std::vector<T>& x)
{
DoContainer(x);
DoContiguousContainer(x);
}

template <typename T>
Expand All @@ -134,7 +134,7 @@ class PointerWrap
template <typename T>
void Do(std::basic_string<T>& x)
{
DoContainer(x);
DoContiguousContainer(x);
}

template <typename T, typename U>
Expand All @@ -147,16 +147,22 @@ class PointerWrap
template <typename T, std::size_t N>
void DoArray(std::array<T, N>& x)
{
DoArray(x.data(), (u32)x.size());
DoArray(x.data(), static_cast<u32>(x.size()));
}

template <typename T>
template <typename T, typename std::enable_if_t<IsTriviallyCopyable<T>, int> = 0>
void DoArray(T* x, u32 count)
{
static_assert(IsTriviallyCopyable<T>, "Only sane for trivially copyable types");
DoVoid(x, count * sizeof(T));
}

template <typename T, typename std::enable_if_t<!IsTriviallyCopyable<T>, int> = 0>
void DoArray(T* x, u32 count)
{
for (u32 i = 0; i < count; ++i)
Do(x[i]);
}

template <typename T, std::size_t N>
void DoArray(T (&arr)[N])
{
Expand Down Expand Up @@ -249,6 +255,16 @@ class PointerWrap
}

private:
template <typename T>
void DoContiguousContainer(T& container)
{
u32 size = static_cast<u32>(container.size());
Do(size);
container.resize(size);

DoArray(&container[0], size);
}

template <typename T>
void DoContainer(T& x)
{
Expand Down

0 comments on commit 0115906

Please sign in to comment.