New Patches
Yuriy Skalko
yuriy.skalko at gmail.com
Thu Nov 19 12:09:08 UTC 2020
New patches for LyX.
Yuriy
-------------- next part --------------
From c083a56f9ddb2e4d5d2cc4bb0586fbb83ae598e9 Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Thu, 19 Nov 2020 13:24:04 +0200
Subject: [PATCH 1/2] Simplify constructors
---
src/Dimension.h | 28 +++++++++++-----------------
src/graphics/PreviewLoader.cpp | 2 +-
src/mathed/MathData.cpp | 3 +--
src/mathed/MathData.h | 15 ++++++++-------
src/mathed/MathStream.cpp | 7 ++-----
src/mathed/MathStream.h | 34 +++++++++++++++++-----------------
6 files changed, 40 insertions(+), 49 deletions(-)
diff --git a/src/Dimension.h b/src/Dimension.h
index 0f7fdabcef..802b3bb555 100644
--- a/src/Dimension.h
+++ b/src/Dimension.h
@@ -18,16 +18,12 @@ namespace lyx {
class Dimension {
public:
/// constructor
- Dimension() : wid(0), asc(0), des(0) {}
+ Dimension() = default;
/// initialize data
Dimension(int w, int a, int d) : wid(w), asc(a), des(d) {}
+ ///
+ Dimension & operator=(Dimension const & dim) = default;
- Dimension & operator=(Dimension const & dim) {
- wid = dim.wid;
- asc = dim.asc;
- des = dim.des;
- return *this;
- }
/// glue horizontally
void operator+=(Dimension const & dim);
/// set to empty box
@@ -59,35 +55,33 @@ public:
///
/// makes the code neither faster nor clearer
/// width
- int wid;
+ int wid = 0;
/// ascent
- int asc;
+ int asc = 0;
/// descent
- int des;
+ int des = 0;
};
inline
bool operator==(Dimension const & a, Dimension const & b)
{
- return a.wid == b.wid && a.asc == b.asc && a.des == b.des ;
+ return a.wid == b.wid && a.asc == b.asc && a.des == b.des;
}
inline
bool operator!=(Dimension const & a, Dimension const & b)
{
- return a.wid != b.wid || a.asc != b.asc || a.des != b.des ;
+ return !(a == b);
}
class Point {
public:
- Point()
- : x_(0), y_(0)
- {}
-
+ Point() = default;
Point(int x, int y);
- int x_, y_;
+ int x_ = 0;
+ int y_ = 0;
};
} // namespace lyx
diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp
index f9c0ba9b4d..a7e37f3ee5 100644
--- a/src/graphics/PreviewLoader.cpp
+++ b/src/graphics/PreviewLoader.cpp
@@ -631,7 +631,7 @@ void PreviewLoader::Impl::startLoading(bool wait)
// Set \jobname of previews to the document name (see bug 9627)
of << "\\def\\jobname{"
- << from_utf8(changeExtension(buffer_.latexName(true), ""))
+ << from_utf8(changeExtension(buffer_.latexName(), ""))
<< "}\n";
LYXERR(Debug::LATEX, "Format = " << buffer_.params().getDefaultOutputFormat());
diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp
index 39d5f80184..53724303a9 100644
--- a/src/mathed/MathData.cpp
+++ b/src/mathed/MathData.cpp
@@ -47,8 +47,7 @@ namespace lyx {
MathData::MathData(Buffer * buf, const_iterator from, const_iterator to)
- : base_type(from, to), minasc_(0), mindes_(0), slevel_(0),
- sshift_(0), buffer_(buf)
+ : base_type(from, to), buffer_(buf)
{}
diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h
index 34749802fe..81d6cfcd78 100644
--- a/src/mathed/MathData.h
+++ b/src/mathed/MathData.h
@@ -68,8 +68,9 @@ public:
public:
///
- explicit MathData(Buffer * buf = 0) : minasc_(0), mindes_(0), slevel_(0),
- sshift_(0), buffer_(buf) {}
+ MathData() = default;
+ ///
+ explicit MathData(Buffer * buf) : buffer_(buf) {}
///
MathData(Buffer * buf, const_iterator from, const_iterator to);
///
@@ -186,11 +187,11 @@ public:
protected:
/// cached values for super/subscript placement
- mutable int minasc_;
- mutable int mindes_;
- mutable int slevel_;
- mutable int sshift_;
- Buffer * buffer_;
+ mutable int minasc_ = 0;
+ mutable int mindes_ = 0;
+ mutable int slevel_ = 0;
+ mutable int sshift_ = 0;
+ Buffer * buffer_ = nullptr;
private:
/// is this an exact match at this position?
diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp
index 2f25ce6c95..588e219157 100644
--- a/src/mathed/MathStream.cpp
+++ b/src/mathed/MathStream.cpp
@@ -126,11 +126,8 @@ WriteStream & operator<<(WriteStream & ws, docstring const & s)
WriteStream::WriteStream(otexrowstream & os, bool fragile, bool latex,
OutputType output, Encoding const * encoding)
- : os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
- output_(output), pendingspace_(false), pendingbrace_(false),
- textmode_(false), locked_(false), ascii_(false), canbreakline_(true),
- mathsout_(false), ulemcmd_(NONE), line_(0), encoding_(encoding),
- row_entry_(TexRow::row_none), mathclass_(false)
+ : os_(os), fragile_(fragile), latex_(latex),
+ output_(output), encoding_(encoding)
{}
diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h
index db4a499a0f..94e810de83 100644
--- a/src/mathed/MathStream.h
+++ b/src/mathed/MathStream.h
@@ -49,7 +49,7 @@ public:
///
explicit WriteStream(otexrowstream & os, bool fragile = false,
bool latex = false, OutputType output = wsDefault,
- Encoding const * encoding = 0);
+ Encoding const * encoding = nullptr);
///
~WriteStream();
///
@@ -116,37 +116,37 @@ private:
///
otexrowstream & os_;
/// do we have to write \\protect sometimes
- bool fragile_;
+ bool fragile_ = false;
/// are we at the beginning of an MathData?
- bool firstitem_;
+ bool firstitem_ = false;
/// are we writing to .tex?
- int latex_;
+ int latex_ = false;
/// output type (default, source preview, instant preview)?
- OutputType output_;
+ OutputType output_ = wsDefault;
/// do we have a space pending?
- bool pendingspace_;
+ bool pendingspace_ = false;
/// do we have a brace pending?
- bool pendingbrace_;
+ bool pendingbrace_ = false;
/// are we in text mode when producing latex code?
- bool textmode_;
+ bool textmode_ = false;
/// are we allowed to switch mode when producing latex code?
- bool locked_;
+ bool locked_ = false;
/// should we use only ascii chars when producing latex code?
- bool ascii_;
+ bool ascii_ = false;
/// are we allowed to output an immediately following newline?
- bool canbreakline_;
+ bool canbreakline_ = true;
/// should we take care for striking out display math?
- bool mathsout_;
+ bool mathsout_ = false;
/// what ulem command are we inside (none, underline, strikeout)?
- UlemCmdType ulemcmd_;
+ UlemCmdType ulemcmd_ = NONE;
///
- int line_;
+ int line_ = 0;
///
- Encoding const * encoding_;
+ Encoding const * encoding_ = nullptr;
/// Row entry we are in
- TexRow::RowEntry row_entry_;
+ TexRow::RowEntry row_entry_ = TexRow::row_none;
/// whether we are in a MathClass inset
- bool mathclass_;
+ bool mathclass_ = false;
};
///
--
2.28.0.windows.1
-------------- next part --------------
From 4cedba36240daa7bbb5b89506332ee0ce0335cb6 Mon Sep 17 00:00:00 2001
From: Yuriy Skalko <yuriy.skalko at gmail.com>
Date: Thu, 19 Nov 2020 14:03:26 +0200
Subject: [PATCH 2/2] Use C++11 standard algorithm
---
src/frontends/qt/GuiCommandBuffer.cpp | 28 +++++++-----------
src/frontends/qt/qt_helpers.cpp | 1 -
src/insets/ExternalSupport.cpp | 1 -
src/insets/InsetInclude.cpp | 1 -
src/insets/InsetLabel.cpp | 1 -
src/mathed/MathData.cpp | 1 -
src/output_latex.cpp | 1 -
src/support/lyxalgo.h | 41 ---------------------------
8 files changed, 10 insertions(+), 65 deletions(-)
diff --git a/src/frontends/qt/GuiCommandBuffer.cpp b/src/frontends/qt/GuiCommandBuffer.cpp
index 06ca59ca06..e670e3a41d 100644
--- a/src/frontends/qt/GuiCommandBuffer.cpp
+++ b/src/frontends/qt/GuiCommandBuffer.cpp
@@ -26,7 +26,6 @@
#include "FuncRequest.h"
#include "Session.h"
-#include "support/lyxalgo.h"
#include "support/lstrings.h"
#include <QHBoxLayout>
@@ -38,6 +37,8 @@
#include <QToolTip>
#include <QVBoxLayout>
+#include <algorithm>
+
using namespace std;
using namespace lyx::support;
@@ -86,7 +87,8 @@ GuiCommandBuffer::GuiCommandBuffer(GuiView * view)
: view_(view)
{
transform(lyxaction.func_begin(), lyxaction.func_end(),
- back_inserter(commands_), firster());
+ back_inserter(commands_),
+ [](auto const & p) { return p.first; });
QPixmap qpup = getPixmap("images/", "up", "svgz,png");
QPixmap qpdown = getPixmap("images/", "down", "svgz,png");
@@ -263,18 +265,6 @@ void GuiCommandBuffer::hideParent()
}
-namespace {
-
-class prefix_p {
-public:
- string p;
- prefix_p(string const & s) : p(s) {}
- bool operator()(string const & s) const { return prefixIs(s, p); }
-};
-
-} // namespace
-
-
string const GuiCommandBuffer::historyUp()
{
if (history_pos_ == history_.begin())
@@ -300,8 +290,9 @@ GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
{
vector<string> comp;
- lyx::copy_if(commands_.begin(), commands_.end(),
- back_inserter(comp), prefix_p(prefix));
+ std::copy_if(commands_.begin(), commands_.end(),
+ back_inserter(comp),
+ [&](string const & s) { return prefixIs(s, prefix); });
if (comp.empty()) {
new_prefix = prefix;
@@ -320,8 +311,9 @@ GuiCommandBuffer::completions(string const & prefix, string & new_prefix)
test += tmp[test.length()];
while (test.length() < tmp.length()) {
vector<string> vtmp;
- lyx::copy_if(comp.begin(), comp.end(),
- back_inserter(vtmp), prefix_p(test));
+ std::copy_if(comp.begin(), comp.end(),
+ back_inserter(vtmp),
+ [&](string const & s) { return prefixIs(s, test); });
if (vtmp.size() != comp.size()) {
test.erase(test.length() - 1);
break;
diff --git a/src/frontends/qt/qt_helpers.cpp b/src/frontends/qt/qt_helpers.cpp
index dcac28f734..108d613042 100644
--- a/src/frontends/qt/qt_helpers.cpp
+++ b/src/frontends/qt/qt_helpers.cpp
@@ -33,7 +33,6 @@
#include "support/gettext.h"
#include "support/Length.h"
#include "support/lstrings.h"
-#include "support/lyxalgo.h"
#include "support/os.h"
#include "support/Package.h"
#include "support/PathChanger.h"
diff --git a/src/insets/ExternalSupport.cpp b/src/insets/ExternalSupport.cpp
index 3d7936abc7..24a228cb55 100644
--- a/src/insets/ExternalSupport.cpp
+++ b/src/insets/ExternalSupport.cpp
@@ -30,7 +30,6 @@
#include "support/filetools.h"
#include "support/gettext.h"
#include "support/lstrings.h"
-#include "support/lyxalgo.h"
#include "support/os.h"
#include "support/Package.h"
diff --git a/src/insets/InsetInclude.cpp b/src/insets/InsetInclude.cpp
index 623152863c..0de8aa3d42 100644
--- a/src/insets/InsetInclude.cpp
+++ b/src/insets/InsetInclude.cpp
@@ -61,7 +61,6 @@
#include "support/gettext.h"
#include "support/lassert.h"
#include "support/lstrings.h" // contains
-#include "support/lyxalgo.h"
#include "support/mutex.h"
#include "support/ExceptionMessage.h"
diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp
index 427df8a767..ce4494759c 100644
--- a/src/insets/InsetLabel.cpp
+++ b/src/insets/InsetLabel.cpp
@@ -41,7 +41,6 @@
#include "support/convert.h"
#include "support/gettext.h"
#include "support/lstrings.h"
-#include "support/lyxalgo.h"
using namespace std;
using namespace lyx::support;
diff --git a/src/mathed/MathData.cpp b/src/mathed/MathData.cpp
index 53724303a9..50fc100e64 100644
--- a/src/mathed/MathData.cpp
+++ b/src/mathed/MathData.cpp
@@ -37,7 +37,6 @@
#include "support/docstream.h"
#include "support/gettext.h"
#include "support/lassert.h"
-#include "support/lyxalgo.h"
#include <cstdlib>
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index 12bbdeade7..71ebf0301f 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -35,7 +35,6 @@
#include "support/convert.h"
#include "support/debug.h"
#include "support/lstrings.h"
-#include "support/lyxalgo.h"
#include "support/textutils.h"
#include "support/gettext.h"
diff --git a/src/support/lyxalgo.h b/src/support/lyxalgo.h
index 8bf8bbc541..8777a03e41 100644
--- a/src/support/lyxalgo.h
+++ b/src/support/lyxalgo.h
@@ -14,11 +14,6 @@
#ifndef LYX_ALGO_H
#define LYX_ALGO_H
-#include <utility>
-#include <iterator>
-#include <algorithm>
-
-
namespace lyx {
@@ -48,42 +43,6 @@ bool sorted(For first, For last, Cmp cmp)
}
-struct firster {
- template <class P1, class P2>
- P1 operator()(std::pair<P1, P2> const & p) {
- return p.first;
- }
-};
-
-
-/**
- * copy elements in the given range to the output iterator
- * if the predicate evaluates as true
- */
-template <class InputIter, class OutputIter, class Func>
-OutputIter copy_if(InputIter first, InputIter last,
- OutputIter result, Func func)
-{
- for (; first != last; ++first) {
- if (func(*first)) {
- *result++ = *first;
- }
- }
- return result;
-}
-
-
-/// Remove all duplicate entries in c.
-template<class C>
-void eliminate_duplicates(C & c)
-{
- // It is a requirement that the container is sorted for
- // std::unique to work properly.
- std::sort(c.begin(), c.end());
- c.erase(std::unique(c.begin(), c.end()), c.end());
-}
-
-
} // namespace lyx
#endif // LYX_ALGO_H
--
2.28.0.windows.1
More information about the lyx-devel
mailing list