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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Nov 18 21:27:15 CET 2010


Revision: 54344
          http://scummvm.svn.sourceforge.net/scummvm/?rev=54344&view=rev
Author:   fingolfin
Date:     2010-11-18 20:27:15 +0000 (Thu, 18 Nov 2010)

Log Message:
-----------
COMMON: Change wrapBufferedWriteStream() to always disposes wrapped stream

This is the only we need right now, and it saves a few bytes per
instance. The template approach I used before has the drawback that it
increases the binary size, which negates the benefit. Thanks to LordHoto
for pointing this out.

Modified Paths:
--------------
    scummvm/trunk/backends/fs/ds/ds-fs.cpp
    scummvm/trunk/backends/fs/psp/psp-fs.cpp
    scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.cpp
    scummvm/trunk/common/stream.cpp
    scummvm/trunk/common/stream.h

Modified: scummvm/trunk/backends/fs/ds/ds-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/ds/ds-fs.cpp	2010-11-18 20:24:27 UTC (rev 54343)
+++ scummvm/trunk/backends/fs/ds/ds-fs.cpp	2010-11-18 20:27:15 UTC (rev 54344)
@@ -210,7 +210,7 @@
 
 Common::WriteStream *DSFileSystemNode::createWriteStream() {
 	Common::WriteStream *stream = DSFileStream::makeFromPath(getPath(), true);
-	return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE, DisposeAfterUse::YES);
+	return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE);
 }
 
 //////////////////////////////////////////////////////////////////////////
@@ -392,7 +392,7 @@
 
 Common::WriteStream *GBAMPFileSystemNode::createWriteStream() {
 	Common::WriteStream *stream = DSFileStream::makeFromPath(getPath(), true);
-	return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE, DisposeAfterUse::YES);
+	return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE);
 }
 
 

Modified: scummvm/trunk/backends/fs/psp/psp-fs.cpp
===================================================================
--- scummvm/trunk/backends/fs/psp/psp-fs.cpp	2010-11-18 20:24:27 UTC (rev 54343)
+++ scummvm/trunk/backends/fs/psp/psp-fs.cpp	2010-11-18 20:27:15 UTC (rev 54344)
@@ -259,7 +259,7 @@
 
 	Common::WriteStream *stream = PspIoStream::makeFromPath(getPath(), true);
 
-	return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE, DisposeAfterUse::YES);
+	return Common::wrapBufferedWriteStream(stream, WRITE_BUFFER_SIZE);
 }
 
 #endif //#ifdef __PSP__

Modified: scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.cpp
===================================================================
--- scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.cpp	2010-11-18 20:24:27 UTC (rev 54343)
+++ scummvm/trunk/backends/platform/ds/arm9/source/gbampsave.cpp	2010-11-18 20:27:15 UTC (rev 54344)
@@ -58,7 +58,7 @@
 	
 	Common::WriteStream *stream = DS::DSFileStream::makeFromPath(fileSpec, true);
 	// Use a write buffer
-	stream = Common::wrapBufferedWriteStream(stream, SAVE_BUFFER_SIZE, DisposeAfterUse::YES);
+	stream = Common::wrapBufferedWriteStream(stream, SAVE_BUFFER_SIZE);
 	return stream;
 }
 

Modified: scummvm/trunk/common/stream.cpp
===================================================================
--- scummvm/trunk/common/stream.cpp	2010-11-18 20:24:27 UTC (rev 54343)
+++ scummvm/trunk/common/stream.cpp	2010-11-18 20:27:15 UTC (rev 54344)
@@ -421,7 +421,6 @@
 /**
  * Wrapper class which adds buffering to any WriteStream.
  */
-template <DisposeAfterUse::Flag _disposeParentStream>
 class BufferedWriteStream : public WriteStream {
 protected:
 	WriteStream *_parentStream;
@@ -462,8 +461,7 @@
 		const bool flushResult = flushBuffer();
 		assert(flushResult);
 
-		if (_disposeParentStream)
-			delete _parentStream;
+		delete _parentStream;
 
 		delete[] _buf;
 	}
@@ -492,15 +490,9 @@
 
 }	// End of nameless namespace
 
-WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream) {
-	if (parentStream) {
-		switch (disposeParentStream) {
-		case DisposeAfterUse::YES:
-			return new BufferedWriteStream<DisposeAfterUse::YES>(parentStream, bufSize);
-		case DisposeAfterUse::NO:
-			return new BufferedWriteStream<DisposeAfterUse::NO>(parentStream, bufSize);
-		}
-	}
+WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize) {
+	if (parentStream)
+		return new BufferedWriteStream(parentStream, bufSize);
 	return 0;
 }
 

Modified: scummvm/trunk/common/stream.h
===================================================================
--- scummvm/trunk/common/stream.h	2010-11-18 20:24:27 UTC (rev 54343)
+++ scummvm/trunk/common/stream.h	2010-11-18 20:27:15 UTC (rev 54344)
@@ -508,13 +508,13 @@
 /**
  * Take an arbitrary WriteStream and wrap it in a custom stream which
  * transparently provides buffering.
- * Users can specify how big the buffer should be, and whether the wrapped
- * stream should be disposed when the wrapper is disposed.
+ * Users can specify how big the buffer should be. Currently, the
+ * parent stream is \em always disposed when the wrapper is disposed.
  *
  * It is safe to call this with a NULL parameter (in this case, NULL is
  * returned).
  */
-WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream);
+WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize);
 
 /**
  * Simple memory based 'stream', which implements the ReadStream interface for


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