This commit is contained in:
Igor Pavlov
2019-03-04 01:27:14 +00:00
committed by Kornel
parent 5b2a99c548
commit 4a960640a3
74 changed files with 906 additions and 415 deletions

View File

@@ -7,6 +7,23 @@
#include "FilterCoder.h"
#include "StreamUtils.h"
#ifdef _WIN32
#define alignedMidBuffer_Alloc g_MidAlloc
#else
#define alignedMidBuffer_Alloc g_AlignedAlloc
#endif
CAlignedMidBuffer::~CAlignedMidBuffer()
{
ISzAlloc_Free(&alignedMidBuffer_Alloc, _buf);
}
void CAlignedMidBuffer::AllocAligned(size_t size)
{
ISzAlloc_Free(&alignedMidBuffer_Alloc, _buf);
_buf = (Byte *)ISzAlloc_Alloc(&alignedMidBuffer_Alloc, size);
}
/*
AES filters need 16-bytes alignment for HARDWARE-AES instructions.
So we call IFilter::Filter(, size), where (size != 16 * N) only for last data block.
@@ -36,7 +53,7 @@ HRESULT CFilterCoder::Alloc()
size = kMinSize;
if (!_buf || _bufSize != size)
{
AllocAlignedMask(size, 16 - 1);
AllocAligned(size);
if (!_buf)
return E_OUTOFMEMORY;
_bufSize = size;

View File

@@ -19,41 +19,11 @@
struct CAlignedMidBuffer
{
#ifdef _WIN32
Byte *_buf;
CAlignedMidBuffer(): _buf(NULL) {}
~CAlignedMidBuffer() { ::MidFree(_buf); }
void AllocAlignedMask(size_t size, size_t)
{
::MidFree(_buf);
_buf = (Byte *)::MidAlloc(size);
}
#else
Byte *_bufBase;
Byte *_buf;
CAlignedMidBuffer(): _bufBase(NULL), _buf(NULL) {}
~CAlignedMidBuffer() { ::MidFree(_bufBase); }
void AllocAlignedMask(size_t size, size_t alignMask)
{
::MidFree(_bufBase);
_buf = NULL;
_bufBase = (Byte *)::MidAlloc(size + alignMask);
if (_bufBase)
{
// _buf = (Byte *)(((uintptr_t)_bufBase + alignMask) & ~(uintptr_t)alignMask);
_buf = (Byte *)(((ptrdiff_t)_bufBase + alignMask) & ~(ptrdiff_t)alignMask);
}
}
#endif
~CAlignedMidBuffer();
void AllocAligned(size_t size);
};
class CFilterCoder: