]> git.lyx.org Git - features.git/commitdiff
microoptimization
authorAndré Pönitz <poenitz@gmx.net>
Sun, 22 Oct 2006 19:33:37 +0000 (19:33 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Sun, 22 Oct 2006 19:33:37 +0000 (19:33 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15493 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/qt_helpers.C
src/frontends/qt4/qt_helpers.h

index 9c25e1dddac8c9aa626bdba1cfdce83eb369548a..56c20699b682ea5b305ded172c81aa27fd6d45e9 100644 (file)
@@ -111,36 +111,12 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
 }
 
 
-QString const toqstr(char const * str)
-{
-       return QString::fromUtf8(str);
-}
-
-
-QString const toqstr(string const & str)
-{
-       return toqstr(str.c_str());
-}
-
-
-void ucs4_to_qstring(char_type const * str, size_t ls, QString & s)
-{
-       s.reserve(ls);
-       s.clear();
-
-       for (size_t i = 0; i < ls; ++i)
-               s.append(ucs4_to_qchar(str[i]));
-}
-
-
 void ucs4_to_qstring(lyx::docstring const & str, QString & s)
 {
-       size_t ls = str.size(); 
-       s.reserve(ls);
-       s.clear();
-
-       for (size_t i = 0; i < ls; ++i)
-               s.append(ucs4_to_qchar(str[i]));
+       size_t const ls = str.size(); 
+       s.resize(ls);
+       for (int i = ls; --i >= 0; )
+               s[i] = ucs4_to_qchar(str[i]);
 }
 
 
@@ -156,7 +132,6 @@ QString const toqstr(docstring const & ucs4)
 {
        QString s;
        ucs4_to_qstring(ucs4, s);
-
        return s;
 }
 
@@ -167,7 +142,6 @@ docstring const qstring_to_ucs4(QString const & qstr)
        docstring ucs4;
        for (int i = 0; i < ls; ++i)
                ucs4 += static_cast<char_type>(qstr[i].unicode());
-
        return ucs4;
 }
 
index fa96925da49d6303ec276266875a3b54cc3b59fc..57c68f285a6e56878098849602afd226c523aba4 100644 (file)
 #include "support/docstring.h"
 
 #include <QChar>
+#include <QString>
 
 #include <vector>
 #include <utility>
 
 class QComboBox;
 class QLineEdit;
-class QString;
 
 class LengthCombo;
 
@@ -45,12 +45,15 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
 docstring const formatted(docstring const & text, int w = 80);
 
 /**
- * toqstr - convert char * into unicode
+ * toqstr - convert char * into Qt's unicode (UTF16)
  *
  * Use this whenever there's a user-visible string that is encoded
  * for the locale (menus, dialogs etc.)
  */
-QString const toqstr(char const * str);
+inline QString const toqstr(char const * str)
+{
+       return QString::fromUtf8(str);
+}
 
 
 /**
@@ -59,7 +62,10 @@ QString const toqstr(char const * str);
  * Use this whenever there's a user-visible string that is encoded
  * for the locale (menus, dialogs etc.)
  */
-QString const toqstr(std::string const & str);
+inline QString const toqstr(std::string const & str)
+{
+       return toqstr(str.c_str());
+}
 
 
 /**
@@ -67,26 +73,32 @@ QString const toqstr(std::string const & str);
  *
  * QString uses utf16 internally.
  */
-QString const toqstr(docstring const & ucs4);
+inline char_type const qchar_to_ucs4(QChar const & qchar) {
+       return static_cast<char_type>(qchar.unicode());
+}
 
-void ucs4_to_qstring(char_type const * str, size_t ls, QString & s);
+inline QChar const ucs4_to_qchar(char_type const ucs4) {
+       return QChar(static_cast<unsigned short>(ucs4));
+}
+
+QString const toqstr(docstring const & ucs4);
 
 void ucs4_to_qstring(docstring const & str, QString & s);
 
+inline void ucs4_to_qstring(char_type const * str, size_t ls, QString & s)
+{
+       s.resize(ls);
+       for (int i = ls; --i >= 0; )
+               s[i] = ucs4_to_qchar(str[i]);
+}
+
+
 QString ucs4_to_qstring(docstring const & str);
 
 docstring const qstring_to_ucs4(QString const & qstr);
 
 void qstring_to_ucs4(QString const & qstr, std::vector<char_type> & ucs4);
 
-inline char_type const qchar_to_ucs4(QChar const & qchar) {
-       return static_cast<char_type>(qchar.unicode());
-}
-
-inline QChar const ucs4_to_qchar(char_type const ucs4) {
-       return QChar(static_cast<unsigned short>(ucs4));
-}
-
 /**
  * qt_ - i18nize string and convert to unicode
  *