Note that, as shown in the new last line, removing lexical_cast _and_ signals2 
is the big win here.

JMarc

Here is the first step -- removing lexical_cast.

Yuriy

From 379ae9e7110b027c647aa4c34b906deeaa87a838 Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.ska...@gmail.com>
Date: Thu, 10 Dec 2020 14:32:55 +0200
Subject: [PATCH 1/2] Remove unnecessary `c_str`

---
 src/graphics/PreviewLoader.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp
index 63ddd43639..d0590f6b28 100644
--- a/src/graphics/PreviewLoader.cpp
+++ b/src/graphics/PreviewLoader.cpp
@@ -380,8 +380,8 @@ PreviewLoader::Impl::Impl(PreviewLoader & p, Buffer const & 
b)
 {
        font_scaling_factor_ = int(buffer_.fontScalingFactor());
        if (theApp()) {
-               fg_color_ = 
convert(theApp()->hexName(foregroundColor()).c_str(), 16);
-               bg_color_ = 
convert(theApp()->hexName(backgroundColor()).c_str(), 16);
+               fg_color_ = convert(theApp()->hexName(foregroundColor()), 16);
+               bg_color_ = convert(theApp()->hexName(backgroundColor()), 16);
        } else {
                fg_color_ = 0x0;
                bg_color_ = 0xffffff;
@@ -444,8 +444,8 @@ PreviewLoader::Impl::preview(string const & latex_snippet) 
const
        int fg = 0x0;
        int bg = 0xffffff;
        if (theApp()) {
-               fg = convert(theApp()->hexName(foregroundColor()).c_str(), 16);
-               bg = convert(theApp()->hexName(backgroundColor()).c_str(), 16);
+               fg = convert(theApp()->hexName(foregroundColor()), 16);
+               bg = convert(theApp()->hexName(backgroundColor()), 16);
        }
        if (font_scaling_factor_ != fs || fg_color_ != fg || bg_color_ != bg) {
                // Schedule refresh of all previews on zoom or color changes.
-- 
2.28.0.windows.1

From 2a3d2135102b374c27c68c77508027fdc623cbae Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.ska...@gmail.com>
Date: Thu, 10 Dec 2020 14:33:47 +0200
Subject: [PATCH 2/2] Use `to_string` instead of `boost::lexical_cast`

---
 src/support/convert.cpp | 51 +++++++++++++----------------------------
 1 file changed, 16 insertions(+), 35 deletions(-)

diff --git a/src/support/convert.cpp b/src/support/convert.cpp
index 5912ac54e6..7053be3fa7 100644
--- a/src/support/convert.cpp
+++ b/src/support/convert.cpp
@@ -14,8 +14,6 @@
 #include "support/convert.h"
 #include "support/docstring.h"
 
-#include <boost/lexical_cast.hpp>
-
 #include <string>
 #include <sstream>
 //needed for Mac OSX 10.5.2 Leopard
@@ -23,23 +21,6 @@
 
 using namespace std;
 
-namespace {
-
-// A version of lexical cast that does not throw. Useful for when we convert 
to string
-template<typename To, typename From>
-To lexical_cast(From const & value, To const & defaultResult = To())
-{
-       try {
-               return boost::lexical_cast<To>(value);
-       } catch(...) {
-               // Ignore all exceptions and use default.
-               return defaultResult;
-       }
-}
-
-} // namespace
-
-
 namespace lyx {
 
 template<>
@@ -59,49 +40,49 @@ string convert<string>(char c)
 template<>
 string convert<string>(short unsigned int sui)
 {
-       return lexical_cast<string>(sui);
+       return to_string(sui);
 }
 
 
 template<>
 string convert<string>(int i)
 {
-       return lexical_cast<string>(i);
+       return to_string(i);
 }
 
 
 template<>
 docstring convert<docstring>(int i)
 {
-       return from_ascii(lexical_cast<string>(i));
+       return from_ascii(to_string(i));
 }
 
 
 template<>
 string convert<string>(unsigned int ui)
 {
-       return lexical_cast<string>(ui);
+       return to_string(ui);
 }
 
 
 template<>
 docstring convert<docstring>(unsigned int ui)
 {
-       return from_ascii(lexical_cast<string>(ui));
+       return from_ascii(to_string(ui));
 }
 
 
 template<>
 string convert<string>(unsigned long ul)
 {
-       return lexical_cast<string>(ul);
+       return to_string(ul);
 }
 
 
 template<>
 docstring convert<docstring>(unsigned long ul)
 {
-       return from_ascii(lexical_cast<string>(ul));
+       return from_ascii(to_string(ul));
 }
 
 
@@ -109,28 +90,28 @@ docstring convert<docstring>(unsigned long ul)
 template<>
 string convert<string>(unsigned long long ull)
 {
-       return lexical_cast<string>(ull);
+       return to_string(ull);
 }
 
 
 template<>
 docstring convert<docstring>(unsigned long long ull)
 {
-       return from_ascii(lexical_cast<string>(ull));
+       return from_ascii(to_string(ull));
 }
 
 
 template<>
 string convert<string>(long long ll)
 {
-       return lexical_cast<string>(ll);
+       return to_string(ll);
 }
 
 
 template<>
 docstring convert<docstring>(long long ll)
 {
-       return from_ascii(lexical_cast<string>(ll));
+       return from_ascii(to_string(ll));
 }
 
 
@@ -154,21 +135,21 @@ long long convert<long long>(string const s)
 template<>
 string convert<string>(long l)
 {
-       return lexical_cast<string>(l);
+       return to_string(l);
 }
 
 
 template<>
 docstring convert<docstring>(long l)
 {
-       return from_ascii(lexical_cast<string>(l));
+       return from_ascii(to_string(l));
 }
 
 
 template<>
 string convert<string>(float f)
 {
-       std::ostringstream val;
+       ostringstream val;
        val << f;
        return val.str();
 }
@@ -177,7 +158,7 @@ string convert<string>(float f)
 template<>
 string convert<string>(double d)
 {
-       std::ostringstream val;
+       ostringstream val;
        val << d;
        return val.str();
 }
@@ -197,7 +178,7 @@ int convert<int>(string const s)
 }
 
 
-int convert(std::string const & s, int base)
+int convert(string const & s, int base)
 {
        return int(strtol(s.c_str(), nullptr, base));
 }
-- 
2.28.0.windows.1

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to