[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog libbase/noseek_fd_adapter.cpp
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog libbase/noseek_fd_adapter.cpp |
Date: |
Sun, 02 Dec 2007 23:43:14 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/12/02 23:43:14
Modified files:
. : ChangeLog
libbase : noseek_fd_adapter.cpp
Log message:
stop calling fstat and needlessly allocate/deallocate buffers.
Read in chunks of 512 bytes.
This makes reading from stdin more then 15 times faster.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5056&r2=1.5057
http://cvs.savannah.gnu.org/viewcvs/gnash/libbase/noseek_fd_adapter.cpp?cvsroot=gnash&r1=1.22&r2=1.23
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5056
retrieving revision 1.5057
diff -u -b -r1.5056 -r1.5057
--- ChangeLog 2 Dec 2007 14:54:32 -0000 1.5056
+++ ChangeLog 2 Dec 2007 23:43:13 -0000 1.5057
@@ -1,5 +1,11 @@
2007-12-02 Sandro Santilli <address@hidden>
+ * libbase/noseek_fd_adapter.cpp: stop calling fstat and needlessly
+ allocate/deallocate buffers. Read in chunks of 512 bytes.
+ This makes reading from stdin more then 15 times faster.
+
+2007-12-02 Sandro Santilli <address@hidden>
+
* libbase/: Makefile.am, tu_file.h, utility.h,
libmedia/AudioDecoderSimple.cpp, server/asobj/:
Global.cpp, string.cpp, server/vm/action.cpp:
Index: libbase/noseek_fd_adapter.cpp
===================================================================
RCS file: /sources/gnash/gnash/libbase/noseek_fd_adapter.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- libbase/noseek_fd_adapter.cpp 30 Oct 2007 18:55:41 -0000 1.22
+++ libbase/noseek_fd_adapter.cpp 2 Dec 2007 23:43:14 -0000 1.23
@@ -24,6 +24,7 @@
#include "utility.h"
#include "GnashException.h"
#include "log.h"
+
#include <unistd.h>
#include <cstring>
@@ -55,8 +56,7 @@
*
* NoSeekFile definition
*
- * TODO: optimize this class, it makes too many unneeded allocs/deallocs
- * and calls fstat far too often.
+ * TODO: cleanup this class, it makes too many seeks
*
**********************************************************************/
@@ -100,6 +100,9 @@
private:
+ /// Read buffer size
+ static const unsigned int chunkSize = 512;
+
// Open either a temporary file or a named file
// (depending on value of _cachefilename)
void openCacheFile();
@@ -119,6 +122,12 @@
// cache filename
const char* _cachefilename;
+ // Current size of cached data
+ long unsigned _cached;
+
+ // Current read buffer
+ char _buf[chunkSize];
+
// Attempt at filling the cache up to the given size.
void fill_cache(size_t size);
@@ -173,6 +182,8 @@
throw gnash::GnashException(errmsg);
}
+ _cached += sz;
+
#ifdef GNASH_NOSEEK_FD_VERBOSE
fprintf(stderr, " after write, position: %ld\n", ftell(_cache));
#endif
@@ -198,43 +209,35 @@
fprintf(stderr, "fill_cache(%d) called\n", size);
#endif
- struct stat statbuf;
-
// See how big is the cache
- fstat(_cachefd, &statbuf);
- if ( (size_t)statbuf.st_size >= size )
+ while ( _cached < size )
{
-#ifdef GNASH_NOSEEK_FD_VERBOSE
- fprintf(stderr,
- " big enough (%d), returning\n",
- statbuf.st_size);
-#endif
- return;
- }
// Let's see how many bytes are left to read
- size_t bytes_needed = size-statbuf.st_size;
+ unsigned int bytesNeeded = size-_cached;
+ if ( bytesNeeded > chunkSize ) bytesNeeded = chunkSize;
+
+ bytesNeeded = chunkSize; // why read less ?
+
#ifdef GNASH_NOSEEK_FD_VERBOSE
- fprintf(stderr, " bytes needed = " SIZET_FMT "\n", bytes_needed);
+ fprintf(stderr, " bytes needed = " SIZET_FMT "\n", bytesNeeded);
#endif
-
- boost::scoped_array<char> buf ( new char[bytes_needed] );
- int bytes_read = read(_fd, (void*)buf.get(), bytes_needed);
- if ( bytes_read < 0 )
+ ssize_t bytesRead = read(_fd, (void*)_buf, bytesNeeded);
+ if ( bytesRead < 0 )
{
fprintf(stderr,
"Error reading " SIZET_FMT " bytes from input stream",
- bytes_needed);
+ bytesNeeded);
_running = false;
// this looks like a CRITICAL error (since we don't handle it..)
throw gnash::GnashException("Error reading from input stream");
return;
}
- if ( static_cast<size_t>(bytes_read) < bytes_needed )
+ if ( static_cast<size_t>(bytesRead) < bytesNeeded )
{
- if ( bytes_read == 0 )
+ if ( bytesRead == 0 )
{
#ifdef GNASH_NOSEEK_FD_VERBOSE
fprintf(stderr, "EOF reached\n");
@@ -244,8 +247,9 @@
}
}
- cache(buf.get(), static_cast<size_t>(bytes_read));
+ cache(_buf, static_cast<size_t>(bytesRead));
+ }
}
/*private*/
@@ -283,7 +287,8 @@
:
_fd(fd),
_running(1),
- _cachefilename(filename)
+ _cachefilename(filename),
+ _cached(0)
{
// might throw an exception
openCacheFile();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog libbase/noseek_fd_adapter.cpp,
Sandro Santilli <=