[LyX/master] Pass parameters as const references when possible

Jean-Marc Lasgouttes lasgouttes at lyx.org
Fri Oct 2 16:29:15 UTC 2020


commit dd65a97b55403d320100daf179685eae32f6aa32
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date:   Fri Oct 2 18:56:01 2020 +0200

    Pass parameters as const references when possible
    
    Fixes some cppcheck warnings.
---
 src/BiblioInfo.cpp        |    2 +-
 src/BiblioInfo.h          |    2 +-
 src/CiteEnginesList.cpp   |    2 +-
 src/CiteEnginesList.h     |    2 +-
 src/HunspellChecker.cpp   |    2 +-
 src/mathed/MathStream.cpp |    2 +-
 src/mathed/MathStream.h   |    8 +++++---
 src/tex2lyx/Parser.cpp    |    4 ++--
 src/tex2lyx/Parser.h      |    4 ++--
 src/tex2lyx/Preamble.cpp  |    4 ++--
 src/tex2lyx/Preamble.h    |    2 +-
 src/tex2lyx/tex2lyx.h     |    4 ++--
 src/tex2lyx/text.cpp      |    6 +++---
 src/xml.h                 |    4 ++--
 14 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
index 6d2af6c..15705ce 100644
--- a/src/BiblioInfo.cpp
+++ b/src/BiblioInfo.cpp
@@ -1045,7 +1045,7 @@ docstring const & BibTeXInfo::getInfo(BibTeXInfoList const & xrefs,
 }
 
 
