aboutsummaryrefslogtreecommitdiff
path: root/common/unarj.cpp
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2009-07-21 09:39:58 +0000
committerWillem Jan Palenstijn2009-07-21 09:39:58 +0000
commit4c797d57d0ce45532e1fd3dc144ba271f2f5f86c (patch)
treeeab472f8a6d6a527a218d4d4106d8c087998e950 /common/unarj.cpp
parent004b313ae0cbacad98bbc7ee3ae82bcb5ef1780c (diff)
downloadscummvm-rg350-4c797d57d0ce45532e1fd3dc144ba271f2f5f86c.tar.gz
scummvm-rg350-4c797d57d0ce45532e1fd3dc144ba271f2f5f86c.tar.bz2
scummvm-rg350-4c797d57d0ce45532e1fd3dc144ba271f2f5f86c.zip
Use a BufferedReadStream to buffer ArjFile's input to reduce memory usage
svn-id: r42637
Diffstat (limited to 'common/unarj.cpp')
-rw-r--r--common/unarj.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/common/unarj.cpp b/common/unarj.cpp
index 428b4a426e..0312cc5b08 100644
--- a/common/unarj.cpp
+++ b/common/unarj.cpp
@@ -105,7 +105,7 @@ public:
void decode(int32 origsize);
void decode_f(int32 origsize);
- MemoryReadStream *_compressed;
+ BufferedReadStream *_compressed;
MemoryWriteStream *_outstream;
//protected:
@@ -360,6 +360,9 @@ bool ArjFile::open(const Common::String &filename) {
return false;
ArjHeader *hdr = _headers[_fileMap[filename]];
+
+ // TODO: It would be good if ArjFile could decompress files in a streaming
+ // mode, so it would not need to pre-allocate the entire output.
byte *uncompressedData = (byte *)malloc(hdr->origSize);
File archiveFile;
@@ -372,10 +375,11 @@ bool ArjFile::open(const Common::String &filename) {
} else {
ArjDecoder *decoder = new ArjDecoder(hdr);
- byte *compressedData = (byte *)malloc(hdr->compSize);
- archiveFile.read(compressedData, hdr->compSize);
-
- decoder->_compressed = new MemoryReadStream(compressedData, hdr->compSize, true);
+ // TODO: It might not be appropriate to use this wrapper inside ArjFile.
+ // If reading from archiveFile directly is too slow to be usable,
+ // maybe the filesystem code should instead wrap its files
+ // in a BufferedReadStream.
+ decoder->_compressed = new BufferedReadStream(&archiveFile, 4096, false);
decoder->_outstream = new MemoryWriteStream(uncompressedData, hdr->origSize);
if (hdr->method == 1 || hdr->method == 2 || hdr->method == 3)