[Scummvm-cvs-logs] SF.net SVN: scummvm: [32472] scummvm/trunk/common

sev at users.sourceforge.net sev at users.sourceforge.net
Sun Jun 1 21:07:13 CEST 2008


Revision: 32472
          http://scummvm.svn.sourceforge.net/scummvm/?rev=32472&view=rev
Author:   sev
Date:     2008-06-01 12:07:13 -0700 (Sun, 01 Jun 2008)

Log Message:
-----------
Speed up decoding by memory caching

Modified Paths:
--------------
    scummvm/trunk/common/unarj.cpp
    scummvm/trunk/common/unarj.h

Modified: scummvm/trunk/common/unarj.cpp
===================================================================
--- scummvm/trunk/common/unarj.cpp	2008-06-01 18:37:35 UTC (rev 32471)
+++ scummvm/trunk/common/unarj.cpp	2008-06-01 19:07:13 UTC (rev 32472)
@@ -77,6 +77,7 @@
 
 ArjFile::ArjFile() {
 	InitCRC();
+	_isOpen = false;
 }
 
 ArjFile::~ArjFile() {
@@ -228,6 +229,9 @@
 
 
 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,13 +250,23 @@
 	_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;
 	_outstream = NULL;
@@ -305,7 +319,7 @@
 		_bitbuf |= _subbitbuf << (n -= _bitcount);
 		if (_compsize != 0) {
 			_compsize--;
-			_subbitbuf = _currArchive.readByte();
+			_subbitbuf = _compressed->readByte();
 		} else
 			_subbitbuf = 0;
 		_bitcount = CHAR_BIT;

Modified: scummvm/trunk/common/unarj.h
===================================================================
--- scummvm/trunk/common/unarj.h	2008-06-01 18:37:35 UTC (rev 32471)
+++ scummvm/trunk/common/unarj.h	2008-06-01 19:07:13 UTC (rev 32472)
@@ -125,7 +125,9 @@
 	StringMap _archMap;
 	ReadStream *_stream;
 	byte *_uncompressedData;
+	byte *_compressedData;
 	MemoryWriteStream *_outstream;
+	MemoryReadStream *_compressed;
 	MemoryReadStream *_uncompressed;
 
 	bool _isOpen;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list