]> git.lyx.org Git - lyx.git/commitdiff
Paragraph:
authorAbdelrazak Younes <younes@lyx.org>
Sun, 19 Oct 2008 07:03:44 +0000 (07:03 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 19 Oct 2008 07:03:44 +0000 (07:03 +0000)
- constify some parameters
- getFontSettings():
- getFirstFontSettings(): return a const ref instead of a copy. This brings a consistent 4% improvement in LateX generation. Might speedup rtl handling too.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26957 a592a061-630c-0410-9148-cb99ea01b6c8

src/CutAndPaste.cpp
src/Paragraph.cpp
src/Paragraph.h
src/Session.cpp
src/Text.cpp
src/frontends/qt4/GuiCompleter.cpp
src/lyxfind.cpp
src/paragraph_funcs.cpp

index 5f1410726b5215f0ba6bda8e2ba46a53b4e1cfb3..8a13b87fdf10ed11db07d370facb4af84f578d99 100644 (file)
@@ -915,7 +915,7 @@ void replaceSelectionWithString(Cursor & cur, docstring const & str, bool backwa
        DocIterator selbeg = cur.selectionBegin();
 
        // Get font setting before we cut
-       Font const font =
+       Font const font =
                selbeg.paragraph().getFontSettings(cur.buffer().params(), selbeg.pos());
 
        // Insert the new string
index 1b6d5f7ccd4f707a066cd669cd90166e106a75fd..61ca78ae1364bca4afcdfad468aa1f5990ad2858 100644 (file)
@@ -109,7 +109,7 @@ public:
        /// specified by the latex macro \p ltx, to \p os starting from \p i.
        /// \return the number of characters written.
        int writeScriptChars(odocstream & os, docstring const & ltx,
-                          Change &, Encoding const &, pos_type & i);
+                          Change const &, Encoding const &, pos_type & i);
 
        /// This could go to ParagraphParameters if we want to.
        int startTeXParParams(BufferParams const &, odocstream &, TexRow &,
@@ -135,9 +135,9 @@ public:
        ///
        void latexSpecialChar(
                                   odocstream & os,
-                                  OutputParams & runparams,
-                                  Font & running_font,
-                                  Change & running_change,
+                                  OutputParams const & runparams,
+                                  Font const & running_font,
+                                  Change const & running_change,
                                   Layout const & style,
                                   pos_type & i,
                                   unsigned int & column);
@@ -146,20 +146,20 @@ public:
        bool latexSpecialT1(
                char_type const c,
                odocstream & os,
-               pos_type i,
+               pos_type i,
                unsigned int & column);
        ///
        bool latexSpecialTypewriter(
                char_type const c,
                odocstream & os,
-               pos_type i,
+               pos_type i,
                unsigned int & column);
        ///
        bool latexSpecialPhrase(
                odocstream & os,
                pos_type & i,
                unsigned int & column,
-               OutputParams & runparams);
+               OutputParams const & runparams);
 
        ///
        void validate(LaTeXFeatures & features,
@@ -603,7 +603,7 @@ bool Paragraph::Private::simpleTeXBlanks(OutputParams const & runparams,
 
 int Paragraph::Private::writeScriptChars(odocstream & os,
                                         docstring const & ltx,
-                                        Change & runningChange,
+                                        Change const & runningChange,
                                         Encoding const & encoding,
                                         pos_type & i)
 {
@@ -840,9 +840,9 @@ void Paragraph::Private::latexInset(
 
 void Paragraph::Private::latexSpecialChar(
                                             odocstream & os,
-                                            OutputParams & runparams,
-                                            Font & running_font,
-                                            Change & running_change,
+                                            OutputParams const & runparams,
+                                            Font const & running_font,
+                                            Change const & running_change,
                                             Layout const & style,
                                             pos_type & i,
                                             unsigned int & column)
@@ -970,7 +970,7 @@ void Paragraph::Private::latexSpecialChar(
 
 
 bool Paragraph::Private::latexSpecialT1(char_type const c, odocstream & os,
-       pos_type i, unsigned int & column)
+       pos_type i, unsigned int & column)
 {
        switch (c) {
        case '>':
@@ -998,7 +998,7 @@ bool Paragraph::Private::latexSpecialT1(char_type const c, odocstream & os,
 
 
 bool Paragraph::Private::latexSpecialTypewriter(char_type const c, odocstream & os,
-       pos_type i, unsigned int & column)
+       pos_type i, unsigned int & column)
 {
        switch (c) {
        case '-':
@@ -1020,7 +1020,7 @@ bool Paragraph::Private::latexSpecialTypewriter(char_type const c, odocstream &
 
 
 bool Paragraph::Private::latexSpecialPhrase(odocstream & os, pos_type & i,
-       unsigned int & column, OutputParams & runparams)
+       unsigned int & column, OutputParams const & runparams)
 {
        // FIXME: if we have "LaTeX" with a font
        // change in the middle (before the 'T', then
@@ -1327,7 +1327,7 @@ void Paragraph::resetFonts(Font const & font)
 }
 
 // Gets uninstantiated font setting at position.
-Font const Paragraph::getFontSettings(BufferParams const & bparams,
+Font const Paragraph::getFontSettings(BufferParams const & bparams,
                                         pos_type pos) const
 {
        if (pos > size()) {
@@ -1342,7 +1342,16 @@ Font const Paragraph::getFontSettings(BufferParams const & bparams,
        if (pos == size() && !empty())
                return getFontSettings(bparams, pos - 1);
 
-       return Font(inherit_font, getParLanguage(bparams));
+       // Optimisation: avoid a full font instantiation if there is no
+       // language change from previous call.
+       static Font previous_font;
+       static Language const * previous_lang = 0;
+       Language const * lang = getParLanguage(bparams);
+       if (lang != previous_lang) {
+               previous_lang = lang;
+               previous_font = Font(inherit_font, lang);
+       }
+       return previous_font;
 }
 
 
@@ -1373,12 +1382,21 @@ FontSpan Paragraph::fontSpan(pos_type pos) const
 
 
 // Gets uninstantiated font setting at position 0
-Font const Paragraph::getFirstFontSettings(BufferParams const & bparams) const
+Font const Paragraph::getFirstFontSettings(BufferParams const & bparams) const
 {
        if (!empty() && !d->fontlist_.empty())
                return d->fontlist_.begin()->font();
 
-       return Font(inherit_font, bparams.language);
+       // Optimisation: avoid a full font instantiation if there is no
+       // language change from previous call.
+       static Font previous_font;
+       static Language const * previous_lang = 0;
+       if (bparams.language != previous_lang) {
+               previous_lang = bparams.language;
+               previous_font = Font(inherit_font, bparams.language);
+       }
+
+       return previous_font;
 }
 
 
index 06318200c92aa0720111828ee95c270386b6b301..87576afe1f2a31909a3df79d40777a8ac4afd00a 100644 (file)
@@ -253,10 +253,10 @@ public:
            between the characters font and the layoutfont.
            This is what is stored in the fonttable
        */
-       Font const
+       Font const &
        getFontSettings(BufferParams const &, pos_type pos) const;
        ///
-       Font const getFirstFontSettings(BufferParams const &) const;
+       Font const getFirstFontSettings(BufferParams const &) const;
 
        /** Get fully instantiated font. If pos == -1, use the layout
            font attached to this paragraph.
index f09d2f6b73b87de539420c485d2052b792ddac90..804364651766d8d46b8684784cf517c08d9f9d39 100644 (file)
@@ -14,6 +14,7 @@
 #include "Session.h"
 
 #include "support/debug.h"
+#include "support/FileNameList.h"
 #include "support/filetools.h"
 #include "support/Package.h"
 
@@ -102,31 +103,23 @@ void LastFilesSection::setNumberOfLastFiles(unsigned int no)
 }
 
 
-void LastOpenedSection::read(istream & is)
+void LastOpenedSection::read(istream & /*is*/)
 {
-       string tmp;
-       do {
-               char c = is.peek();
-               if (c == '[')
-                       break;
-               getline(is, tmp);
-               FileName const file(tmp);
-               if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ' || !file.isAbsolute())
-                       continue;
-
-               if (file.exists() && !file.isDirectory())
-                       lastopened.push_back(file);
+       lastopened.clear();
+       FileNameList list;// = theApp()->fileNameListFromSession("last_opened");
+       for (size_t i = 0; i != list.size(); ++i) {
+               FileName const & file = list[i];
+               if (!file.isAbsolute() || !file.exists() || file.isDirectory())
+                       LYXERR(Debug::INIT, "Warning: invalid last opened file: " << file);
                else
-                       LYXERR(Debug::INIT, "LyX: Warning: Ignore last opened file: " << tmp);
-       } while (is.good());
+                       lastopened.push_back(file);
+       }
 }
 
 
-void LastOpenedSection::write(ostream & os) const
+void LastOpenedSection::write(ostream & /*os*/) const
 {
-       os << '\n' << sec_lastopened << '\n';
-       copy(lastopened.begin(), lastopened.end(),
-            ostream_iterator<FileName>(os, "\n"));
+       //theApp()->toSession(lastopened);
 }
 
 
index f6b676b57deb7b6d29fb3edd95776c6a41251552..3465a0850e5087d2358b9420bbfa9bd99797f321 100644 (file)
@@ -1541,11 +1541,11 @@ void Text::charsTranspose(Cursor & cur)
 
        // Store the characters to be transposed (including font information).
        char_type char1 = par.getChar(pos1);
-       Font const font1 =
+       Font const font1 =
                par.getFontSettings(cur.buffer().params(), pos1);
 
        char_type char2 = par.getChar(pos2);
-       Font const font2 =
+       Font const font2 =
                par.getFontSettings(cur.buffer().params(), pos2);
 
        // And finally, we are ready to perform the transposition.
index 0c4a73206459e9d68a59b0264d75ea53d843fecc..0e81aa034458b69f28a48eb92c266e1b2526cab3 100644 (file)
@@ -455,7 +455,7 @@ void GuiCompleter::updateModel(Cursor & cur, bool popupUpdate, bool inlineUpdate
        bool rtl = false;
        if (cur.inTexted()) {
                Paragraph const & par = cur.paragraph();
-               Font const font =
+               Font const font =
                        par.getFontSettings(cur.bv().buffer().params(), cur.pos());
                rtl = font.isVisibleRightToLeft();
        }
index 00bc9d51def3f9f1de0699839ef86cdf9979c61a..0cfd2cf86861d80a20468cad3250419f90160c20 100644 (file)
@@ -158,7 +158,7 @@ int replaceAll(BufferView * bv,
        cur.setCursor(doc_iterator_begin(buf.inset()));
        while (findForward(cur, match, false)) {
                pos_type pos = cur.pos();
-               Font const font
+               Font const font
                        = cur.paragraph().getFontSettings(buf.params(), pos);
                cur.recordUndo();
                int striked = ssize - cur.paragraph().eraseChars(pos, pos + ssize,
index d8a7a858fb00945345ad0d055717b258cdb0bd2c..e59e4a5909ef05df2e6b0d6a512ed0a920a37c61 100644 (file)
@@ -36,7 +36,7 @@ static bool moveItem(Paragraph & fromPar, pos_type fromPos,
        // Note: moveItem() does not honour change tracking!
        // Therefore, it should only be used for breaking and merging paragraphs
 
-       Font const tmpFont = fromPar.getFontSettings(params, fromPos);
+       Font const tmpFont = fromPar.getFontSettings(params, fromPos);
        Change const & tmpChange = fromPar.lookupChange(fromPos);
 
        if (Inset * tmpInset = fromPar.getInset(fromPos)) {
@@ -123,7 +123,7 @@ void breakParagraph(BufferParams const & bparams,
                // breaking paragraph.
                if (tmp->empty()) {
                        Font changed = tmp->getFirstFontSettings(bparams);
-                       Font old = par.getFontSettings(bparams, par.size());
+                       Font const & old = par.getFontSettings(bparams, par.size());
                        changed.setLanguage(old.language());
                        tmp->setFont(0, changed);
                }