Update of /cvsroot/mahogany/M/src/modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18696/src/modules
Modified Files:
TextViewer.cpp
Log Message:
reduce the number of AppendText() calls by bundling together chunks of text
with the same style (this gives 10x speed up under Windows for messages with
few quotations/URLs and presumably even more under GTK2)
Index: TextViewer.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/modules/TextViewer.cpp,v
retrieving revision 1.64
retrieving revision 1.65
diff -b -u -2 -r1.64 -r1.65
--- TextViewer.cpp 29 Oct 2004 02:08:23 -0000 1.64
+++ TextViewer.cpp 2 Dec 2004 08:49:04 -0000 1.65
@@ -144,4 +144,7 @@
void InitPrinting();
+ // flush the contents of m_textToAppend if it is not empty
+ void FlushText();
+
// the viewer window
@@ -154,4 +157,8 @@
wxString m_textFind;
+ // calling AppendText() each time is too slow, so we collect all text with
+ // the same style in this variable and then FlushText() it all at once
+ wxString m_textToAppend;
+
#if wxUSE_PRINTING_ARCHITECTURE
// the object which does the printing
@@ -556,4 +563,13 @@
}
+void TextViewer::FlushText()
+{
+ if ( !m_textToAppend.empty() )
+ {
+ m_window->AppendText(m_textToAppend);
+ m_textToAppend.clear();
+ }
+}
+
// ----------------------------------------------------------------------------
// TextViewer operations
@@ -670,14 +686,20 @@
void TextViewer::ShowHeaderName(const String& name)
{
+ // flush previous text before the style change
+ FlushText();
+
const ProfileValues& profileValues = GetOptions();
+ // change the style for the header name
MTextStyle attr(profileValues.HeaderNameCol);
wxFont font = m_window->GetFont();
font.SetWeight(wxFONTWEIGHT_BOLD);
attr.SetFont(font);
+ m_window->SetDefaultStyle(attr);
- InsertText(name + _T(": "), attr);
+ // do show it
+ m_window->AppendText(name + _T(": "));
- // restore the non bold font
+ // and restore the non bold font for the header value which will follow
attr.SetFont(m_window->GetFont());
m_window->SetDefaultStyle(attr);
@@ -735,9 +757,11 @@
// put a blank line before each part start - including the very first one to
// separate it from the headers
- m_window->AppendText(_T("\n"));
+ InsertText(_T("\n"), MTextStyle());
}
void TextViewer::InsertAttachment(const wxBitmap& /* icon */, ClickableInfo
*ci)
{
+ FlushText();
+
String str;
str << _("[Attachment: ") << ci->GetLabel() << _T(']');
@@ -750,4 +774,6 @@
const wxColour& col)
{
+ FlushText();
+
String str;
str << _T('[') << ci->GetLabel() << _T(']');
@@ -773,15 +799,26 @@
void TextViewer::InsertText(const String& text, const MTextStyle& style)
{
+ // check if we need to change style
+ wxTextAttr old = m_window->GetDefaultStyle();
+ if ( (style.HasTextColour() &&
+ style.GetTextColour() != old.GetTextColour()) ||
+ (style.HasBackgroundColour() &&
+ style.GetBackgroundColour() != old.GetBackgroundColour()) ||
+ (style.HasFont() && style.GetFont() != old.GetFont()) )
+ {
+ // we do, flush the text in old style
+ FlushText();
+
+ // and set the new one
m_window->SetDefaultStyle(style);
+ }
-#ifdef OS_WIN
- m_window->AppendText(text);
-#else
- m_window->AppendText(wxTextBuffer::Translate(text, wxTextFileType_Unix));
-#endif
+ m_textToAppend += text;
}
void TextViewer::InsertURL(const String& text, const String& url)
{
+ FlushText();
+
m_window->InsertClickable(text,
new ClickableURL(m_msgView, url),
@@ -791,5 +828,5 @@
void TextViewer::EndPart()
{
- // this function intentionally left (almost) blank
+ FlushText();
}
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates