commit c2f2ba57f1275cdf37e38da7e45ce5bb9ee124b9
Author: Juergen Spitzmueller <[email protected]>
Date:   Mon Dec 20 12:09:12 2021 +0100

    Do not repeatedly call main_font_encoding()
    
    This method impacts on performance and we store the value anyway in
    the output params.
---
 src/BufferParams.cpp       |   18 +++++++++++-------
 src/LaTeXFeatures.cpp      |   14 +++++++-------
 src/Paragraph.cpp          |    4 ++--
 src/insets/InsetQuotes.cpp |   13 +++++--------
 src/insets/InsetQuotes.h   |    2 --
 5 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index a41a570..fc559a4 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -1847,7 +1847,8 @@ bool BufferParams::writeLaTeX(otexstream & os, 
LaTeXFeatures & features,
 
        // if we use fontspec or newtxmath, we have to load the AMS packages 
here
        string const ams = features.loadAMSPackages();
-       bool const ot1 = (main_font_encoding() == "default" || 
main_font_encoding() == "OT1");
+       string const main_font_enc = features.runparams().main_fontenc;
+       bool const ot1 = (main_font_enc == "default" || main_font_enc == "OT1");
        bool const use_newtxmath =
                
theLaTeXFonts().getLaTeXFont(from_ascii(fontsMath())).getUsedPackage(
                        ot1, false, false) == "newtxmath";
@@ -1887,7 +1888,7 @@ bool BufferParams::writeLaTeX(otexstream & os, 
LaTeXFeatures & features,
        // set font encoding
        // non-TeX fonts use font encoding TU (set by fontspec)
        if (!useNonTeXFonts && !features.isProvided("fontenc")
-           && main_font_encoding() != "default") {
+           && main_font_enc != "default") {
                // get main font encodings
                vector<string> fontencs = font_encodings();
                // get font encodings of secondary languages
@@ -3235,12 +3236,13 @@ string const BufferParams::dvips_options() const
 
 string const BufferParams::main_font_encoding() const
 {
-       if (font_encodings().empty()) {
+       vector<string> const fencs = font_encodings();
+       if (fencs.empty()) {
                if (ascii_lowercase(language->fontenc(*this)) == "none")
                        return "none";
                return "default";
        }
-       return font_encodings().back();
+       return fencs.back();
 }
 
 
@@ -3255,9 +3257,10 @@ vector<string> const BufferParams::font_encodings() const
                if (!doc_fontenc.empty())
                        // If we have a custom setting, we use only that!
                        return getVectorFromString(doc_fontenc);
-               if (!language->fontenc(*this).empty()
+               string const lfe = language->fontenc(*this);
+               if (!lfe.empty()
                    && ascii_lowercase(language->fontenc(*this)) != "none") {
-                       vector<string> fencs = 
getVectorFromString(language->fontenc(*this));
+                       vector<string> fencs = getVectorFromString(lfe);
                        for (auto & fe : fencs) {
                                if (find(fontencs.begin(), fontencs.end(), fe) 
== fontencs.end())
                                        fontencs.push_back(fe);
@@ -3509,7 +3512,8 @@ string const BufferParams::loadFonts(LaTeXFeatures & 
features) const
        }
 
        // Tex Fonts
-       bool const ot1 = (main_font_encoding() == "default" || 
main_font_encoding() == "OT1");
+       bool const ot1 = (features.runparams().main_fontenc == "default"
+                         || features.runparams().main_fontenc == "OT1");
        bool const dryrun = features.runparams().dryrun;
        bool const complete = (fontsSans() == "default" && fontsTypewriter() == 
"default");
        bool const nomath = (fontsMath() != "auto");
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 0344202..f321799 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -783,8 +783,8 @@ bool LaTeXFeatures::isProvided(string const & name) const
        if (params_.useNonTeXFonts)
                return params_.documentClass().provides(name);
 
-       bool const ot1 = (params_.main_font_encoding() == "default"
-               || params_.main_font_encoding() == "OT1");
+       bool const ot1 = (runparams().main_fontenc == "default"
+               || runparams().main_fontenc == "OT1");
        bool const complete = (params_.fontsSans() == "default"
                && params_.fontsTypewriter() == "default");
        bool const nomath = (params_.fontsMath() == "default");
@@ -1315,8 +1315,8 @@ string const LaTeXFeatures::getPackages() const
        // if fontspec or newtxmath is used, AMS packages have to be loaded
        // before fontspec (in BufferParams)
        string const amsPackages = loadAMSPackages();
-       bool const ot1 = (params_.main_font_encoding() == "default"
-                         || params_.main_font_encoding() == "OT1");
+       bool const ot1 = (runparams().main_fontenc == "default"
+                         || runparams().main_fontenc == "OT1");
        bool const use_newtxmath =
                
theLaTeXFonts().getLaTeXFont(from_ascii(params_.fontsMath())).getUsedPackage(
                        ot1, false, false) == "newtxmath";
@@ -1584,15 +1584,15 @@ TexString LaTeXFeatures::getMacros() const
                macros << lyxZWSP_def << '\n';
 
        if (!usePolyglossia() && mustProvide("textgreek")) {
-           // ensure LGR font encoding is defined also if fontenc is not 
loaded by LyX
-               if (params_.main_font_encoding() == "default")
+               // ensure LGR font encoding is defined also if fontenc is not 
loaded by LyX
+               if (runparams().main_fontenc == "default")
                        macros << textgreek_LGR_def;
                macros << textgreek_def << '\n';
        }
 
        if (!usePolyglossia() && mustProvide("textcyrillic")) {
                // ensure T2A font encoding is set up also if fontenc is not 
loaded by LyX
-               if (params_.main_font_encoding() == "default")
+               if (runparams().main_fontenc == "default")
                        macros << textcyr_T2A_def;
                macros << textcyr_def << '\n';
        }
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 2408261..6b960cd 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -1240,7 +1240,7 @@ void Paragraph::Private::latexSpecialChar(otexstream & os,
        //       non-standard font encoding. If we are using such a language,
        //       we do not output special T1 chars.
        if (!runparams.inIPA && !running_font.language()->internalFontEncoding()
-           && !runparams.isFullUnicode() && bparams.main_font_encoding() == 
"T1"
+           && !runparams.isFullUnicode() && runparams.main_fontenc == "T1"
            && latexSpecialT1(c, os, i, column))
                return;
        // NOTE: "fontspec" (non-TeX fonts) sets the font encoding to "TU" 
(untill 2017 "EU1" or "EU2")
@@ -1532,7 +1532,7 @@ void Paragraph::Private::validate(LaTeXFeatures & 
features) const
                if (c == 0x0022) {
                        if (features.runparams().isFullUnicode() && 
bp.useNonTeXFonts)
                                features.require("textquotedblp");
-                       else if (bp.main_font_encoding() != "T1"
+                       else if (features.runparams().main_fontenc != "T1"
                                 || ((&owner_->getFontSettings(bp, 
i))->language()->internalFontEncoding()))
                                features.require("textquotedbl");
                } else if (ci.textfeature() && contains(ci.textpreamble(), 
'=')) {
diff --git a/src/insets/InsetQuotes.cpp b/src/insets/InsetQuotes.cpp
index d503e8b..dc6dbba 100644
--- a/src/insets/InsetQuotes.cpp
+++ b/src/insets/InsetQuotes.cpp
@@ -639,11 +639,8 @@ InsetQuotes::InsetQuotes(Buffer * buf, char_type c, 
QuoteLevel level,
        bool dynamic = false;
        if (buf) {
                global_style_ = buf->masterBuffer()->params().quotes_style;
-               fontenc_ = buf->masterBuffer()->params().main_font_encoding();
                dynamic = buf->masterBuffer()->params().dynamic_quotes;
                fontspec_ = buf->masterBuffer()->params().useNonTeXFonts;
-       } else {
-               fontenc_ = "OT1";
        }
        if (style.empty())
                style_ = dynamic ? QuoteStyle::Dynamic : global_style_;
@@ -891,7 +888,7 @@ void InsetQuotes::latex(otexstream & os, OutputParams const 
& runparams) const
                // Use internal commands in headings with hyperref
                // (ligatures not featured in PDF strings)
                qstr = quoteparams.getLaTeXQuote(quotechar, "int", rtl_);
-       } else if (fontenc_ == "T1"
+       } else if (runparams.main_fontenc == "T1"
                   && 
!runparams.local_font->language()->internalFontEncoding()) {
                // Quotation marks for T1 font encoding
                // (using ligatures)
@@ -905,7 +902,7 @@ void InsetQuotes::latex(otexstream & os, OutputParams const 
& runparams) const
 #else
        } else if ((!runparams.use_babel
 #endif
-                  || (fontenc_ != "T1" && fontenc_ != "OT1"))
+                  || (runparams.main_fontenc != "T1" && runparams.main_fontenc 
!= "OT1"))
                   || runparams.isFullUnicode()) {
                // Standard quotation mark macros
                // These are also used by babel
@@ -1008,7 +1005,6 @@ void InsetQuotes::updateBuffer(ParIterator const & it, 
UpdateType /* utype*/, bo
        pass_thru_ = it.paragraph().isPassThru();
        context_lang_ = font.language()->code();
        internal_fontenc_ = font.language()->internalFontEncoding();
-       fontenc_ = bp.main_font_encoding();
        global_style_ = bp.quotes_style;
        fontspec_ = bp.useNonTeXFonts;
        rtl_ = font.isRightToLeft();
@@ -1028,7 +1024,8 @@ void InsetQuotes::validate(LaTeXFeatures & features) const
 #else
        if (!features.useBabel()
 #endif
-           && !features.runparams().isFullUnicode() && fontenc_ != "T1") {
+           && !features.runparams().isFullUnicode()
+           && features.runparams().main_fontenc != "T1") {
                switch (type) {
                case 0x201a:
                        features.require("quotesinglbase");
@@ -1065,7 +1062,7 @@ void InsetQuotes::validate(LaTeXFeatures & features) const
        case 0x0022: {
                if (features.runparams().isFullUnicode() && fontspec_)
                        features.require("textquotedblp");
-               else if (fontenc_ != "T1" || internal_fontenc_)
+               else if (features.runparams().main_fontenc != "T1" || 
internal_fontenc_)
                        features.require("textquotedbl");
                break;
        }
diff --git a/src/insets/InsetQuotes.h b/src/insets/InsetQuotes.h
index d1f23e4..c4b525c 100644
--- a/src/insets/InsetQuotes.h
+++ b/src/insets/InsetQuotes.h
@@ -200,8 +200,6 @@ private:
        QuoteLevel level_ = QuoteLevel::Primary;
        ///
        QuoteStyle global_style_ = QuoteStyle::English;
-       /// Current font encoding
-       std::string fontenc_;
        /// Code of the contextual language
        std::string context_lang_;
        /// Is this in a pass-thru context?
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to