widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #07930
[Merge] lp:~widelands-dev/widelands/bug-986611-cppcheck_performance into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-986611-cppcheck_performance into lp:widelands.
Commit message:
Fixed various performance issues that were flagged up by cppcheck:
- Prefer prefix ++ operator in src/graphic/richtext.cc
- Constructor initialization in src/graphic/text_parser.cc and src/io/filesystem/filesystem.cc
- Passing parameters per reference in src/io/fileread.h and src/io/filewrite
- Removed unnecessary calls to c_str() in src/io/filesystem/disk_filesystem.cc
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #986611 in widelands: "Issues reported by cppcheck"
https://bugs.launchpad.net/widelands/+bug/986611
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-986611-cppcheck_performance/+merge/301043
Fixed various performance issues that were flagged up by cppcheck:
- Prefer prefix ++ operator in
src/graphic/richtext.cc
- Constructor initialization in
src/graphic/text_parser.cc and src/io/filesystem/filesystem.cc
- Passing parameters per reference in
src/io/fileread.h and src/io/filewrite
- Removed unnecessary calls to c_str() in
src/io/filesystem/disk_filesystem.cc
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-986611-cppcheck_performance into lp:widelands.
=== modified file 'src/graphic/richtext.cc'
--- src/graphic/richtext.cc 2016-03-30 08:38:59 +0000
+++ src/graphic/richtext.cc 2016-07-25 08:48:28 +0000
@@ -486,7 +486,7 @@
text.advance_line();
}
- text.textblock++;
+ ++text.textblock;
}
if (!text.elements.empty())
=== modified file 'src/graphic/text_parser.cc'
--- src/graphic/text_parser.cc 2016-04-03 12:52:20 +0000
+++ src/graphic/text_parser.cc 2016-07-25 08:48:28 +0000
@@ -49,15 +49,15 @@
text_align_ = src.text_align_;
}
-TextBlock::TextBlock() {
- font_size_ = 10;
- font_color_ = RGBColor(255, 255, 0);
- font_weight_ = "normal";
- font_style_ = "normal";
- font_decoration_ = "none";
- font_face_ = (UI::g_fh1->fontset())->sans();
- line_spacing_ = 0;
-}
+TextBlock::TextBlock() :
+ font_size_(10),
+ font_color_(RGBColor(255, 255, 0)),
+ font_weight_("normal"),
+ font_style_("normal"),
+ font_decoration_("none"),
+ font_face_((UI::g_fh1->fontset())->sans()),
+ line_spacing_(0)
+{}
void TextParser::parse
(std::string & text,
=== modified file 'src/io/fileread.cc'
--- src/io/fileread.cc 2015-03-01 09:21:20 +0000
+++ src/io/fileread.cc 2016-07-25 08:48:28 +0000
@@ -57,7 +57,7 @@
return length_ <= filepos_;
}
-void FileRead::set_file_pos(Pos const pos) {
+void FileRead::set_file_pos(const Pos& pos) {
assert(data_);
if (pos >= length_)
throw FileBoundaryExceeded();
@@ -77,7 +77,7 @@
return read;
}
-char* FileRead::data(uint32_t const bytes, const Pos pos) {
+char* FileRead::data(uint32_t const bytes, const Pos& pos) {
assert(data_);
Pos i = pos;
if (pos.is_null()) {
@@ -89,7 +89,7 @@
return data_ + i;
}
-char* FileRead::c_string(Pos const pos) {
+char* FileRead::c_string(const Pos& pos) {
assert(data_);
Pos i = pos.is_null() ? filepos_ : pos;
=== modified file 'src/io/fileread.h'
--- src/io/fileread.h 2014-09-20 09:37:47 +0000
+++ src/io/fileread.h 2016-07-25 08:48:28 +0000
@@ -53,7 +53,7 @@
Pos operator++() {
return ++pos;
}
- Pos operator += (Pos const other) {
+ Pos operator += (const Pos& other) {
return pos += other.pos;
}
@@ -96,7 +96,7 @@
/// Set the file pointer to the given location.
/// \throws File_Boundary_Exceeded if the pointer is out of bound.
- void set_file_pos(Pos pos);
+ void set_file_pos(const Pos& pos);
/// Get the position that will be read from in the next read operation that
/// does not specify a position.
@@ -104,10 +104,10 @@
// Returns the next 'bytes' starting at 'pos' in the file. Can throw
// File_Boundary_Exceeded.
- char* data(uint32_t bytes, Pos pos = Pos::null());
+ char* data(uint32_t bytes, const Pos& pos = Pos::null());
// Returns the whole file as a string starting from 'pos'.
- char* c_string(Pos pos);
+ char* c_string(const Pos& pos);
// Returns the next line.
char* read_line();
=== modified file 'src/io/filesystem/disk_filesystem.cc'
--- src/io/filesystem/disk_filesystem.cc 2016-05-07 18:56:22 +0000
+++ src/io/filesystem/disk_filesystem.cc 2016-07-25 08:48:28 +0000
@@ -365,7 +365,7 @@
void * RealFSImpl::load(const std::string & fname, size_t & length) {
const std::string fullname = canonicalize_name(fname);
if (is_directory(fullname)) {
- throw FileError("RealFSImpl::load", fullname.c_str());
+ throw FileError("RealFSImpl::load", fullname);
}
FILE * file = nullptr;
@@ -374,7 +374,7 @@
try {
file = fopen(fullname.c_str(), "rb");
if (!file)
- throw FileError("RealFSImpl::load", fullname.c_str());
+ throw FileError("RealFSImpl::load", fullname);
// determine the size of the file (rather quirky, but it doesn't require
// potentially unportable functions)
=== modified file 'src/io/filesystem/filesystem.cc'
--- src/io/filesystem/filesystem.cc 2016-02-18 18:27:52 +0000
+++ src/io/filesystem/filesystem.cc 2016-07-25 08:48:28 +0000
@@ -61,9 +61,8 @@
#endif
FileSystem::FileSystem()
-{
- root_ = "";
-}
+ : root_("")
+{}
/**
=== modified file 'src/io/filewrite.cc'
--- src/io/filewrite.cc 2015-03-01 09:21:20 +0000
+++ src/io/filewrite.cc 2016-07-25 08:48:28 +0000
@@ -50,7 +50,7 @@
return filepos_;
}
-void FileWrite::set_pos(const Pos pos) {
+void FileWrite::set_pos(const Pos& pos) {
filepos_ = pos;
}
=== modified file 'src/io/filewrite.h'
--- src/io/filewrite.h 2014-09-19 12:54:54 +0000
+++ src/io/filewrite.h 2016-07-25 08:48:28 +0000
@@ -88,7 +88,7 @@
/// Set the file pointer to a new location. The position can be beyond the
/// current end of file.
- void set_pos(Pos pos);
+ void set_pos(const Pos& pos);
/// Write data at the given location.
void data(const void* src, size_t size, Pos pos);
=== modified file 'src/profile/profile.cc'
--- src/profile/profile.cc 2016-02-18 18:27:52 +0000
+++ src/profile/profile.cc 2016-07-25 08:48:28 +0000
@@ -634,7 +634,7 @@
*/
Section & Profile::get_safe_section(const std::string & name)
{
- if (Section * const s = get_section(name.c_str()))
+ if (Section * const s = get_section(name))
return *s;
else
throw wexception
=== modified file 'src/scripting/lua_game.cc'
--- src/scripting/lua_game.cc 2016-05-14 15:56:20 +0000
+++ src/scripting/lua_game.cc 2016-07-25 08:48:28 +0000
@@ -979,9 +979,9 @@
{nullptr, nullptr, nullptr},
};
-LuaObjective::LuaObjective(const Widelands::Objective& o) {
- name_ = o.name();
-}
+LuaObjective::LuaObjective(const Widelands::Objective& o) :
+ name_(o.name())
+{}
void LuaObjective::__persist(lua_State * L) {
PERS_STRING("name", name_);
References