Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #892 from comex/oh-the-abstraction
Optimize PointerWrap.
  • Loading branch information
comex committed Aug 28, 2014
2 parents ad8fe0f + faa2666 commit 683191b
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions Source/Core/Common/ChunkFile.h
Expand Up @@ -162,8 +162,8 @@ class PointerWrap
template <typename T>
void DoArray(T* x, u32 count)
{
for (u32 i = 0; i != count; ++i)
Do(x[i]);
static_assert(IsTriviallyCopyable(T), "Only sane for trivially copyable types");
DoVoid(x, count * sizeof(T));
}

void Do(Common::Flag& flag)
Expand All @@ -178,6 +178,10 @@ class PointerWrap
void Do(T& x)
{
static_assert(IsTriviallyCopyable(T), "Only sane for trivially copyable types");
// Note:
// Usually we can just use x = **ptr, etc. However, this doesn't work
// for unions containing BitFields (long story, stupid language rules)
// or arrays. This will get optimized anyway.
DoVoid((void*)&x, sizeof(x));
}

Expand Down Expand Up @@ -285,38 +289,30 @@ class PointerWrap
Do(elem);
}

__forceinline void DoByte(u8& x)
__forceinline
void DoVoid(void *data, u32 size)
{
switch (mode)
{
case MODE_READ:
x = **ptr;
memcpy(data, *ptr, size);
break;

case MODE_WRITE:
**ptr = x;
memcpy(*ptr, data, size);
break;

case MODE_MEASURE:
break;

case MODE_VERIFY:
_dbg_assert_msg_(COMMON, (x == **ptr),
"Savestate verification failure: %d (0x%X) (at %p) != %d (0x%X) (at %p).\n",
x, x, &x, **ptr, **ptr, *ptr);
break;

default:
_dbg_assert_msg_(COMMON, !memcmp(data, *ptr, size),
"Savestate verification failure: buf %p != %p (size %u).\n",
data, *ptr, size);
break;
}

++(*ptr);
}

void DoVoid(void *data, u32 size)
{
for (u32 i = 0; i != size; ++i)
DoByte(reinterpret_cast<u8*>(data)[i]);
*ptr += size;
}
};

Expand Down

0 comments on commit 683191b

Please sign in to comment.