Skip to content

Commit

Permalink
cppcheck performance fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbi committed Jun 3, 2024
1 parent 090a7c4 commit 079d904
Show file tree
Hide file tree
Showing 28 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion src/addon/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Addon::get_filename() const
return get_id() + ".zip";
}

std::string
const std::string&
Addon::get_install_filename() const
{
return m_install_filename;
Expand Down
16 changes: 8 additions & 8 deletions src/addon/addon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ class Addon final
Addon();

public:
std::string get_id() const { return m_id; }
const std::string& get_id() const { return m_id; }
int get_version() const { return m_version; }
int get_format() const { return m_format; }

Type get_type() const { return m_type; }
std::string get_title() const { return m_title; }
std::string get_author() const { return m_author; }
std::string get_license() const { return m_license; }
const std::string& get_title() const { return m_title; }
const std::string& get_author() const { return m_author; }
const std::string& get_license() const { return m_license; }

std::string get_description() const { return m_description; }
std::string get_url() const { return m_url; }
std::string get_md5() const { return m_md5; }
const std::string& get_description() const { return m_description; }
const std::string& get_url() const { return m_url; }
const std::string& get_md5() const { return m_md5; }
const std::vector<std::string>& get_screenshots() const { return m_screenshots; }
const std::vector<std::string>& get_dependencies() const { return m_dependencies; }

std::string get_filename() const;
std::string get_install_filename() const;
const std::string& get_install_filename() const;

bool is_installed() const;
bool is_enabled() const;
Expand Down
2 changes: 1 addition & 1 deletion src/audio/sound_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class SoundManager final : public Currenton<SoundManager>
bool is_sound_enabled() const { return m_sound_enabled; }

bool is_audio_enabled() const { return m_device != nullptr && m_context != nullptr; }
std::string get_current_music() const { return m_current_music; }
const std::string& get_current_music() const { return m_current_music; }
void update();

/** Tell soundmanager to call update() for stream_sound_source. */
Expand Down
4 changes: 2 additions & 2 deletions src/collision/collision_movement_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ class CollisionGroundMovementManager final
void register_movement(CollisionObject& moving_object, const Vector& movement);
void register_movement(TileMap& moving_tilemap, const Vector& movement);

const std::unordered_map<CollisionObject*, Vector> get_objects_map() const
const std::unordered_map<CollisionObject*, Vector>& get_objects_map() const
{
return m_moving_objects;
}

const std::unordered_map<TileMap*, Vector> get_tilemaps_map() const
const std::unordered_map<TileMap*, Vector>& get_tilemaps_map() const
{
return m_moving_tilemaps;
}
Expand Down
2 changes: 1 addition & 1 deletion src/editor/editor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Editor final : public Screen,
int get_tileselect_select_mode() const;
int get_tileselect_move_mode() const;

std::string get_levelfile() const { return m_levelfile; }
const std::string& get_levelfile() const { return m_levelfile; }

void set_level(const std::string& levelfile_) {
m_levelfile = levelfile_;
Expand Down
2 changes: 1 addition & 1 deletion src/editor/object_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ObjectGroup final

void add_icon(const std::string& object, const std::string& icon_path);

std::string get_name() const { return m_name; }
const std::string& get_name() const { return m_name; }

bool is_worldmap() const { return m_for_worldmap; }

Expand Down
2 changes: 1 addition & 1 deletion src/editor/object_icon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ObjectIcon
virtual void draw(DrawingContext& context, const Vector& pos);
virtual void draw(DrawingContext& context, const Vector& pos, int pixels_shown);

std::string get_object_class() const { return m_object_class; }
const std::string& get_object_class() const { return m_object_class; }

ObjectIcon(const ObjectIcon&) = default;
ObjectIcon& operator=(const ObjectIcon&) = default;
Expand Down
2 changes: 1 addition & 1 deletion src/editor/tilebox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class EditorTilebox final : public Widget
void set_input_type(InputType input_type) { m_input_type = input_type; }

TileSelection* get_tiles() const { return m_tiles.get(); }
std::string get_object() const { return m_object; }
const std::string& get_object() const { return m_object; }
void set_object(const std::string& object) { m_object = object; }

float get_tiles_height() const;
Expand Down
2 changes: 1 addition & 1 deletion src/interface/control_textbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ ControlTextbox::revert_value()
recenter_offset();
}

std::string
const std::string&
ControlTextbox::get_string() const
{
return m_internal_string_backup;
Expand Down
2 changes: 1 addition & 1 deletion src/interface/control_textbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ControlTextbox : public InterfaceControl
void bind_string(std::string* value) { m_string = value; }

/** Returns the full string held in m_charlist */
std::string get_string() const;
const std::string& get_string() const;

/** Gets at which (absolute) index, in the text, corresponds an on-screen point */
int get_text_position(const Vector& pos) const;
Expand Down
2 changes: 1 addition & 1 deletion src/interface/label.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class InterfaceLabel : public Widget
Rectf get_rect() const { return m_rect; }

void set_label(const std::string& label) { m_label = label; }
std::string get_label() const { return m_label; }
const std::string& get_label() const { return m_label; }

bool fits(const std::string& text) const;
std::string get_truncated_text() const;
Expand Down
2 changes: 1 addition & 1 deletion src/object/background.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Background final : public GameObject,

void draw_image(DrawingContext& context, const Vector& pos);

std::string get_image() const { return m_imagefile; }
const std::string& get_image() const { return m_imagefile; }
float get_speed() const { return m_parallax_speed.x; }
int get_layer() const { return m_layer; }

Expand Down
2 changes: 1 addition & 1 deletion src/object/music_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ MusicObject::set_music(const std::string& music)
m_music = music;
}

std::string
const std::string&
MusicObject::get_music() const
{
return m_music;
Expand Down
2 changes: 1 addition & 1 deletion src/object/music_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MusicObject : public GameObject
MusicType get_music_type() const;

void set_music(const std::string& music);
std::string get_music() const;
const std::string& get_music() const;

private:
MusicType m_currentmusic;
Expand Down
4 changes: 2 additions & 2 deletions src/object/particle_zone.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ParticleZone final :
void set_particle_name(std::string& particle_name) {m_particle_name = particle_name;}

/** Returns the name of the particle object for this area */
std::string get_particle_name() const {return m_particle_name;}
const std::string& get_particle_name() const { return m_particle_name; }

/** Move the area around. Multiple calls stack (e. g. calling one before
* the other finished will play both movements simultaneously)
Expand Down Expand Up @@ -116,7 +116,7 @@ class ParticleZone final :

Rectf get_rect() const {return m_rect;}
ParticleZoneType get_type() const {return m_type;}
std::string get_particle_name() const {return m_particle_name;}
const std::string& get_particle_name() const {return m_particle_name;}
};

ZoneDetails get_details() {
Expand Down
2 changes: 1 addition & 1 deletion src/squirrel/squirrel_environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ SquirrelEnvironment::unexpose(const std::string& name)
SQInteger oldtop = sq_gettop(m_vm.get_vm());
sq_pushobject(m_vm.get_vm(), m_table);
try {
unexpose_object(m_vm.get_vm(), -1, name.c_str());
unexpose_object(m_vm.get_vm(), -1, name);
} catch(std::exception& e) {
log_warning << "Couldn't unregister object: " << e.what() << std::endl;
}
Expand Down
2 changes: 1 addition & 1 deletion src/supertux/game_session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class GameSession final : public Screen,
* resources for the current level/world
*/
std::string get_working_directory() const;
std::string get_level_file() const { return m_levelfile; }
const std::string& get_level_file() const { return m_levelfile; }
bool has_active_sequence() const;
int restart_level(bool after_death = false, bool preserve_music = false);

Expand Down
4 changes: 2 additions & 2 deletions src/supertux/level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Level final

std::vector<Player*> get_players() const;

std::string get_tileset() const { return m_tileset; }
const std::string& get_tileset() const { return m_tileset; }

int get_total_coins() const;
int get_total_badguys() const;
Expand All @@ -67,7 +67,7 @@ class Level final

bool is_worldmap() const { return m_is_worldmap; }

std::string get_license() const { return m_license; }
const std::string& get_license() const { return m_license; }

private:
void initialize();
Expand Down
4 changes: 2 additions & 2 deletions src/supertux/profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class Profile final
std::string get_basedir() const;

int get_id() const { return m_id; }
std::string get_name() const { return m_name; }
std::string get_last_world() const { return m_last_world; }
const std::string& get_name() const { return m_name; }
const std::string& get_last_world() const { return m_last_world; }

void set_name(const std::string& name) { m_name = name; }
void set_last_world(const std::string& world) { m_last_world = world; }
Expand Down
10 changes: 5 additions & 5 deletions src/supertux/world.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ class World final

public:
std::string get_basename() const;
std::string get_basedir() const { return m_basedir; }
std::string get_title() const { return m_title; }
std::string get_description() const { return m_description; }
const std::string& get_basedir() const { return m_basedir; }
const std::string& get_title() const { return m_title; }
const std::string& get_description() const { return m_description; }

bool hide_from_contribs() const { return m_hide_from_contribs && !g_config->developer_mode; }

bool is_levelset() const { return m_is_levelset; }
bool is_worldmap() const { return !m_is_levelset; }

std::string get_contrib_type() const { return m_contrib_type; }
std::string get_title_level() const { return m_title_level; }
const std::string& get_contrib_type() const { return m_contrib_type; }
const std::string& get_title_level() const { return m_title_level; }

std::string get_worldmap_filename() const;

Expand Down
2 changes: 1 addition & 1 deletion src/util/reader_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ReaderDocument::get_root() const
return ReaderObject(*this, m_sx);
}

std::string
const std::string&
ReaderDocument::get_filename() const
{
return m_filename;
Expand Down
2 changes: 1 addition & 1 deletion src/util/reader_document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ReaderDocument final
ReaderObject get_root() const;

/** Returns the filename of the document */
std::string get_filename() const;
const std::string& get_filename() const;

/** Returns the directory of the document */
std::string get_directory() const;
Expand Down
2 changes: 1 addition & 1 deletion src/video/surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Surface final
int get_width() const;
int get_height() const;
Flip get_flip() const { return m_flip; }
std::string get_filename() const { return m_source_filename; }
const std::string& get_filename() const { return m_source_filename; }

private:
const TexturePtr m_diffuse_texture;
Expand Down
8 changes: 4 additions & 4 deletions src/worldmap/level_tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class LevelTile final : public WorldMapObject

void update_sprite_action();

std::string get_title() const { return m_title; }
std::string get_level_filename() const { return m_level_filename; }
std::string get_basedir() const { return m_basedir; }
const std::string& get_title() const { return m_title; }
const std::string& get_level_filename() const { return m_level_filename; }
const std::string& get_basedir() const { return m_basedir; }
Color get_title_color() const { return m_title_color; }
std::string get_extro_script() const { return m_extro_script; }
const std::string& get_extro_script() const { return m_extro_script; }
float get_target_time() const { return m_target_time; }
bool is_auto_play() const { return m_auto_play; }

Expand Down
2 changes: 1 addition & 1 deletion src/worldmap/spawn_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SpawnPoint final
public:
SpawnPoint(const ReaderMapping& mapping);

std::string get_name() const { return m_name; }
const std::string& get_name() const { return m_name; }
Vector get_pos() const { return m_pos; }
Direction get_auto_dir() const { return m_auto_dir; }

Expand Down
4 changes: 2 additions & 2 deletions src/worldmap/special_tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class SpecialTile final : public WorldMapObject

virtual ObjectSettings get_settings() override;

std::string get_map_message() const { return m_map_message; }
const std::string& get_map_message() const { return m_map_message; }
bool is_passive_message() const { return m_passive_message; }
std::string get_script() const { return m_script; }
const std::string& get_script() const { return m_script; }

bool get_apply_action_north() const { return m_apply_action_north; }
bool get_apply_action_east() const { return m_apply_action_east; }
Expand Down
2 changes: 1 addition & 1 deletion src/worldmap/worldmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ WorldMap::set_sector(const std::string& name, const std::string& spawnpoint,
m_sector->move_to_spawnpoint(spawnpoint);
}

std::string
const std::string&
WorldMap::get_filename() const
{
return m_map_filename;
Expand Down
2 changes: 1 addition & 1 deletion src/worldmap/worldmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class WorldMap final : public Currenton<WorldMap>
void set_sector(const std::string& name, const std::string& spawnpoint = "",
bool perform_full_setup = true);

std::string get_filename() const;
const std::string& get_filename() const;

private:
void on_escape_press();
Expand Down

0 comments on commit 079d904

Please sign in to comment.