mirror of
https://github.com/TTimo/GtkRadiant.git
synced 2024-11-10 07:11:54 +00:00
added buffering to minimise GtkTextBuffer insert calls
git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@17 8a3a26a2-13c4-0310-b231-cf6edde360e5
This commit is contained in:
parent
eaad87408f
commit
8c19a03806
10 changed files with 111 additions and 73 deletions
|
@ -36,28 +36,27 @@ template<typename InputStreamType, int SIZE = 1024>
|
|||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -122,7 +122,7 @@ template<typename Type>
|
|||
class StaticNodeType
|
||||
{
|
||||
public:
|
||||
static const int SIZE = NODETYPEID_MAX;
|
||||
enum unnamed0 { SIZE = NODETYPEID_MAX };
|
||||
static TypeId getTypeId()
|
||||
{
|
||||
return Static< NodeType<Type> >::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<typename Type>
|
|||
class StaticInstanceType
|
||||
{
|
||||
public:
|
||||
static const int SIZE = INSTANCETYPEID_MAX;
|
||||
enum unnamed0 { SIZE = INSTANCETYPEID_MAX };
|
||||
static TypeId getTypeId()
|
||||
{
|
||||
return Static< InstanceType<Type> >::instance().getTypeId();
|
||||
|
|
|
@ -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<typename TextOutputStreamType, int SIZE = 1024>
|
||||
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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -26,57 +26,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
#include <vector>
|
||||
#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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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<GtkTextBufferOutputStream> 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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue