# HG changeset patch
# User Michael Stahl <mst@openoffice.org>
# Date 1286553274 -7200
# Node ID 7d283082a94ca8cb7ab14eaf82cb56ba10b81afd
# Parent  f6126678ca827ccf4bdfb3959601c30ad5d3f196
rtftok01: speed up unicode text a lot by actually using the ustring buffer

diff --git a/writerfilter/source/rtftok/RTFDocumentImpl.cxx b/writerfilter/source/rtftok/RTFDocumentImpl.cxx
--- a/writerfilter/source/rtftok/RTFDocumentImpl.cxx
+++ b/writerfilter/source/rtftok/RTFDocumentImpl.cxx
@@ -309,11 +309,11 @@
     virtual void ctrl(Token_t const token, char const*const value)
     {
         m_NegativeCharacters = 0;
-        checkStrings();
         switch (token)
         {
             case RTF_u:
             {
+                checkString(); // no checkUString() here!
                 sal_Int32 const v(::rtl::OString(value).toInt32());
 fprintf(stderr, "RTFScannerHandlerImpl::ctrl: \\u%" SAL_PRIdINT32 "\n", v);
                 if ((SAL_MIN_INT16 <= v) && (v <= SAL_MAX_INT16)) {
@@ -324,6 +324,7 @@
             break;
             case RTF_uc:
             {
+                checkStrings();
                 sal_Int32 const v(::rtl::OString(value).toInt32());
                 if ((0 <= v) && (v < SAL_MAX_UINT16)) {
                     SetUnicodeCharacters(v);
@@ -332,6 +333,7 @@
             break;
             default:
             {
+                checkStrings();
                 m_Destinations.top().second->ctrl(token, value);
             }
             break;
@@ -363,17 +365,16 @@
     }
     virtual void addSpaces(unsigned int const count)
     {
-        checkUString();
-        unsigned int realCount(0);
-        if (count >= m_NegativeCharacters) {
-            realCount = count - m_NegativeCharacters;
+        if (count > m_NegativeCharacters) {
+            unsigned int const realCount(count - m_NegativeCharacters);
             m_NegativeCharacters = 0;
+            checkUString();
+            for (unsigned int i = 0; i < realCount; ++i) {
+                m_String.append(" ");
+            }
         } else {
             m_NegativeCharacters -= count;
         }
-        for (unsigned int i = 0; i < realCount; ++i) {
-            m_String.append(" ");
-        }
     }
     virtual void addBinData(unsigned char const /*data*/)
     {
@@ -381,11 +382,11 @@
     }
     virtual void addChar(char const ch)
     {
-        checkUString();
         if (0 != m_NegativeCharacters) {
 fprintf(stderr, "RTFScannerHandlerImpl::addChar: ignoring character '%c'(%x)\n", ch, ch);
             --m_NegativeCharacters; /* ignore the character */
         } else {
+            checkUString();
             m_String.append(ch);
         }
     }
