upgraded to lzma sdk 4.43 for faster compression

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@4772 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2006-10-16 08:46:36 +00:00
parent 51a96f2d75
commit 2cd2142ca3
42 changed files with 1900 additions and 1572 deletions

View file

@ -7,11 +7,11 @@
#include "../../Common/Alloc.h"
CInBuffer::CInBuffer():
_bufferBase(0),
_bufferSize(0),
_buffer(0),
_bufferLimit(0),
_stream(0)
_bufferBase(0),
_stream(0),
_bufferSize(0)
{}
bool CInBuffer::Create(UInt32 bufferSize)
@ -23,19 +23,23 @@ bool CInBuffer::Create(UInt32 bufferSize)
return true;
Free();
_bufferSize = bufferSize;
_bufferBase = (Byte *)::BigAlloc(bufferSize);
_bufferBase = (Byte *)::MidAlloc(bufferSize);
return (_bufferBase != 0);
}
void CInBuffer::Free()
{
BigFree(_bufferBase);
::MidFree(_bufferBase);
_bufferBase = 0;
}
void CInBuffer::Init(ISequentialInStream *stream)
void CInBuffer::SetStream(ISequentialInStream *stream)
{
_stream = stream;
}
void CInBuffer::Init()
{
_processedSize = 0;
_buffer = _bufferBase;
_bufferLimit = _buffer;
@ -55,7 +59,7 @@ bool CInBuffer::ReadBlock()
return false;
_processedSize += (_buffer - _bufferBase);
UInt32 numProcessedBytes;
HRESULT result = _stream->ReadPart(_bufferBase, _bufferSize, &numProcessedBytes);
HRESULT result = _stream->Read(_bufferBase, _bufferSize, &numProcessedBytes);
#ifdef _NO_EXCEPTIONS
ErrorCode = result;
#else
@ -67,3 +71,10 @@ bool CInBuffer::ReadBlock()
_wasFinished = (numProcessedBytes == 0);
return (!_wasFinished);
}
Byte CInBuffer::ReadBlock2()
{
if(!ReadBlock())
return 0xFF;
return *_buffer++;
}

View file

