From: spog Date: Mon, 20 Feb 2006 23:14:51 +0000 (+0000) Subject: added buffering to minimise GtkTextBuffer insert calls X-Git-Tag: xonotic-v0.7.0~16^2~12^2~277 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=commitdiff_plain;h=8c19a03806d0a06596036625adaacced47c44431 added buffering to minimise GtkTextBuffer insert calls git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@17 8a3a26a2-13c4-0310-b231-cf6edde360e5 --- diff --git a/libs/archivelib.h b/libs/archivelib.h index 8071ab90..710d2e8a 100644 --- a/libs/archivelib.h +++ b/libs/archivelib.h @@ -36,28 +36,27 @@ template class SingleByteInputStream { typedef typename InputStreamType::byte_type byte_type; - static const int BUFFERSIZE = SIZE; InputStreamType& m_inputStream; - byte_type m_buffer[BUFFERSIZE]; + byte_type m_buffer[SIZE]; byte_type* m_cur; byte_type* m_end; public: - SingleByteInputStream(InputStreamType& inputStream) : m_inputStream(inputStream), m_cur(m_buffer + BUFFERSIZE), m_end(m_cur) + SingleByteInputStream(InputStreamType& inputStream) : m_inputStream(inputStream), m_cur(m_buffer + SIZE), m_end(m_cur) { } bool readByte(byte_type& b) { if(m_cur == m_end) { - if(m_end != m_buffer + BUFFERSIZE) + if(m_end != m_buffer + SIZE) { return false; } - m_end = m_buffer + m_inputStream.read(m_buffer, BUFFERSIZE); + m_end = m_buffer + m_inputStream.read(m_buffer, SIZE); m_cur = m_buffer; if(m_end == m_buffer) diff --git a/libs/debugging/debugging.h b/libs/debugging/debugging.h index 93dd0995..2a9cbe70 100644 --- a/libs/debugging/debugging.h +++ b/libs/debugging/debugging.h @@ -128,6 +128,7 @@ if(!globalDebugMessageHandler().handleMessage()) { DEBUGGER_BREAKPOINT(); } else #else #define ASSERT_MESSAGE(condition, message) +#define ERROR_MESSAGE(message) #define ASSERT_NOTNULL(ptr) #endif diff --git a/libs/scenelib.h b/libs/scenelib.h index 71d4963b..a5be2413 100644 --- a/libs/scenelib.h +++ b/libs/scenelib.h @@ -122,7 +122,7 @@ template class StaticNodeType { public: - static const int SIZE = NODETYPEID_MAX; + enum unnamed0 { SIZE = NODETYPEID_MAX }; static TypeId getTypeId() { return Static< NodeType >::instance().getTypeId(); @@ -161,10 +161,10 @@ namespace scene class Node { public: - static const int eVisible = 0; - static const int eHidden = 1 << 0; - static const int eFiltered = 1 << 1; - static const int eExcluded = 1 << 2; + enum unnamed0 { eVisible = 0 }; + enum unnamed1 { eHidden = 1 << 0 }; + enum unnamed2 { eFiltered = 1 << 1 }; + enum unnamed3 { eExcluded = 1 << 2 }; class Symbiot { @@ -483,7 +483,7 @@ template class StaticInstanceType { public: - static const int SIZE = INSTANCETYPEID_MAX; + enum unnamed0 { SIZE = INSTANCETYPEID_MAX }; static TypeId getTypeId() { return Static< InstanceType >::instance().getTypeId(); diff --git a/libs/stream/textstream.h b/libs/stream/textstream.h index ddc6cf45..083026bc 100644 --- a/libs/stream/textstream.h +++ b/libs/stream/textstream.h @@ -389,4 +389,87 @@ public: } }; +/// \brief A wrapper for a TextOutputStream, optimised for writing a single character at a time. +class SingleCharacterOutputStream : public TextOutputStream +{ + enum unnamed0 { m_bufsize = 1024 }; + TextOutputStream& m_ostream; + char m_buffer[m_bufsize]; + char* m_pos; + const char* m_end; + + const char* end() const + { + return m_end; + } + void reset() + { + m_pos = m_buffer; + } + void flush() + { + m_ostream.write(m_buffer, m_pos - m_buffer); + reset(); + } +public: + SingleCharacterOutputStream(TextOutputStream& ostream) : m_ostream(ostream), m_pos(m_buffer), m_end(m_buffer+m_bufsize) + { + } + ~SingleCharacterOutputStream() + { + flush(); + } + void write(const char c) + { + if(m_pos == end()) + { + flush(); + } + *m_pos++ = c; + } + std::size_t write(const char* buffer, std::size_t length) + { + const char*const end = buffer + length; + for(const char* p = buffer; p != end; ++p) + { + write(*p); + } + return length; + } +}; + +/// \brief A wrapper for a TextOutputStream, optimised for writing a few characters at a time. +template +class BufferedTextOutputStream : public TextOutputStream +{ + TextOutputStreamType outputStream; + char m_buffer[SIZE]; + char* m_cur; + +public: + BufferedTextOutputStream(TextOutputStreamType& outputStream) : outputStream(outputStream), m_cur(m_buffer) + { + } + ~BufferedTextOutputStream() + { + outputStream.write(m_buffer, m_cur - m_buffer); + } + std::size_t write(const char* buffer, std::size_t length) + { + std::size_t remaining = length; + for(;;) + { + std::size_t n = std::min(remaining, std::size_t((m_buffer + SIZE) - m_cur)); + m_cur = std::copy(buffer, buffer + n, m_cur); + remaining -= n; + if(remaining == 0) + { + return 0; + } + outputStream.write(m_buffer, SIZE); + m_cur = m_buffer; + } + } +}; + #endif diff --git a/libs/xml/xmlparser.h b/libs/xml/xmlparser.h index 3140888b..bea4557a 100644 --- a/libs/xml/xmlparser.h +++ b/libs/xml/xmlparser.h @@ -201,7 +201,7 @@ public: class XMLStreamParser : public XMLExporter { - static const int BUFSIZE = 1024; + enum unnamed0 { BUFSIZE = 1024 }; public: XMLStreamParser(TextInputStream& istream) : m_istream(istream) diff --git a/libs/xml/xmlwriter.h b/libs/xml/xmlwriter.h index 8cf40bdd..d387f320 100644 --- a/libs/xml/xmlwriter.h +++ b/libs/xml/xmlwriter.h @@ -26,57 +26,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include "xml/ixml.h" -class BufferedTextOutputStream : public TextOutputStream -{ - static const int m_bufsize = 1024; - TextOutputStream& m_ostream; - char m_buffer[m_bufsize]; - char* m_pos; - const char* m_end; - - const char* end() const - { - return m_end; - } - void reset() - { - m_pos = m_buffer; - } - void flush() - { - m_ostream.write(m_buffer, m_pos - m_buffer); - reset(); - } -public: - BufferedTextOutputStream(TextOutputStream& ostream) : m_ostream(ostream), m_pos(m_buffer), m_end(m_buffer+m_bufsize) - { - } - ~BufferedTextOutputStream() - { - flush(); - } - void write(const char c) - { - if(m_pos == end()) - { - flush(); - } - *m_pos++ = c; - } - std::size_t write(const char* buffer, std::size_t length) - { - const char*const end = buffer + length; - for(const char* p = buffer; p != end; ++p) - { - write(*p); - } - return length; - } -}; - class XMLEntityOutputStream { - BufferedTextOutputStream m_ostream; + SingleCharacterOutputStream m_ostream; public: XMLEntityOutputStream(TextOutputStream& ostream) : m_ostream(ostream) diff --git a/plugins/archivezip/zlibstream.h b/plugins/archivezip/zlibstream.h index 3ce91796..63def546 100644 --- a/plugins/archivezip/zlibstream.h +++ b/plugins/archivezip/zlibstream.h @@ -33,7 +33,7 @@ class DeflatedInputStream : public InputStream { InputStream& m_istream; z_stream m_zipstream; - static const int m_bufsize = 1024; + enum unnamed0 { m_bufsize = 1024 }; unsigned char m_buffer[m_bufsize]; public: diff --git a/radiant/console.cpp b/radiant/console.cpp index 5c462405..f47c66da 100644 --- a/radiant/console.cpp +++ b/radiant/console.cpp @@ -206,14 +206,17 @@ std::size_t Sys_Print(int level, const char* buf, std::size_t length) } - GtkTextBufferOutputStream textBuffer(buffer, &iter, tag); - if(!globalCharacterSet().isUTF8()) { - textBuffer << ConvertLocaleToUTF8(StringRange(buf, buf + length)); - } - else - { - textBuffer << StringRange(buf, buf + length); + GtkTextBufferOutputStream textBuffer(buffer, &iter, tag); + if(!globalCharacterSet().isUTF8()) + { + BufferedTextOutputStream buffered(textBuffer); + buffered << ConvertLocaleToUTF8(StringRange(buf, buf + length)); + } + else + { + textBuffer << StringRange(buf, buf + length); + } } // update console widget immediatly if we're doing something time-consuming diff --git a/radiant/undo.cpp b/radiant/undo.cpp index 5a15d34e..001adbf9 100644 --- a/radiant/undo.cpp +++ b/radiant/undo.cpp @@ -60,7 +60,7 @@ public: class RadiantUndoSystem : public UndoSystem { - static const int MAX_UNDO_LEVELS = 1024; + INTEGER_CONSTANT(MAX_UNDO_LEVELS, 1024); class Snapshot { @@ -295,9 +295,9 @@ public: } void setLevels(std::size_t levels) { - if(levels > MAX_UNDO_LEVELS) + if(levels > MAX_UNDO_LEVELS()) { - levels = MAX_UNDO_LEVELS; + levels = MAX_UNDO_LEVELS(); } while(m_undo_stack.size() > levels) diff --git a/radiant/xmlstuff.h b/radiant/xmlstuff.h index 34a52bf4..0ffb8e2b 100644 --- a/radiant/xmlstuff.h +++ b/radiant/xmlstuff.h @@ -58,7 +58,7 @@ struct message_info_t int geometry_depth; // are we parsing some geometry information (i.e. do we forward the SAX calls?) ISAXHandler* pGeometry; // the handler - static const int bufsize = 1024; + enum unnamed0 { bufsize = 1024 }; char m_buffer[bufsize]; std::size_t m_length; };