Skip to content

Commit

Permalink
Merge pull request #85 from conor42/master
Browse files Browse the repository at this point in the history
Pass blockSize to fast-lzma2 and limit it to 256 Mb
  • Loading branch information
mcmilk committed May 4, 2019
2 parents cd1e182 + 0cc8701 commit 7932a50
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CPP/7zip/Compress/Lzma2Encoder.cpp
Expand Up @@ -147,6 +147,9 @@ static HRESULT TranslateError(size_t res)

#define CHECK_P(f) if (FL2_isError(f)) return E_INVALIDARG; /* check and convert error code */

#define MIN_BLOCK_SIZE (1U << 20)
#define MAX_BLOCK_SIZE (1U << 28)

CFastEncoder::FastLzma2::FastLzma2()
: fcs(NULL),
dict_pos(0)
Expand Down Expand Up @@ -204,6 +207,18 @@ HRESULT CFastEncoder::FastLzma2::SetCoderProperties(const PROPID *propIDs, const
CHECK_P(FL2_CCtx_setParameter(fcs, FL2_p_literalPosBits, lzma2Props.lzmaProps.lp));
if (lzma2Props.lzmaProps.pb >= 0)
CHECK_P(FL2_CCtx_setParameter(fcs, FL2_p_posBits, lzma2Props.lzmaProps.pb));
if (lzma2Props.blockSize == 0)
lzma2Props.blockSize = min(max(MIN_BLOCK_SIZE, dictSize * 4U), MAX_BLOCK_SIZE);
else if (lzma2Props.blockSize == LZMA2_ENC_PROPS__BLOCK_SIZE__SOLID)
lzma2Props.blockSize = 0;
unsigned r = 0;
if (lzma2Props.blockSize != 0) {
r = 1;
// Do not exceed the block size. TODO: the lib should support setting a value instead of a multiplier.
while (r < FL2_RESET_INTERVAL_MAX && (r + 1) * (UInt64)dictSize <= lzma2Props.blockSize)
++r;
}
CHECK_P(FL2_CCtx_setParameter(fcs, FL2_p_resetInterval, r));
FL2_CCtx_setParameter(fcs, FL2_p_omitProperties, 1);
FL2_setCStreamTimeout(fcs, 500);
return S_OK;
Expand Down

0 comments on commit 7932a50

Please sign in to comment.