Skip to content

Commit

Permalink
Merge pull request #74565 from anothersimulacrum/mod_tracker_string_view
Browse files Browse the repository at this point in the history
Use std::string_view in mod_tracker
  • Loading branch information
dseguin authored Jun 17, 2024
2 parents b6d3ed3 + 179e09b commit d1a5a81
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static social_modifiers load_bionic_social_mods( const JsonObject &jo )
return ret;
}

void bionic_data::load( const JsonObject &jsobj, const std::string &src )
void bionic_data::load( const JsonObject &jsobj, const std::string_view src )
{

mandatory( jsobj, was_loaded, "id", id );
Expand Down
2 changes: 1 addition & 1 deletion src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ struct bionic_data {

itype_id itype() const;

void load( const JsonObject &obj, const std::string &src );
void load( const JsonObject &obj, std::string_view src );
void finalize();
static void load_bionic( const JsonObject &jo, const std::string &src );
static void finalize_bionic();
Expand Down
2 changes: 1 addition & 1 deletion src/effect_on_condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void effect_on_condition::load( const JsonObject &jo, const std::string_view )
}

effect_on_condition_id effect_on_conditions::load_inline_eoc( const JsonValue &jv,
const std::string &src )
std::string_view src )
{
if( jv.test_string() ) {
return effect_on_condition_id( jv.get_string() );
Expand Down
2 changes: 1 addition & 1 deletion src/effect_on_condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void load_new_character( Character &you );
/** Load any new eocs that don't exist in the save. */
void load_existing_character( Character &you );
/** Loads an inline eoc */
effect_on_condition_id load_inline_eoc( const JsonValue &jv, const std::string &src );
effect_on_condition_id load_inline_eoc( const JsonValue &jv, std::string_view src );
/** queue an eoc to happen in the future */
void queue_effect_on_condition( time_duration duration, effect_on_condition_id eoc,
Character &you, const std::unordered_map<std::string, std::string> &context );
Expand Down
5 changes: 1 addition & 4 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4471,10 +4471,7 @@ void Item_factory::load_basic_info( const JsonObject &jo, itype &def, const std:
check_and_create_magazine_pockets( def );
add_special_pockets( def );

if( !def.src.empty() && def.src.back().first != def.id ) {
def.src.clear();
}
def.src.emplace_back( def.id, mod_id( src ) );
mod_tracker::assign_src( def, src );

if( def.magazines.empty() ) {
migrate_mag_from_pockets( def );
Expand Down
4 changes: 2 additions & 2 deletions src/martialarts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void ma_requirements::load( const JsonObject &jo, const std::string_view )
optional( jo, was_loaded, "weapon_damage_requirements", min_damage, ma_weapon_damage_reader {} );
}

void ma_technique::load( const JsonObject &jo, const std::string &src )
void ma_technique::load( const JsonObject &jo, const std::string_view src )
{
mandatory( jo, was_loaded, "name", name );
optional( jo, was_loaded, "description", description, translation() );
Expand Down Expand Up @@ -405,7 +405,7 @@ class ma_buff_reader : public generic_typed_reader<ma_buff_reader>
}
};

void martialart::load( const JsonObject &jo, const std::string &src )
void martialart::load( const JsonObject &jo, const std::string_view src )
{
mandatory( jo, was_loaded, "name", name );
mandatory( jo, was_loaded, "description", description );
Expand Down
4 changes: 2 additions & 2 deletions src/martialarts.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class ma_technique
public:
ma_technique();

void load( const JsonObject &jo, const std::string &src );
void load( const JsonObject &jo, std::string_view src );
static void verify_ma_techniques();
void check() const;

Expand Down Expand Up @@ -326,7 +326,7 @@ class martialart
public:
martialart();

void load( const JsonObject &jo, const std::string &src );
void load( const JsonObject &jo, std::string_view src );

void remove_all_buffs( Character &u ) const;

Expand Down
2 changes: 1 addition & 1 deletion src/mod_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct has_src_member<T, std::void_t<decltype( std::declval<T &>().src.emplace_b

/** If those conditions are satisfied, keep track of where this item has been modified */
template<typename T, typename std::enable_if_t<has_src_member<T>::value > * = nullptr>
static void assign_src( T &def, const std::string &src ) {
static void assign_src( T &def, const std::string_view src ) {
// We need to make sure we're keeping where this entity has been loaded
// If the id this was last loaded with is not this one, discard the history and start again
if( !def.src.empty() && def.src.back().first != def.id ) {
Expand Down
2 changes: 1 addition & 1 deletion src/mutation.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ struct mutation_branch {
// For init.cpp: reset (clear) the mutation data
static void reset_all();
// For init.cpp: load mutation data from json
void load( const JsonObject &jo, const std::string &src );
void load( const JsonObject &jo, std::string_view src );
static void load_trait( const JsonObject &jo, const std::string &src );
// For init.cpp: check internal consistency (valid ids etc.) of all mutations
static void check_consistency();
Expand Down
2 changes: 1 addition & 1 deletion src/mutation_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void mutation_variant::deserialize( const JsonObject &jo )
load( jo );
}

void mutation_branch::load( const JsonObject &jo, const std::string &src )
void mutation_branch::load( const JsonObject &jo, const std::string_view src )
{
mandatory( jo, was_loaded, "name", raw_name );
mandatory( jo, was_loaded, "description", raw_desc );
Expand Down

0 comments on commit d1a5a81

Please sign in to comment.