aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorEugene Sandulenko2008-06-01 19:07:13 +0000
committerEugene Sandulenko2008-06-01 19:07:13 +0000
commit8728cd2881b276f3ec6ad3bf0ac61be51eb474b8 (patch)
tree06245d508bfd58ea8f7d6a818463a5aaf2ce189c /common
parent37563ff3ae020ab05c314ad79630aaacf8d4c458 (diff)
downloadscummvm-rg350-8728cd2881b276f3ec6ad3bf0ac61be51eb474b8.tar.gz
scummvm-rg350-8728cd2881b276f3ec6ad3bf0ac61be51eb474b8.tar.bz2
scummvm-rg350-8728cd2881b276f3ec6ad3bf0ac61be51eb474b8.zip
Speed up decoding by memory caching
svn-id: r32472
Diffstat (limited to 'common')
-rw-r--r--common/unarj.cpp26
-rw-r--r--common/unarj.h2
2 files changed, 22 insertions, 6 deletions
diff --git a/common/unarj.cpp b/common/unarj.cpp
index c8e48dce2c..64203d5c66 100644
--- a/common/unarj.cpp
+++ b/common/unarj.cpp
@@ -77,6 +77,7 @@ static uint32 GetCRC(byte *data, int len) {
ArjFile::ArjFile() {
InitCRC();
+ _isOpen = false;
}
ArjFile::~ArjFile() {
@@ -228,6 +229,9 @@ ArjHeader *ArjFile::readHeader() {
bool ArjFile::open(const Common::String &filename, AccessMode mode) {
+ if (_isOpen)
+ error("Attempt to open another instance of archive");
+
_isOpen = false;
if (!_fileMap.contains(filename))
@@ -246,12 +250,22 @@ bool ArjFile::open(const Common::String &filename, AccessMode mode) {
_currArchive.open(_archMap[filename]);
_currArchive.seek(hdr->pos, SEEK_SET);
- if (hdr->method == 0) // store
+ if (hdr->method == 0) { // store
_currArchive.read(_uncompressedData, _origsize);
- else if (hdr->method == 1 || hdr->method == 2 || hdr->method == 3)
- decode();
- else if (hdr->method == 4)
- decode_f();
+ } else {
+ _compressedData = (byte *)malloc(_compsize);
+ _currArchive.read(_compressedData, _compsize);
+
+ _compressed = new MemoryReadStream(_compressedData, _compsize);
+
+ if (hdr->method == 1 || hdr->method == 2 || hdr->method == 3)
+ decode();
+ else if (hdr->method == 4)
+ decode_f();
+
+ delete _compressed;
+ free(_compressedData);
+ }
_currArchive.close();
delete _outstream;
@@ -305,7 +319,7 @@ void ArjFile::fillbuf(int n) { // Shift bitbuf n bits left, read n bits
_bitbuf |= _subbitbuf << (n -= _bitcount);
if (_compsize != 0) {
_compsize--;
- _subbitbuf = _currArchive.readByte();
+ _subbitbuf = _compressed->readByte();
} else
_subbitbuf = 0;
_bitcount = CHAR_BIT;
diff --git a/common/unarj.h b/common/unarj.h
index 63c6ca582d..28424f70bd 100644
--- a/common/unarj.h
+++ b/common/unarj.h
@@ -125,7 +125,9 @@ private:
StringMap _archMap;
ReadStream *_stream;
byte *_uncompressedData;
+ byte *_compressedData;
MemoryWriteStream *_outstream;
+ MemoryReadStream *_compressed;
MemoryReadStream *_uncompressed;
bool _isOpen;