-docstring const BibTeXInfo::getLabel(BibTeXInfoList const xrefs,
+docstring const BibTeXInfo::getLabel(BibTeXInfoList const & xrefs,
 	Buffer const & buf, docstring const & format,
 	CiteItem const & ci, bool next, bool second) const
 {
diff --git a/src/BiblioInfo.h b/src/BiblioInfo.h
index 5a6f0d5..a08204e 100644
--- a/src/BiblioInfo.h
+++ b/src/BiblioInfo.h
@@ -78,7 +78,7 @@ public:
 				  Buffer const & buf, CiteItem const & ci,
 				  docstring const & format = docstring()) const;
 	/// \return formatted BibTeX data for a citation label
-	docstring const getLabel(BibTeXInfoList const xrefs,
+	docstring const getLabel(BibTeXInfoList const & xrefs,
 		Buffer const & buf, docstring const & format,
 		CiteItem const & ci, bool next = false, bool second = false) const;
 	///
diff --git a/src/CiteEnginesList.cpp b/src/CiteEnginesList.cpp
index 53ec83e..7d7ad3f 100644
--- a/src/CiteEnginesList.cpp
+++ b/src/CiteEnginesList.cpp
@@ -110,7 +110,7 @@ bool LyXCiteEngine::isDefaultBiblio(string const & bf) const
 }
 
 
-bool LyXCiteEngine::required(const string p) const
+bool LyXCiteEngine::required(string const & p) const
 {
 	return find(package_list_.begin(), package_list_.end(), p) != package_list_.end();
 }
diff --git a/src/CiteEnginesList.h b/src/CiteEnginesList.h
index ad70332..6b795b4 100644
--- a/src/CiteEnginesList.h
+++ b/src/CiteEnginesList.h
@@ -80,7 +80,7 @@ public:
 	std::vector<std::string> const & getPackageList() const
 		{ return package_list_; }
 	///
-	bool required(std::string const p) const;
+	bool required(std::string const & p) const;
 private:
 	/// what appears in the ui
 	std::string name_;
diff --git a/src/HunspellChecker.cpp b/src/HunspellChecker.cpp
index c211b47..dcdc1bb 100644
--- a/src/HunspellChecker.cpp
+++ b/src/HunspellChecker.cpp
@@ -47,7 +47,7 @@ typedef map<std::string, PersonalWordList *> LangPersonalWordList;
 
 typedef vector<WordLangTuple> IgnoreList;
 
-docstring remap_result(docstring const s)
+docstring remap_result(docstring const & s)
 {
 	// substitute RIGHT SINGLE QUOTATION MARK
 	// by APOSTROPHE
diff --git a/src/mathed/MathStream.cpp b/src/mathed/MathStream.cpp
index f93ff72..7e6ea6b 100644
--- a/src/mathed/MathStream.cpp
+++ b/src/mathed/MathStream.cpp
@@ -269,7 +269,7 @@ WriteStream & operator<<(WriteStream & ws, unsigned int i)
 //////////////////////////////////////////////////////////////////////
 
 
-MathStream::MathStream(odocstream & os, std::string xmlns, bool xmlMode)
+MathStream::MathStream(odocstream & os, std::string const & xmlns, bool xmlMode)
 	: os_(os), tab_(0), line_(0), in_text_(false), xmlns_(xmlns), xml_mode_(xmlMode)
 {}
 
diff --git a/src/mathed/MathStream.h b/src/mathed/MathStream.h
index 9344dac..fb229e6 100644
--- a/src/mathed/MathStream.h
+++ b/src/mathed/MathStream.h
@@ -327,7 +327,7 @@ public:
 class CTag {
 public:
 	///
-	CTag(char const * const tag, std::string attr = "")
+	CTag(char const * const tag, std::string const & attr = "")
             : tag_(tag), attr_(attr) {}
 	///
 	char const * const tag_;
@@ -346,7 +346,7 @@ class MathExportException : public std::exception {};
 class MathStream {
 public:
 	/// Builds a stream proxy for os; the MathML namespace is given by xmlns (supposed to be already defined elsewhere in the document).
-	explicit MathStream(odocstream & os, std::string xmlns="", bool xmlMode=false);
+	explicit MathStream(odocstream & os, std::string const & xmlns="", bool xmlMode=false);
 	///
 	void cr();
 	///
@@ -370,7 +370,9 @@ public:
 	///
 	bool xmlMode() const { return xml_mode_; }
 	/// Returns the tag name prefixed by the name space if needed.
-	std::string namespacedTag(std::string tag) const { return ((xmlns().empty()) ? "" : xmlns() + ":") + tag; }
+	std::string namespacedTag(std::string const & tag) const {
+		return (xmlns().empty() ? "" : xmlns() + ":") + tag;
+	}
 private:
 	///
 	void setTextMode(bool t) { in_text_ = t; }
diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp
index fa40533..cc8dd5a 100644
--- a/src/tex2lyx/Parser.cpp
+++ b/src/tex2lyx/Parser.cpp
@@ -453,7 +453,7 @@ bool Parser::good()
 }
 
 
-bool Parser::hasOpt(string const l)
+bool Parser::hasOpt(string const & l)
 {
 	// An optional argument can occur in any of the following forms:
 	// - \foo[bar]
@@ -577,7 +577,7 @@ string Parser::getFullParentheseArg()
 }
 
 
-bool Parser::hasListPreamble(string const itemcmd)
+bool Parser::hasListPreamble(string const & itemcmd)
 {
 	// remember current position
 	unsigned int oldpos = pos_;
diff --git a/src/tex2lyx/Parser.h b/src/tex2lyx/Parser.h
index d611513..e9afbd1 100644
--- a/src/tex2lyx/Parser.h
+++ b/src/tex2lyx/Parser.h
@@ -214,7 +214,7 @@ public:
 	void dump() const;
 
 	/// Does an optional argument follow after the current token?
-	bool hasOpt(std::string const l = "[");
+	bool hasOpt(std::string const & l = "[");
 	///
 	typedef std::pair<bool, std::string> Arg;
 	/*!
@@ -260,7 +260,7 @@ public:
 	 */
 	std::string getFullParentheseArg();
 	/// Check if we have a list preamble
-	bool hasListPreamble(std::string const itemcmd);
+	bool hasListPreamble(std::string const & itemcmd);
 	/*!
 	 * \returns the contents of the environment \p name.
 	 * <tt>\begin{name}</tt> must be parsed already, <tt>\end{name}</tt>
diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index f28df64..cf01fdd 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -295,7 +295,7 @@ vector<string> split_options(string const & input)
  * \p options and return the value.
  * The found option is also removed from \p options.
  */
-string process_keyval_opt(vector<string> & options, string name)
+string process_keyval_opt(vector<string> & options, string const & name)
 {
 	for (size_t i = 0; i < options.size(); ++i) {
 		vector<string> option;
@@ -469,7 +469,7 @@ void Preamble::add_package(string const & name, vector<string> & options)
 	}
 }
 
-void Preamble::setTextClass(string const tclass, TeX2LyXDocClass & tc)
+void Preamble::setTextClass(string const & tclass, TeX2LyXDocClass & tc)
 {
 	h_textclass = tclass;
 	tc.setName(h_textclass);
diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h
index 92d3694..5287f53 100644
--- a/src/tex2lyx/Preamble.h
+++ b/src/tex2lyx/Preamble.h
@@ -96,7 +96,7 @@ public:
 	/// Get author named \p name (must be registered first)
 	Author const & getAuthor(std::string const & name) const;
 	/// Set text class
-	void setTextClass(std::string const tclass, TeX2LyXDocClass & tc);
+	void setTextClass(std::string const & tclass, TeX2LyXDocClass & tc);
 	/// Get number of arguments of special table column type \c or -1
 	/// if no column type \p c exists
 	int getSpecialTableColumnArguments(char c) const;
diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h
index 883eb75..2b1eaf9 100644
--- a/src/tex2lyx/tex2lyx.h
+++ b/src/tex2lyx/tex2lyx.h
@@ -48,7 +48,7 @@ extern std::string rgbcolor2code(std::string const & name);
 std::string translate_len(std::string const &);
 
 void parse_text(Parser & p, std::ostream & os, unsigned flags, bool outer,
-		Context & context, std::string const rdelim = std::string());
+		Context & context, std::string const & rdelim = std::string());
 void check_comment_bib(std::ostream & os, Context & context);
 
 void fix_child_filename(std::string & name);
@@ -68,7 +68,7 @@ std::string find_file(std::string const & name, std::string const & path,
 void parse_text_in_inset(Parser & p, std::ostream & os, unsigned flags,
                          bool outer, Context const & context,
                          InsetLayout const * layout = 0,
-                         std::string const rdelim = std::string());
+                         std::string const & rdelim = std::string());
 
 /// Guess document language from \p p if CJK is used.
 /// \p lang is used for all non-CJK contents.
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index 6744d78..208e149 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -55,7 +55,7 @@ void output_arguments(ostream &, Parser &, bool, bool, string, Context &,
 
 void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
 		Context const & context, InsetLayout const * layout,
-		string const rdelim)
+		string const & rdelim)
 {
 	bool const forcePlainLayout =
 		layout ? layout->forcePlainLayout() : false;
@@ -86,7 +86,7 @@ namespace {
 
 void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
 		Context const & context, string const & name,
-		string const rdelim = string())
+		string const & rdelim = string())
 {
 	InsetLayout const * layout = 0;
 	DocumentClass::InsetLayouts::const_iterator it =
@@ -2867,7 +2867,7 @@ void fix_child_filename(string & name)
 
 
 void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
-		Context & context, string const rdelim)
+		Context & context, string const & rdelim)
 {
 	Layout const * newlayout = 0;
 	InsetLayout const * newinsetlayout = 0;
diff --git a/src/xml.h b/src/xml.h
index 857867b..4fa19aa 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -219,9 +219,9 @@ struct StartTag
 struct EndTag
 {
 	///
-	explicit EndTag(std::string tag) : tag_(from_ascii(tag)) {}
+	explicit EndTag(std::string const & tag) : tag_(from_ascii(tag)) {}
 	///
-	explicit EndTag(docstring tag) : tag_(tag) {}
+	explicit EndTag(docstring const & tag) : tag_(tag) {}
 	///
 	virtual ~EndTag() {}
 	/// </tag_>


More information about the lyx-cvs mailing list