@ -4,6 +4,7 @@
#define __INBUFFER_H
#include "../IStream.h"
#include "../../Common/MyCom.h"
#ifndef _NO_EXCEPTIONS
class CInBufferException
@ -16,15 +17,16 @@ public:
class CInBuffer
{
UInt64 _processedSize;
Byte *_bufferBase;
UInt32 _bufferSize;
Byte *_buffer;
Byte *_bufferLimit;
ISequentialInStream *_stream;
Byte *_bufferBase;
CMyComPtr<ISequentialInStream> _stream;
UInt64 _processedSize;
UInt32 _bufferSize;
bool _wasFinished;
bool ReadBlock();
Byte ReadBlock2();
public:
#ifdef _NO_EXCEPTIONS
@ -37,8 +39,9 @@ public:
bool Create(UInt32 bufferSize);
void Free();
void Init(ISequentialInStream *stream);
// void ReleaseStream() { _stream.Release(); }
void SetStream(ISequentialInStream *stream);
void Init();
void ReleaseStream() { _stream.Release(); }
bool ReadByte(Byte &b)
{
@ -51,8 +54,7 @@ public:
Byte ReadByte()
{
if(_buffer >= _bufferLimit)
if(!ReadBlock())
return 0xFF;
return ReadBlock2();
return *_buffer++;
}
void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)

View file

@ -15,48 +15,98 @@ bool COutBuffer::Create(UInt32 bufferSize)
return true;
Free();
_bufferSize = bufferSize;
_buffer = (Byte *)::BigAlloc(bufferSize);
_buffer = (Byte *)::MidAlloc(bufferSize);
return (_buffer != 0);
}
void COutBuffer::Free()
{
BigFree(_buffer);
::MidFree(_buffer);
_buffer = 0;
}
void COutBuffer::Init(ISequentialOutStream *stream)
void COutBuffer::SetStream(ISequentialOutStream *stream)
{
_stream = stream;
_processedSize = 0;
}
void COutBuffer::Init()
{
_streamPos = 0;
_limitPos = _bufferSize;
_pos = 0;
_processedSize = 0;
_overDict = false;
#ifdef _NO_EXCEPTIONS
ErrorCode = S_OK;
#endif
}
HRESULT COutBuffer::Flush()
{
if (_pos == 0)
return S_OK;
UInt32 processedSize;
HRESULT result = _stream->Write(_buffer, _pos, &processedSize);
if (result != S_OK)
return result;
if (_pos != processedSize)
return E_FAIL;
_processedSize += processedSize;
_pos = 0;
return S_OK;
UInt64 COutBuffer::GetProcessedSize() const
{
UInt64 res = _processedSize + _pos - _streamPos;
if (_streamPos > _pos)
res += _bufferSize;
return res;
}
void COutBuffer::WriteBlock()
HRESULT COutBuffer::FlushPart()
{
// _streamPos < _bufferSize
UInt32 size = (_streamPos >= _pos) ? (_bufferSize - _streamPos) : (_pos - _streamPos);
HRESULT result = S_OK;
#ifdef _NO_EXCEPTIONS
result = ErrorCode;
#endif
if (_buffer2 != 0)
{
memmove(_buffer2, _buffer + _streamPos, size);
_buffer2 += size;
}
if (_stream != 0
#ifdef _NO_EXCEPTIONS
&& (ErrorCode == S_OK)
#endif
)
{
UInt32 processedSize = 0;
result = _stream->Write(_buffer + _streamPos, size, &processedSize);
size = processedSize;
}
_streamPos += size;
if (_streamPos == _bufferSize)
_streamPos = 0;
if (_pos == _bufferSize)
{
_overDict = true;
_pos = 0;
}
_limitPos = (_streamPos > _pos) ? _streamPos : _bufferSize;
_processedSize += size;
return result;
}
HRESULT COutBuffer::Flush()
{
#ifdef _NO_EXCEPTIONS
if (ErrorCode != S_OK)
return;
return ErrorCode;
#endif
HRESULT result = Flush();
while(_streamPos != _pos)
{
HRESULT result = FlushPart();
if (result != S_OK)
return result;
}
return S_OK;
}
void COutBuffer::FlushWithCheck()
{
HRESULT result = FlushPart();
#ifdef _NO_EXCEPTIONS
ErrorCode = result;
#else

View file

@ -4,6 +4,7 @@
#define __OUTBUFFER_H
#include "../IStream.h"
#include "../../Common/MyCom.h"
#ifndef _NO_EXCEPTIONS
struct COutBufferException
@ -15,55 +16,49 @@ struct COutBufferException
class COutBuffer
{
protected:
Byte *_buffer;
UInt32 _pos;
UInt32 _limitPos;
UInt32 _streamPos;
UInt32 _bufferSize;
ISequentialOutStream *_stream;
CMyComPtr<ISequentialOutStream> _stream;
UInt64 _processedSize;
Byte *_buffer2;
bool _overDict;
void WriteBlock();
HRESULT FlushPart();
void FlushWithCheck();
public:
#ifdef _NO_EXCEPTIONS
HRESULT ErrorCode;
#endif
COutBuffer(): _buffer(0), _pos(0), _stream(0) {}
COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}
~COutBuffer() { Free(); }
bool Create(UInt32 bufferSize);
void Free();
void Init(ISequentialOutStream *stream);
void SetMemStream(Byte *buffer) { _buffer2 = buffer; }
void SetStream(ISequentialOutStream *stream);
void Init();
HRESULT Flush();
// void ReleaseStream(); { _stream.Release(); }
/*
void *GetBuffer(UInt32 &sizeAvail)
{
sizeAvail = _bufferSize - _pos;
return _buffer + _pos;
}
void MovePos(UInt32 num)
{
_pos += num;
if(_pos >= _bufferSize)
WriteBlock();
}
*/
void ReleaseStream() { _stream.Release(); }
void WriteByte(Byte b)
{
_buffer[_pos++] = b;
if(_pos >= _bufferSize)
WriteBlock();
if(_pos == _limitPos)
FlushWithCheck();
}
void WriteBytes(const void *data, UInt32 size)
void WriteBytes(const void *data, size_t size)
{
for (UInt32 i = 0; i < size; i++)
for (size_t i = 0; i < size; i++)
WriteByte(((const Byte *)data)[i]);
}
UInt64 GetProcessedSize() const { return _processedSize + _pos; }
UInt64 GetProcessedSize() const;
};
#endif

View file

@ -3,6 +3,6 @@
#ifndef __STDAFX_H
#define __STDAFX_H
#include "../../../Platform.h"
#include "../../Common/MyWindows.h"
#endif

View file

@ -0,0 +1,44 @@
// StreamUtils.cpp
#include "StdAfx.h"
#include "../../Common/MyCom.h"
#include "StreamUtils.h"
HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize)
{
if (processedSize != 0)
*processedSize = 0;
while(size != 0)
{
UInt32 processedSizeLoc;
HRESULT res = stream->Read(data, size, &processedSizeLoc);
if (processedSize != 0)
*processedSize += processedSizeLoc;
data = (Byte *)((Byte *)data + processedSizeLoc);
size -= processedSizeLoc;
RINOK(res);
if (processedSizeLoc == 0)
return S_OK;
}
return S_OK;
}
HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize)
{
if (processedSize != 0)
*processedSize = 0;
while(size != 0)
{
UInt32 processedSizeLoc;
HRESULT res = stream->Write(data, size, &processedSizeLoc);
if (processedSize != 0)
*processedSize += processedSizeLoc;
data = (const void *)((const Byte *)data + processedSizeLoc);
size -= processedSizeLoc;
RINOK(res);
if (processedSizeLoc == 0)
break;
}
return S_OK;
}

View file

@ -0,0 +1,11 @@
// StreamUtils.h
#ifndef __STREAMUTILS_H
#define __STREAMUTILS_H
#include "../IStream.h"
HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);
HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);
#endif