Skip to content

Commit

Permalink
Merge pull request CleverRaven#38141 from ZhilkinSerg/sa-2020-02-18
Browse files Browse the repository at this point in the history
Code optimizations reported by static code analysis (2020-02-18)
  • Loading branch information
kevingranade authored Feb 20, 2020
2 parents f98c67d + 5d4be2c commit 142295b
Show file tree
Hide file tree
Showing 45 changed files with 16 additions and 83 deletions.
6 changes: 2 additions & 4 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1942,7 +1942,6 @@ static void fetch_activity( player &p, const tripoint &src_loc,
src_veh = &vp->vehicle();
src_part = vp->part_index();
}
std::string picked_up;
const units::volume volume_allowed = p.volume_capacity() - p.volume_carried();
const units::mass weight_allowed = p.weight_capacity() - p.weight_carried();
// TODO: vehicle_stack and map_stack into one loop.
Expand Down Expand Up @@ -1992,15 +1991,14 @@ static void fetch_activity( player &p, const tripoint &src_loc,
}
it.set_var( "activity_var", p.name );
p.i_add( it );
picked_up = it.tname();
items_there.erase( item_iter );
// If we didn't pick up a whole stack, put the remainder back where it came from.
if( leftovers.charges > 0 ) {
g->m.add_item_or_charges( src_loc, leftovers );
}
if( p.is_npc() && !picked_up.empty() ) {
if( p.is_npc() ) {
if( pickup_count == 1 ) {
add_msg( _( "%1$s picks up a %2$s." ), p.disp_name(), picked_up );
add_msg( _( "%1$s picks up a %2$s." ), p.disp_name(), it.tname() );
} else {
add_msg( _( "%s picks up several items." ), p.disp_name() );
}
Expand Down
1 change: 0 additions & 1 deletion src/advanced_inv_listitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class item_category;
class advanced_inv_listitem
{
public:
using itype_id = std::string;
/**
* Index of the item in the itemstack.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/ammo.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <string>
#include <utility>

class JsonObject;
#include "type_id.h"

using itype_id = std::string;
class JsonObject;

class ammunition_type
{
Expand Down
4 changes: 1 addition & 3 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,9 +1124,7 @@ void avatar_action::use_item( avatar &you, item_location &loc )
// If it's a gun, some gunmods can also be loaded
void avatar_action::unload( avatar &you )
{
item_location loc;

loc = g->inv_map_splice( [&you]( const item & it ) {
item_location loc = g->inv_map_splice( [&you]( const item & it ) {
return you.rate_action_unload( it ) == HINT_GOOD;
}, _( "Unload item" ), 1, _( "You have nothing to unload." ) );

Expand Down
2 changes: 0 additions & 2 deletions src/basecamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ struct expansion_data {
using npc_ptr = shared_ptr_fast<npc>;
using comp_list = std::vector<npc_ptr>;
using Group_tag = std::string;
using itype_id = std::string;

namespace catacurses
{
class window;
Expand Down
2 changes: 0 additions & 2 deletions src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class player;
class JsonObject;
class JsonIn;
class JsonOut;
using itype_id = std::string;

struct bionic_data {
bionic_data();

Expand Down
9 changes: 1 addition & 8 deletions src/cata_string_consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#define STRING_CONSTS_H

#include "type_id.h"
#include "player_activity.h"

#include "itype.h"

static const activity_id ACT_ADV_INVENTORY( "ACT_ADV_INVENTORY" );
static const activity_id ACT_AIM( "ACT_AIM" );
Expand Down Expand Up @@ -104,7 +103,6 @@ static const activity_id ACT_WAIT_WEATHER( "ACT_WAIT_WEATHER" );
static const activity_id ACT_WASH( "ACT_WASH" );
static const activity_id ACT_WEAR( "ACT_WEAR" );


static const bionic_id bio_adrenaline( "bio_adrenaline" );
static const bionic_id bio_ads( "bio_ads" );
static const bionic_id bio_advreactor( "bio_advreactor" );
Expand Down Expand Up @@ -920,7 +918,6 @@ static const mtype_id mon_zombie_technician( "mon_zombie_technician" );
static const mtype_id mon_zombie_tough( "mon_zombie_tough" );
static const mtype_id mon_zombie_waif( "mon_zombie_waif" );


static const std::string flag_ACID( "ACID" );
static const std::string flag_ACT_IN_FIRE( "ACT_IN_FIRE" );
static const std::string flag_ACT_ON_RANGED_HIT( "ACT_ON_RANGED_HIT" );
Expand Down Expand Up @@ -1274,7 +1271,6 @@ static const std::string flag_WIND_EXTINGUISH( "WIND_EXTINGUISH" );
static const std::string flag_WRITE_MESSAGE( "WRITE_MESSAGE" );
static const std::string flag_YOUNG( "YOUNG" );


static const skill_id skill_archery( "archery" );
static const skill_id skill_barter( "barter" );
static const skill_id skill_bashing( "bashing" );
Expand Down Expand Up @@ -1304,7 +1300,6 @@ static const skill_id skill_traps( "traps" );
static const skill_id skill_unarmed( "unarmed" );
static const skill_id skill_weapon( "weapon" );


static const quality_id qual_ANESTHESIA( "ANESTHESIA" );
static const quality_id qual_AXE( "AXE" );
static const quality_id qual_BUTCHER( "BUTCHER" );
Expand All @@ -1323,7 +1318,6 @@ static const quality_id qual_SCREW_FINE( "SCREW_FINE" );
static const quality_id qual_SELF_JACK( "SELF_JACK" );
static const quality_id qual_WELD( "WELD" );


static const zone_type_id zone_investigate_only( "NPC_INVESTIGATE_ONLY" );
static const zone_type_id zone_no_investigate( "NPC_NO_INVESTIGATE" );
static const zone_type_id zone_type_CHOP_TREES( "CHOP_TREES" );
Expand Down Expand Up @@ -1395,7 +1389,6 @@ static const matype_id style_tiger( "style_tiger" );
static const matype_id style_wingchun( "style_wingchun" );
static const matype_id style_zui_quan( "style_zui_quan" );

static const species_id ABERRATION( "ABERRATION" );
static const species_id species_BLOB( "BLOB" );
static const species_id FISH( "FISH" );
static const species_id FUNGUS( "FUNGUS" );
Expand Down
2 changes: 0 additions & 2 deletions src/cata_tiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class player;
class pixel_minimap;
class JsonObject;

using itype_id = std::string;

extern void set_displaybuffer_rendertarget();

/** Structures */
Expand Down
2 changes: 0 additions & 2 deletions src/cata_variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ enum body_part : int;
enum class mutagen_technique : int;
enum hp_part : int;

using itype_id = std::string;

// cata_variant is a variant-like type that stores a variety of different cata
// types. All types are stored by converting them to a string.

Expand Down
2 changes: 0 additions & 2 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
#include "vitamin.h"
#include "vpart_position.h"


// *INDENT-OFF*
Character::Character() :

Expand Down Expand Up @@ -3951,7 +3950,6 @@ void Character::update_needs( int rate_multiplier )
mod_sleep_deprivation( fatigue_roll * 5 );
}


if( npc_no_food && get_fatigue() > TIRED ) {
set_fatigue( TIRED );
set_sleep_deprivation( 0 );
Expand Down
2 changes: 0 additions & 2 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,6 @@ class Character : public Creature, public visitable<Character>

std::array<std::array<int, NUM_WATER_TOLERANCE>, num_bp> mut_drench;

void serialize_consumption_history( JsonOut jsout ) const;
void deserialize_consumption_history( JsonArray jarr );
public:
// recalculates enchantment cache by iterating through all held, worn, and wielded items
void recalculate_enchantment_cache();
Expand Down
2 changes: 0 additions & 2 deletions src/character_martial_arts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include "output.h"
#include "cata_string_consts.h"

using itype_id = std::string;

character_martial_arts::character_martial_arts()
{

Expand Down
2 changes: 0 additions & 2 deletions src/character_martial_arts.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class item;
class JsonOut;
class JsonIn;

using itype_id = std::string;

class character_martial_arts
{
private:
Expand Down
2 changes: 0 additions & 2 deletions src/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include "enum_conversions.h"
#include "type_id.h"

using itype_id = std::string;

// An event is something to be passed via the event_bus to subscribers
// interested in being notified about events.
//
Expand Down
2 changes: 1 addition & 1 deletion src/explosion.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <map>
#include <string>

using itype_id = std::string;
#include "type_id.h"

struct tripoint;
class JsonObject;
Expand Down
1 change: 0 additions & 1 deletion src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ enum target_mode : int;

struct special_game;

using itype_id = std::string;
class avatar;
class event_bus;
class kill_tracker;
Expand Down
2 changes: 0 additions & 2 deletions src/gamemode_defense.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include "type_id.h"

enum action_id : int;
using itype_id = std::string;

enum defense_style {
DEFENSE_CUSTOM = 0,
DEFENSE_EASY,
Expand Down
1 change: 0 additions & 1 deletion src/harvest.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "translations.h"
#include "type_id.h"

using itype_id = std::string;
class JsonObject;

// Could be reused for butchery
Expand Down
2 changes: 0 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9416,8 +9416,6 @@ bool item::has_infinite_charges() const
skill_id item::contextualize_skill( const skill_id &id ) const
{
if( id->is_contextual_skill() ) {


if( id == skill_weapon ) {
if( is_gun() ) {
return gun_skill();
Expand Down
3 changes: 0 additions & 3 deletions src/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ enum m_size : int;
enum class side : int;
class body_part_set;

using itype_id = std::string;
struct fire_data;
struct damage_instance;
struct damage_unit;
Expand Down Expand Up @@ -145,8 +144,6 @@ struct iteminfo {
lower_is_better = 1 << 3, ///< Lower values are better for this stat
no_name = 1 << 4, ///< Do not print the name
show_plus = 1 << 5, ///< Use a + sign for positive values


};

/**
Expand Down
1 change: 0 additions & 1 deletion src/item_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ struct tripoint;

static item_action nullaction;


static char key_bound_to( const input_context &ctxt, const item_action_id &act )
{
auto keys = ctxt.keys_bound_to( act );
Expand Down
1 change: 0 additions & 1 deletion src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,6 @@ void Item_factory::load_basic_info( const JsonObject &jo, itype &def, const std:
assign( jo, "insulation", def.insulation_factor );
assign( jo, "ascii_picture", def.ascii_picture );


if( jo.has_member( "thrown_damage" ) ) {
def.thrown_damage = load_damage_instance( jo.get_array( "thrown_damage" ) );
} else {
Expand Down
2 changes: 0 additions & 2 deletions src/itype.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ enum art_effect_active : int;
enum art_charge : int;
enum art_charge_req : int;
enum art_effect_passive : int;
using itype_id = std::string;

class gun_modifier_data
{
private:
Expand Down
4 changes: 2 additions & 2 deletions src/iuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string>
#include <vector>

#include "type_id.h"
#include "clone_ptr.h"
#include "units.h"

Expand All @@ -17,7 +18,6 @@ class monster;
template<typename T> class ret_val;
struct iteminfo;

using itype_id = std::string;
struct tripoint;

// iuse methods returning a bool indicating whether to consume a charge of the item being used.
Expand Down Expand Up @@ -297,7 +297,7 @@ class iuse_actor
/**
* Finalizes the actor. Must be called after all items are loaded.
*/
virtual void finalize( const itype_id &/*my_item_type*/ ) { }
virtual void finalize( const itype_id & ) { }
};

struct use_function {
Expand Down
1 change: 0 additions & 1 deletion src/iuse_actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ enum hp_part : int;
enum body_part : int;
class JsonObject;

using itype_id = std::string;
struct furn_t;
struct itype;
class item_location;
Expand Down
1 change: 0 additions & 1 deletion src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ struct trap;

enum direction : unsigned;
enum class special_item_type : int;
using itype_id = std::string;
template<typename T>
class visitable;
struct regional_settings;
Expand Down
2 changes: 0 additions & 2 deletions src/mapdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ struct tripoint;

using iexamine_function = void ( * )( player &, const tripoint & );

using itype_id = std::string;

struct map_bash_info {
int str_min; // min str(*) required to bash
int str_max; // max str required: bash succeeds if str >= random # between str_min & str_max
Expand Down
1 change: 0 additions & 1 deletion src/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
class material_type;

enum damage_type : int;
using itype_id = std::string;
class JsonObject;

using mat_burn_products = std::vector<std::pair<itype_id, float>>;
Expand Down
2 changes: 0 additions & 2 deletions src/mtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ using bodytype_id = std::string;
class JsonArray;
class JsonObject;

using itype_id = std::string;

// These are triggers which may affect the monster's anger or morale.
// They are handled in monster::check_triggers(), in monster.cpp
enum class mon_trigger {
Expand Down
1 change: 0 additions & 1 deletion src/mutation.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ struct dream;
class Trait_group;
class item;

using itype_id = std::string;
class JsonArray;

extern std::vector<dream> dreams;
Expand Down
1 change: 0 additions & 1 deletion src/npc_favor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "type_id.h"

using itype_id = std::string;
class JsonIn;
class JsonOut;

Expand Down
1 change: 0 additions & 1 deletion src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class JsonOut;
struct dealt_projectile_attack;
class dispersion_sources;

using itype_id = std::string;
using faction_id = string_id<faction>;
struct trap;
class profession;
Expand Down
2 changes: 1 addition & 1 deletion src/player_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "activity_handlers.h"
#include "activity_type.h"
#include "cata_string_consts.h"
#include "construction.h"
#include "map.h"
#include "game.h"
Expand All @@ -12,7 +13,6 @@
#include "avatar.h"
#include "itype.h"
#include "skill.h"
#include "cata_string_consts.h"

player_activity::player_activity() : type( activity_id::NULL_ID() ) { }

Expand Down
Loading

0 comments on commit 142295b

Please sign in to comment.