[Scummvm-cvs-logs] SF.net SVN: scummvm:[54331] scummvm/trunk/backends/fs/ds

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Nov 18 18:30:00 CET 2010


Revision: 54331
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54331&view=rev
Author:   fingolfin
Date:     2010-11-18 17:30:00 +0000 (Thu, 18 Nov 2010)

Log Message:
-----------
DS: Remove write buffering in DSFileStream, use wrapBufferedWriteStream instead

Modified Paths:
--------------
    scummvm/trunk/backends/fs/ds/ds-fs.cpp
    scummvm/trunk/backends/fs/ds/ds-fs.h

Modified: scummvm/trunk/backends/fs/ds/ds-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/ds/ds-fs.cpp	2010-11-18 17:25:09 UTC (rev 54330)
+++ scummvm/trunk/backends/fs/ds/ds-fs.cpp	2010-11-18 17:30:00 UTC (rev 54331)
@@ -40,10 +40,14 @@
 // DSFileSystemNode - Flash ROM file system using Zip files //
 //////////////////////////////////////////////////////////////
 
-ZipFile*	DSFileSystemNode::_zipFile = NULL;
-char		currentDir[128];
-bool		readPastEndOfFile = false;
+ZipFile*	DSFileSystemNode::_zipFile = NULL;	// FIXME: Avoid non-const global vars
+char		currentDir[128];	// FIXME: Avoid non-const global vars
+bool		readPastEndOfFile = false;	// FIXME: Avoid non-const global vars
 
+enum {
+	WRITE_BUFFER_SIZE = 512
+};
+
 DSFileSystemNode::DSFileSystemNode() {
 	_displayName = "ds:/";
 	_path = "ds:/";
@@ -205,7 +209,8 @@
 }
 
 Common::WriteStream *DSFileSystemNode::createWriteStream() {
-	return DSFileStream::makeFromPath(getPath(), true);
+	Common::WriteStream *stream = DSFileStream::makeFromPath(getPath(), true);
+	return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE, DisposeAfterUse::YES);
 }
 
 //////////////////////////////////////////////////////////////////////////
@@ -386,21 +391,17 @@
 }
 
 Common::WriteStream *GBAMPFileSystemNode::createWriteStream() {
-	return DSFileStream::makeFromPath(getPath(), true);
+	Common::WriteStream *stream = DSFileStream::makeFromPath(getPath(), true);
+	return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE, DisposeAfterUse::YES);
 }
 
 
 
-
 DSFileStream::DSFileStream(void *handle) : _handle(handle) {
 	assert(handle);
-	_writeBufferPos = 0;
 }
 
 DSFileStream::~DSFileStream() {
-	if (_writeBufferPos > 0) {
-		flush();
-	}
 	std_fclose((FILE *)_handle);
 }
 
@@ -417,12 +418,10 @@
 }
 
 int32 DSFileStream::pos() const {
-	assert(_writeBufferPos == 0);	// This method may only be called when reading!
 	return std_ftell((FILE *)_handle);
 }
 
 int32 DSFileStream::size() const {
-	assert(_writeBufferPos == 0);	// This method may only be called when reading!
 	int32 oldPos = std_ftell((FILE *)_handle);
 	std_fseek((FILE *)_handle, 0, SEEK_END);
 	int32 length = std_ftell((FILE *)_handle);
@@ -432,39 +431,18 @@
 }
 
 bool DSFileStream::seek(int32 offs, int whence) {
-	if (_writeBufferPos > 0) {
-		flush();
-	}
 	return std_fseek((FILE *)_handle, offs, whence) == 0;
 }
 
 uint32 DSFileStream::read(void *ptr, uint32 len) {
-	if (_writeBufferPos > 0) {
-		flush();
-	}
 	return std_fread(ptr, 1, len, (FILE *)_handle);
 }
 
 uint32 DSFileStream::write(const void *ptr, uint32 len) {
-	if (_writeBufferPos + len < WRITE_BUFFER_SIZE) {
-		memcpy(_writeBuffer + _writeBufferPos, ptr, len);
-		_writeBufferPos += len;
-		return len;
-	} else {
-		if (_writeBufferPos > 0) {
-			flush();
-		}
-		return std_fwrite(ptr, 1, len, (FILE *)_handle);
-	}
+	return std_fwrite(ptr, 1, len, (FILE *)_handle);
 }
 
 bool DSFileStream::flush() {
-
-	if (_writeBufferPos > 0) {
-		std_fwrite(_writeBuffer, 1, _writeBufferPos, (FILE *) _handle);
-		_writeBufferPos = 0;
-	}
-
 	return std_fflush((FILE *)_handle) == 0;
 }
 

Modified: scummvm/trunk/backends/fs/ds/ds-fs.h
===================================================================
--- scummvm/trunk/backends/fs/ds/ds-fs.h	2010-11-18 17:25:09 UTC (rev 54330)
+++ scummvm/trunk/backends/fs/ds/ds-fs.h	2010-11-18 17:30:00 UTC (rev 54331)
@@ -171,16 +171,10 @@
 
 class DSFileStream : public Common::SeekableReadStream, public Common::WriteStream, public Common::NonCopyable {
 protected:
-	enum {
-		WRITE_BUFFER_SIZE = 512
-	};
 
 	/** File handle to the actual file. */
 	void 	*_handle;
 
-	char	_writeBuffer[WRITE_BUFFER_SIZE];
-	int	_writeBufferPos;
-
 public:
 	/**
 	 * Given a path, invokes fopen on that path and wrap the result in a


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