From 2d9078735edfa1db1bd88c714ff16221e167fcc9 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Thu, 20 Feb 2014 15:31:44 +0100 Subject: [PATCH] fstream.cpp: prefer ftello/fseeko(), bitmap.cpp: huge speedup for EXR loading by avoiding fseek calls --- src/libcore/bitmap.cpp | 5 +++-- src/libcore/fstream.cpp | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libcore/bitmap.cpp b/src/libcore/bitmap.cpp index 8a5f4c9c..8fc1dea7 100644 --- a/src/libcore/bitmap.cpp +++ b/src/libcore/bitmap.cpp @@ -88,11 +88,12 @@ public: EXRIStream(Stream *stream) : IStream(stream->toString().c_str()), m_stream(stream) { m_offset = stream->getPos(); + m_size = stream->getSize(); } bool read(char *c, int n) { m_stream->read(c, n); - return m_stream->isEOF(); + return m_stream->getPos() == m_size; } Imf::Int64 tellg() { @@ -106,7 +107,7 @@ public: void clear() { } private: ref m_stream; - size_t m_offset; + size_t m_offset, m_size; }; class EXROStream : public Imf::OStream { diff --git a/src/libcore/fstream.cpp b/src/libcore/fstream.cpp index c4511417..ea3fbfaf 100644 --- a/src/libcore/fstream.cpp +++ b/src/libcore/fstream.cpp @@ -206,7 +206,7 @@ void FileStream::seek(size_t pos) { pos, d->path.string().c_str(), lastErrorText().c_str()); } #else - if (fseek(d->file, pos, SEEK_SET)) { + if (fseeko(d->file, (off_t) pos, SEEK_SET)) { Log(EError, "Error while trying to seek to position %i in file \"%s\": %s", pos, d->path.string().c_str(), strerror(errno)); } @@ -223,8 +223,7 @@ size_t FileStream::getPos() const { } return (size_t) pos; #else - long pos; - pos = ftell(d->file); + off_t pos = ftello(d->file); if (pos == -1) { Log(EError, "Error while looking up the position in file \"%s\": %s", d->path.string().c_str(), strerror(errno));