diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73b21385bce..f4d8462324f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -446,6 +446,7 @@ jobs: mv panda3d-1.10.16/thirdparty thirdparty rmdir panda3d-1.10.16 (cd thirdparty/darwin-libs-a && rm -rf rocket) + (cd thirdparty/darwin-libs-a && rm -rf openexr) - name: Set up XCode (macOS) if: runner.os == 'macOS' diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a3362badb0..8eb8af51098 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ if(APPLE) # Needed for enable_language(OBJCXX) cmake_minimum_required(VERSION 3.16) - set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Minimum macOS version to target") + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "Minimum macOS version to target") set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") if(CMAKE_VERSION VERSION_LESS "3.19" AND NOT CMAKE_OSX_SYSROOT) diff --git a/direct/src/dcparser/dcArrayParameter.cxx b/direct/src/dcparser/dcArrayParameter.cxx index c2c73635a2d..e2ea12689e8 100644 --- a/direct/src/dcparser/dcArrayParameter.cxx +++ b/direct/src/dcparser/dcArrayParameter.cxx @@ -203,20 +203,19 @@ validate_num_nested_fields(int num_nested_fields) const { * identifier. */ void DCArrayParameter:: -output_instance(std::ostream &out, bool brief, const string &prename, - const string &name, const string &postname) const { +output_instance(std::ostream &out, bool brief, std::string_view prename, + std::string_view name, std::string_view postname) const { if (get_typedef() != nullptr) { output_typedef_name(out, brief, prename, name, postname); } else { std::ostringstream strm; - strm << "["; + strm << postname << "["; _array_size_range.output(strm); strm << "]"; - _element_type->output_instance(out, brief, prename, name, - postname + strm.str()); + _element_type->output_instance(out, brief, prename, name, strm.str()); } } @@ -234,7 +233,7 @@ generate_hash(HashGenerator &hashgen) const { * Packs the indicated numeric or string value into the stream. */ void DCArrayParameter:: -pack_string(DCPackData &pack_data, const string &value, +pack_string(DCPackData &pack_data, std::string_view value, bool &pack_error, bool &range_error) const { // We can only pack a string if the array element type is char or int8. DCSimpleParameter *simple_type = _element_type->as_simple_parameter(); diff --git a/direct/src/dcparser/dcArrayParameter.h b/direct/src/dcparser/dcArrayParameter.h index d81707a9e60..2087d691145 100644 --- a/direct/src/dcparser/dcArrayParameter.h +++ b/direct/src/dcparser/dcArrayParameter.h @@ -46,10 +46,10 @@ class EXPCL_DIRECT_DCPARSER DCArrayParameter : public DCParameter { virtual DCPackerInterface *get_nested_field(int n) const; virtual bool validate_num_nested_fields(int num_nested_fields) const; - virtual void output_instance(std::ostream &out, bool brief, const std::string &prename, - const std::string &name, const std::string &postname) const; + virtual void output_instance(std::ostream &out, bool brief, std::string_view prename, + std::string_view name, std::string_view postname) const; virtual void generate_hash(HashGenerator &hashgen) const; - virtual void pack_string(DCPackData &pack_data, const std::string &value, + virtual void pack_string(DCPackData &pack_data, std::string_view value, bool &pack_error, bool &range_error) const; virtual void pack_blob(DCPackData &pack_data, const vector_uchar &value, bool &pack_error, bool &range_error) const; diff --git a/direct/src/dcparser/dcAtomicField.cxx b/direct/src/dcparser/dcAtomicField.cxx index eb5607e55c6..1b12938cbaf 100644 --- a/direct/src/dcparser/dcAtomicField.cxx +++ b/direct/src/dcparser/dcAtomicField.cxx @@ -25,9 +25,9 @@ using std::string; * */ DCAtomicField:: -DCAtomicField(const string &name, DCClass *dclass, +DCAtomicField(string name, DCClass *dclass, bool bogus_field) : - DCField(name, dclass) + DCField(std::move(name), dclass) { _bogus_field = bogus_field; } diff --git a/direct/src/dcparser/dcAtomicField.h b/direct/src/dcparser/dcAtomicField.h index 418b1b768fe..774cb5c3e1c 100644 --- a/direct/src/dcparser/dcAtomicField.h +++ b/direct/src/dcparser/dcAtomicField.h @@ -29,7 +29,7 @@ */ class EXPCL_DIRECT_DCPARSER DCAtomicField : public DCField { public: - DCAtomicField(const std::string &name, DCClass *dclass, bool bogus_field); + DCAtomicField(std::string name, DCClass *dclass, bool bogus_field); virtual ~DCAtomicField(); PUBLISHED: diff --git a/direct/src/dcparser/dcClass.cxx b/direct/src/dcparser/dcClass.cxx index 9c4028691d2..e8d2d30c5d6 100644 --- a/direct/src/dcparser/dcClass.cxx +++ b/direct/src/dcparser/dcClass.cxx @@ -64,13 +64,13 @@ class SortFieldsByIndex { * */ DCClass:: -DCClass(DCFile *dc_file, const string &name, bool is_struct, bool bogus_class) : +DCClass(DCFile *dc_file, string name, bool is_struct, bool bogus_class) : #ifdef WITHIN_PANDA _class_update_pcollector(_update_pcollector, name), _class_generate_pcollector(_generate_pcollector, name), #endif _dc_file(dc_file), - _name(name), + _name(std::move(name)), _is_struct(is_struct), _bogus_class(bogus_class) { @@ -181,7 +181,7 @@ get_field(int n) const { * class. Returns NULL if there is no such field defined. */ DCField *DCClass:: -get_field_by_name(const string &name) const { +get_field_by_name(std::string_view name) const { FieldsByName::const_iterator ni; ni = _fields_by_name.find(name); if (ni != _fields_by_name.end()) { @@ -402,8 +402,8 @@ write(std::ostream &out, bool brief, int indent_level) const { * stream. */ void DCClass:: -output_instance(std::ostream &out, bool brief, const string &prename, - const string &name, const string &postname) const { +output_instance(std::ostream &out, bool brief, std::string_view prename, + std::string_view name, std::string_view postname) const { if (_is_struct) { out << "struct"; } else { @@ -552,7 +552,7 @@ rebuild_inherited_fields() { * adding a new definition below. */ void DCClass:: -shadow_inherited_field(const string &name) { +shadow_inherited_field(std::string_view name) { Fields::iterator fi; for (fi = _inherited_fields.begin(); fi != _inherited_fields.end(); ++fi) { DCField *field = (*fi); diff --git a/direct/src/dcparser/dcClass.h b/direct/src/dcparser/dcClass.h index d5bbe4f97c2..7909a0c9235 100644 --- a/direct/src/dcparser/dcClass.h +++ b/direct/src/dcparser/dcClass.h @@ -44,7 +44,7 @@ class DCParameter; */ class EXPCL_DIRECT_DCPARSER DCClass : public DCDeclaration { public: - DCClass(DCFile *dc_file, const std::string &name, + DCClass(DCFile *dc_file, std::string name, bool is_struct, bool bogus_class); ~DCClass(); @@ -66,7 +66,7 @@ class EXPCL_DIRECT_DCPARSER DCClass : public DCDeclaration { int get_num_fields() const; DCField *get_field(int n) const; - DCField *get_field_by_name(const std::string &name) const; + DCField *get_field_by_name(std::string_view name) const; DCField *get_field_by_index(int index_number) const; int get_num_inherited_fields() const; @@ -94,9 +94,9 @@ class EXPCL_DIRECT_DCPARSER DCClass : public DCDeclaration { EXTENSION(void receive_update_all_required(PyObject *distobj, DatagramIterator &di) const); EXTENSION(void receive_update_other(PyObject *distobj, DatagramIterator &di) const); - EXTENSION(void direct_update(PyObject *distobj, const std::string &field_name, + EXTENSION(void direct_update(PyObject *distobj, std::string_view field_name, const vector_uchar &value_blob)); - EXTENSION(void direct_update(PyObject *distobj, const std::string &field_name, + EXTENSION(void direct_update(PyObject *distobj, std::string_view field_name, const Datagram &datagram)); EXTENSION(bool pack_required_field(Datagram &datagram, PyObject *distobj, const DCField *field) const); @@ -105,13 +105,13 @@ class EXPCL_DIRECT_DCPARSER DCClass : public DCDeclaration { - EXTENSION(Datagram client_format_update(const std::string &field_name, + EXTENSION(Datagram client_format_update(std::string_view field_name, DOID_TYPE do_id, PyObject *args) const); - EXTENSION(Datagram ai_format_update(const std::string &field_name, + EXTENSION(Datagram ai_format_update(std::string_view field_name, DOID_TYPE do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, PyObject *args) const); - EXTENSION(Datagram ai_format_update_msg_type(const std::string &field_name, + EXTENSION(Datagram ai_format_update_msg_type(std::string_view field_name, DOID_TYPE do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, @@ -131,8 +131,8 @@ class EXPCL_DIRECT_DCPARSER DCClass : public DCDeclaration { public: virtual void output(std::ostream &out, bool brief) const; virtual void write(std::ostream &out, bool brief, int indent_level) const; - void output_instance(std::ostream &out, bool brief, const std::string &prename, - const std::string &name, const std::string &postname) const; + void output_instance(std::ostream &out, bool brief, std::string_view prename, + std::string_view name, std::string_view postname) const; void generate_hash(HashGenerator &hashgen) const; void clear_inherited_fields(); void rebuild_inherited_fields(); @@ -142,7 +142,7 @@ class EXPCL_DIRECT_DCPARSER DCClass : public DCDeclaration { void set_number(int number); private: - void shadow_inherited_field(const std::string &name); + void shadow_inherited_field(std::string_view name); #ifdef WITHIN_PANDA mutable PStatCollector _class_update_pcollector; @@ -166,7 +166,7 @@ class EXPCL_DIRECT_DCPARSER DCClass : public DCDeclaration { typedef pvector Fields; Fields _fields, _inherited_fields; - typedef pmap FieldsByName; + typedef pmap> FieldsByName; FieldsByName _fields_by_name; typedef pmap FieldsByIndex; diff --git a/direct/src/dcparser/dcClassParameter.cxx b/direct/src/dcparser/dcClassParameter.cxx index a3bc68d5eb1..4d9c0a3ed71 100644 --- a/direct/src/dcparser/dcClassParameter.cxx +++ b/direct/src/dcparser/dcClassParameter.cxx @@ -128,8 +128,8 @@ get_nested_field(int n) const { * identifier. */ void DCClassParameter:: -output_instance(std::ostream &out, bool brief, const std::string &prename, - const std::string &name, const std::string &postname) const { +output_instance(std::ostream &out, bool brief, std::string_view prename, + std::string_view name, std::string_view postname) const { if (get_typedef() != nullptr) { output_typedef_name(out, brief, prename, name, postname); diff --git a/direct/src/dcparser/dcClassParameter.h b/direct/src/dcparser/dcClassParameter.h index 1ec4b856a22..60437ed8186 100644 --- a/direct/src/dcparser/dcClassParameter.h +++ b/direct/src/dcparser/dcClassParameter.h @@ -39,8 +39,8 @@ class EXPCL_DIRECT_DCPARSER DCClassParameter : public DCParameter { public: virtual DCPackerInterface *get_nested_field(int n) const final; - virtual void output_instance(std::ostream &out, bool brief, const std::string &prename, - const std::string &name, const std::string &postname) const; + virtual void output_instance(std::ostream &out, bool brief, std::string_view prename, + std::string_view name, std::string_view postname) const; virtual void generate_hash(HashGenerator &hashgen) const; protected: diff --git a/direct/src/dcparser/dcClass_ext.cxx b/direct/src/dcparser/dcClass_ext.cxx index c6b6b4465ce..473639d1b4c 100644 --- a/direct/src/dcparser/dcClass_ext.cxx +++ b/direct/src/dcparser/dcClass_ext.cxx @@ -229,7 +229,7 @@ receive_update_other(PyObject *distobj, DatagramIterator &di) const { * Processes an update for a named field from a packed value blob. */ void Extension:: -direct_update(PyObject *distobj, const std::string &field_name, +direct_update(PyObject *distobj, std::string_view field_name, const vector_uchar &value_blob) { DCField *field = _this->get_field_by_name(field_name); nassertv_always(field != nullptr); @@ -245,7 +245,7 @@ direct_update(PyObject *distobj, const std::string &field_name, * Processes an update for a named field from a packed datagram. */ void Extension:: -direct_update(PyObject *distobj, const std::string &field_name, +direct_update(PyObject *distobj, std::string_view field_name, const Datagram &datagram) { DCField *field = _this->get_field_by_name(field_name); nassertv_always(field != nullptr); @@ -432,7 +432,7 @@ pack_required_field(DCPacker &packer, PyObject *distobj, * the indicated distributed object from the client. */ Datagram Extension:: -client_format_update(const std::string &field_name, DOID_TYPE do_id, +client_format_update(std::string_view field_name, DOID_TYPE do_id, PyObject *args) const { DCField *field = _this->get_field_by_name(field_name); if (field == nullptr) { @@ -451,7 +451,7 @@ client_format_update(const std::string &field_name, DOID_TYPE do_id, * the indicated distributed object from the AI. */ Datagram Extension:: -ai_format_update(const std::string &field_name, DOID_TYPE do_id, +ai_format_update(std::string_view field_name, DOID_TYPE do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, PyObject *args) const { DCField *field = _this->get_field_by_name(field_name); if (field == nullptr) { @@ -471,7 +471,7 @@ ai_format_update(const std::string &field_name, DOID_TYPE do_id, * AI. */ Datagram Extension:: -ai_format_update_msg_type(const std::string &field_name, DOID_TYPE do_id, +ai_format_update_msg_type(std::string_view field_name, DOID_TYPE do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, int msg_type, PyObject *args) const { DCField *field = _this->get_field_by_name(field_name); diff --git a/direct/src/dcparser/dcClass_ext.h b/direct/src/dcparser/dcClass_ext.h index 9f81b7b7222..13e3fc2e749 100644 --- a/direct/src/dcparser/dcClass_ext.h +++ b/direct/src/dcparser/dcClass_ext.h @@ -42,9 +42,9 @@ class Extension : public ExtensionBase { void receive_update_all_required(PyObject *distobj, DatagramIterator &di) const; void receive_update_other(PyObject *distobj, DatagramIterator &di) const; - void direct_update(PyObject *distobj, const std::string &field_name, + void direct_update(PyObject *distobj, std::string_view field_name, const vector_uchar &value_blob); - void direct_update(PyObject *distobj, const std::string &field_name, + void direct_update(PyObject *distobj, std::string_view field_name, const Datagram &datagram); bool pack_required_field(Datagram &datagram, PyObject *distobj, const DCField *field) const; @@ -53,11 +53,11 @@ class Extension : public ExtensionBase { - Datagram client_format_update(const std::string &field_name, + Datagram client_format_update(std::string_view field_name, DOID_TYPE do_id, PyObject *args) const; - Datagram ai_format_update(const std::string &field_name, DOID_TYPE do_id, + Datagram ai_format_update(std::string_view field_name, DOID_TYPE do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, PyObject *args) const; - Datagram ai_format_update_msg_type(const std::string &field_name, DOID_TYPE do_id, + Datagram ai_format_update_msg_type(std::string_view field_name, DOID_TYPE do_id, CHANNEL_TYPE to_id, CHANNEL_TYPE from_id, int msg_type, PyObject *args) const; Datagram ai_format_generate(PyObject *distobj, DOID_TYPE do_id, ZONEID_TYPE parent_id, ZONEID_TYPE zone_id, diff --git a/direct/src/dcparser/dcField.cxx b/direct/src/dcparser/dcField.cxx index 9265160b280..17b4c3c70a5 100644 --- a/direct/src/dcparser/dcField.cxx +++ b/direct/src/dcparser/dcField.cxx @@ -48,12 +48,12 @@ DCField() : * */ DCField:: -DCField(const std::string &name, DCClass *dclass) : - DCPackerInterface(name), +DCField(std::string name, DCClass *dclass) : + DCPackerInterface(std::move(name)), _dclass(dclass) #ifdef WITHIN_PANDA , - _field_update_pcollector(dclass->_class_update_pcollector, name) + _field_update_pcollector(dclass->_class_update_pcollector, get_name()) #endif { _number = -1; @@ -169,10 +169,10 @@ format_data(const vector_uchar &packed_data, bool show_field_names) { * the corresponding packed data. Returns empty string if there is an error. */ vector_uchar DCField:: -parse_string(const std::string &formatted_string) { +parse_string(std::string formatted_string) { DCPacker packer; packer.begin_pack(this); - if (!packer.parse_and_pack(formatted_string)) { + if (!packer.parse_and_pack(std::move(formatted_string))) { // Parse error. return vector_uchar(); } @@ -241,8 +241,8 @@ pack_default_value(DCPackData &pack_data, bool &) const { * Sets the name of this field. */ void DCField:: -set_name(const std::string &name) { - DCPackerInterface::set_name(name); +set_name(std::string name) { + DCPackerInterface::set_name(std::move(name)); if (_dclass != nullptr) { _dclass->_dc_file->mark_inherited_fields_stale(); } diff --git a/direct/src/dcparser/dcField.h b/direct/src/dcparser/dcField.h index 1c6fa8ce5e6..efe9db0d8ab 100644 --- a/direct/src/dcparser/dcField.h +++ b/direct/src/dcparser/dcField.h @@ -38,7 +38,7 @@ class HashGenerator; class EXPCL_DIRECT_DCPARSER DCField : public DCPackerInterface, public DCKeywordList { public: DCField(); - DCField(const std::string &name, DCClass *dclass); + DCField(std::string name, DCClass *dclass); virtual ~DCField(); PUBLISHED: @@ -55,7 +55,7 @@ class EXPCL_DIRECT_DCPARSER DCField : public DCPackerInterface, public DCKeyword virtual const DCParameter *as_parameter() const; std::string format_data(const vector_uchar &packed_data, bool show_field_names = true); - vector_uchar parse_string(const std::string &formatted_string); + vector_uchar parse_string(std::string formatted_string); bool validate_ranges(const vector_uchar &packed_data) const; @@ -94,7 +94,7 @@ class EXPCL_DIRECT_DCPARSER DCField : public DCPackerInterface, public DCKeyword virtual void write(std::ostream &out, bool brief, int indent_level) const=0; virtual void generate_hash(HashGenerator &hashgen) const; virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const; - virtual void set_name(const std::string &name); + virtual void set_name(std::string name); INLINE void set_number(int number); INLINE void set_class(DCClass *dclass); diff --git a/direct/src/dcparser/dcFile.cxx b/direct/src/dcparser/dcFile.cxx index be69b4b18c9..df0eb3ab90d 100644 --- a/direct/src/dcparser/dcFile.cxx +++ b/direct/src/dcparser/dcFile.cxx @@ -166,9 +166,9 @@ read(Filename filename) { * (in which case the file might have been partially read). */ bool DCFile:: -read(std::istream &in, const string &filename) { +read(std::istream &in, string filename) { cerr << "DCFile::read of " << filename << "\n"; - dc_init_parser(in, filename, *this); + dc_init_parser(in, std::move(filename), *this); dcyyparse(); dc_cleanup_parser(); @@ -259,7 +259,7 @@ get_class(int n) const { * class. */ DCClass *DCFile:: -get_class_by_name(const string &name) const { +get_class_by_name(std::string_view name) const { ThingsByName::const_iterator ni; ni = _things_by_name.find(name); if (ni != _things_by_name.end()) { @@ -274,7 +274,7 @@ get_class_by_name(const string &name) const { * switch. */ DCSwitch *DCFile:: -get_switch_by_name(const string &name) const { +get_switch_by_name(std::string_view name) const { ThingsByName::const_iterator ni; ni = _things_by_name.find(name); if (ni != _things_by_name.end()) { @@ -364,7 +364,7 @@ get_typedef(int n) const { * such typedef name. */ DCTypedef *DCFile:: -get_typedef_by_name(const string &name) const { +get_typedef_by_name(std::string_view name) const { TypedefsByName::const_iterator ni; ni = _typedefs_by_name.find(name); if (ni != _typedefs_by_name.end()) { @@ -395,7 +395,7 @@ get_keyword(int n) const { * such keyword name. */ const DCKeyword *DCFile:: -get_keyword_by_name(const string &name) const { +get_keyword_by_name(std::string_view name) const { const DCKeyword *keyword = _keywords.get_keyword_by_name(name); if (keyword == nullptr) { keyword = _default_keywords.get_keyword_by_name(name); @@ -506,10 +506,10 @@ add_switch(DCSwitch *dswitch) { * class interfaces named within the .dc file. */ void DCFile:: -add_import_module(const string &import_module) { +add_import_module(string import_module) { Import import; - import._module = import_module; - _imports.push_back(import); + import._module = std::move(import_module); + _imports.push_back(std::move(import)); } /** @@ -519,9 +519,9 @@ add_import_module(const string &import_module) { * "import module_name". */ void DCFile:: -add_import_symbol(const string &import_symbol) { +add_import_symbol(string import_symbol) { nassertv(!_imports.empty()); - _imports.back()._symbols.push_back(import_symbol); + _imports.back()._symbols.push_back(std::move(import_symbol)); } /** @@ -561,8 +561,8 @@ add_typedef(DCTypedef *dtypedef) { * to add a particular keyword more than once. */ bool DCFile:: -add_keyword(const string &name) { - DCKeyword *keyword = new DCKeyword(name); +add_keyword(std::string name) { + DCKeyword *keyword = new DCKeyword(std::move(name)); bool added = _keywords.add_keyword(keyword); if (added) { diff --git a/direct/src/dcparser/dcFile.h b/direct/src/dcparser/dcFile.h index 37ebbe91811..7d79a04b109 100644 --- a/direct/src/dcparser/dcFile.h +++ b/direct/src/dcparser/dcFile.h @@ -41,15 +41,15 @@ class EXPCL_DIRECT_DCPARSER DCFile { #endif bool read(Filename filename); - bool read(std::istream &in, const std::string &filename = std::string()); + bool read(std::istream &in, std::string filename = std::string()); bool write(Filename filename, bool brief) const; bool write(std::ostream &out, bool brief) const; int get_num_classes() const; DCClass *get_class(int n) const; - DCClass *get_class_by_name(const std::string &name) const; - DCSwitch *get_switch_by_name(const std::string &name) const; + DCClass *get_class_by_name(std::string_view name) const; + DCSwitch *get_switch_by_name(std::string_view name) const; DCField *get_field_by_index(int index_number) const; @@ -62,11 +62,11 @@ class EXPCL_DIRECT_DCPARSER DCFile { int get_num_typedefs() const; DCTypedef *get_typedef(int n) const; - DCTypedef *get_typedef_by_name(const std::string &name) const; + DCTypedef *get_typedef_by_name(std::string_view name) const; int get_num_keywords() const; const DCKeyword *get_keyword(int n) const; - const DCKeyword *get_keyword_by_name(const std::string &name) const; + const DCKeyword *get_keyword_by_name(std::string_view name) const; unsigned long get_hash() const; @@ -74,10 +74,10 @@ class EXPCL_DIRECT_DCPARSER DCFile { void generate_hash(HashGenerator &hashgen) const; bool add_class(DCClass *dclass); bool add_switch(DCSwitch *dswitch); - void add_import_module(const std::string &import_module); - void add_import_symbol(const std::string &import_symbol); + void add_import_module(std::string import_module); + void add_import_symbol(std::string import_symbol); bool add_typedef(DCTypedef *dtypedef); - bool add_keyword(const std::string &name); + bool add_keyword(std::string name); void add_thing_to_delete(DCDeclaration *decl); void set_new_index_number(DCField *field); @@ -91,7 +91,7 @@ class EXPCL_DIRECT_DCPARSER DCFile { typedef pvector Classes; Classes _classes; - typedef pmap ThingsByName; + typedef pmap> ThingsByName; ThingsByName _things_by_name; typedef pvector ImportSymbols; @@ -107,7 +107,7 @@ class EXPCL_DIRECT_DCPARSER DCFile { typedef pvector Typedefs; Typedefs _typedefs; - typedef pmap TypedefsByName; + typedef pmap> TypedefsByName; TypedefsByName _typedefs_by_name; DCKeywordList _keywords; diff --git a/direct/src/dcparser/dcKeyword.cxx b/direct/src/dcparser/dcKeyword.cxx index ef9c497b7d0..876ca552fc2 100644 --- a/direct/src/dcparser/dcKeyword.cxx +++ b/direct/src/dcparser/dcKeyword.cxx @@ -19,8 +19,8 @@ * */ DCKeyword:: -DCKeyword(const std::string &name, int historical_flag) : - _name(name), +DCKeyword(std::string name, int historical_flag) : + _name(std::move(name)), _historical_flag(historical_flag) { } diff --git a/direct/src/dcparser/dcKeyword.h b/direct/src/dcparser/dcKeyword.h index 7447b6ed783..733fbb0601b 100644 --- a/direct/src/dcparser/dcKeyword.h +++ b/direct/src/dcparser/dcKeyword.h @@ -27,7 +27,7 @@ class HashGenerator; */ class EXPCL_DIRECT_DCPARSER DCKeyword : public DCDeclaration { public: - DCKeyword(const std::string &name, int historical_flag = ~0); + DCKeyword(std::string name, int historical_flag = ~0); virtual ~DCKeyword(); PUBLISHED: diff --git a/direct/src/dcparser/dcKeywordList.cxx b/direct/src/dcparser/dcKeywordList.cxx index cdfdd4f7f5a..bbaeda74fab 100644 --- a/direct/src/dcparser/dcKeywordList.cxx +++ b/direct/src/dcparser/dcKeywordList.cxx @@ -57,7 +57,7 @@ DCKeywordList:: * Returns true if this list includes the indicated keyword, false otherwise. */ bool DCKeywordList:: -has_keyword(const std::string &name) const { +has_keyword(std::string_view name) const { return (_keywords_by_name.find(name) != _keywords_by_name.end()); } @@ -92,7 +92,7 @@ get_keyword(int n) const { * is no keyword in the list with that name. */ const DCKeyword *DCKeywordList:: -get_keyword_by_name(const std::string &name) const { +get_keyword_by_name(std::string_view name) const { KeywordsByName::const_iterator ni; ni = _keywords_by_name.find(name); if (ni != _keywords_by_name.end()) { diff --git a/direct/src/dcparser/dcKeywordList.h b/direct/src/dcparser/dcKeywordList.h index ac0ed574fe4..1a2d6e1a62b 100644 --- a/direct/src/dcparser/dcKeywordList.h +++ b/direct/src/dcparser/dcKeywordList.h @@ -31,11 +31,11 @@ class EXPCL_DIRECT_DCPARSER DCKeywordList { ~DCKeywordList(); PUBLISHED: - bool has_keyword(const std::string &name) const; + bool has_keyword(std::string_view name) const; bool has_keyword(const DCKeyword *keyword) const; int get_num_keywords() const; const DCKeyword *get_keyword(int n) const; - const DCKeyword *get_keyword_by_name(const std::string &name) const; + const DCKeyword *get_keyword_by_name(std::string_view name) const; bool compare_keywords(const DCKeywordList &other) const; @@ -52,7 +52,7 @@ class EXPCL_DIRECT_DCPARSER DCKeywordList { typedef pvector Keywords; Keywords _keywords; - typedef pmap KeywordsByName; + typedef pmap> KeywordsByName; KeywordsByName _keywords_by_name; int _flags; diff --git a/direct/src/dcparser/dcLexer.cxx.prebuilt b/direct/src/dcparser/dcLexer.cxx.prebuilt index 69805f8c425..1c3aa4d34ae 100644 --- a/direct/src/dcparser/dcLexer.cxx.prebuilt +++ b/direct/src/dcparser/dcLexer.cxx.prebuilt @@ -642,9 +642,9 @@ static int initial_token; //////////////////////////////////////////////////////////////////// void -dc_init_lexer(std::istream &in, const std::string &filename) { +dc_init_lexer(std::istream &in, std::string filename) { input_p = ∈ - dc_filename = filename; + dc_filename = std::move(filename); line_number = 0; col_number = 0; error_count = 0; @@ -687,7 +687,7 @@ dcyywrap(void) { } void -dcyyerror(const std::string &msg) { +dcyyerror(std::string_view msg) { using std::cerr; cerr << "\nError"; @@ -704,7 +704,7 @@ dcyyerror(const std::string &msg) { } void -dcyywarning(const std::string &msg) { +dcyywarning(std::string_view msg) { using std::cerr; cerr << "\nWarning"; diff --git a/direct/src/dcparser/dcLexer.lxx b/direct/src/dcparser/dcLexer.lxx index b1e70d97da1..99adaa72782 100644 --- a/direct/src/dcparser/dcLexer.lxx +++ b/direct/src/dcparser/dcLexer.lxx @@ -53,9 +53,9 @@ static int initial_token; //////////////////////////////////////////////////////////////////// void -dc_init_lexer(std::istream &in, const std::string &filename) { +dc_init_lexer(std::istream &in, std::string filename) { input_p = ∈ - dc_filename = filename; + dc_filename = std::move(filename); line_number = 0; col_number = 0; error_count = 0; @@ -98,7 +98,7 @@ dcyywrap(void) { } void -dcyyerror(const std::string &msg) { +dcyyerror(std::string_view msg) { using std::cerr; cerr << "\nError"; @@ -115,7 +115,7 @@ dcyyerror(const std::string &msg) { } void -dcyywarning(const std::string &msg) { +dcyywarning(std::string_view msg) { using std::cerr; cerr << "\nWarning"; diff --git a/direct/src/dcparser/dcLexerDefs.h b/direct/src/dcparser/dcLexerDefs.h index eb6b5170458..1b6f204d37c 100644 --- a/direct/src/dcparser/dcLexerDefs.h +++ b/direct/src/dcparser/dcLexerDefs.h @@ -16,14 +16,14 @@ #include "dcbase.h" -void dc_init_lexer(std::istream &in, const std::string &filename); +void dc_init_lexer(std::istream &in, std::string filename); void dc_start_parameter_value(); void dc_start_parameter_description(); int dc_error_count(); int dc_warning_count(); -void dcyyerror(const std::string &msg); -void dcyywarning(const std::string &msg); +void dcyyerror(std::string_view msg); +void dcyywarning(std::string_view msg); int dcyylex(); diff --git a/direct/src/dcparser/dcMolecularField.cxx b/direct/src/dcparser/dcMolecularField.cxx index b5e18094a9d..c229c56ae5a 100644 --- a/direct/src/dcparser/dcMolecularField.cxx +++ b/direct/src/dcparser/dcMolecularField.cxx @@ -22,7 +22,7 @@ * */ DCMolecularField:: -DCMolecularField(const std::string &name, DCClass *dclass) : DCField(name, dclass) { +DCMolecularField(std::string name, DCClass *dclass) : DCField(std::move(name), dclass) { _got_keywords = false; } diff --git a/direct/src/dcparser/dcMolecularField.h b/direct/src/dcparser/dcMolecularField.h index 8983eddab0f..84fc139c3f9 100644 --- a/direct/src/dcparser/dcMolecularField.h +++ b/direct/src/dcparser/dcMolecularField.h @@ -27,7 +27,7 @@ class DCParameter; */ class EXPCL_DIRECT_DCPARSER DCMolecularField : public DCField { public: - DCMolecularField(const std::string &name, DCClass *dclass); + DCMolecularField(std::string name, DCClass *dclass); PUBLISHED: virtual DCMolecularField *as_molecular_field(); diff --git a/direct/src/dcparser/dcPacker.I b/direct/src/dcparser/dcPacker.I index c9212b3302d..bdf15d3f79a 100644 --- a/direct/src/dcparser/dcPacker.I +++ b/direct/src/dcparser/dcPacker.I @@ -206,7 +206,7 @@ pack_uint64(uint64_t value) { * Packs the indicated numeric or string value into the stream. */ INLINE void DCPacker:: -pack_string(const std::string &value) { +pack_string(std::string_view value) { nassertv(_mode == M_pack || _mode == M_repack); if (_current_field == nullptr) { _pack_error = true; @@ -782,7 +782,7 @@ raw_pack_float64(double value) { * Packs the data into the buffer between packing sessions. */ INLINE void DCPacker:: -raw_pack_string(const std::string &value) { +raw_pack_string(std::string_view value) { nassertv(_mode == M_idle); DCPackerInterface::do_pack_uint16(_pack_data.get_write_pointer(2), value.length()); _pack_data.append_data(value.data(), value.length()); diff --git a/direct/src/dcparser/dcPacker.cxx b/direct/src/dcparser/dcPacker.cxx index 78e95be6cfb..502cfee742d 100644 --- a/direct/src/dcparser/dcPacker.cxx +++ b/direct/src/dcparser/dcPacker.cxx @@ -263,7 +263,7 @@ end_repack() { * packer is in an invalid mode). */ bool DCPacker:: -seek(const string &field_name) { +seek(std::string_view field_name) { if (_catalog == nullptr) { _catalog = _root->get_catalog(); _live_catalog = _catalog->get_live_catalog(_unpack_data, _unpack_length); @@ -624,8 +624,8 @@ unpack_skip() { * parse error. */ bool DCPacker:: -parse_and_pack(const string &formatted_object) { - istringstream strm(formatted_object); +parse_and_pack(string formatted_object) { + istringstream strm(std::move(formatted_object)); return parse_and_pack(strm); } @@ -761,9 +761,9 @@ unpack_and_format(ostream &out, bool show_field_names) { * Outputs the indicated string within quotation marks. */ void DCPacker:: -enquote_string(ostream &out, char quote_mark, const string &str) { +enquote_string(ostream &out, char quote_mark, std::string_view str) { out << quote_mark; - for (string::const_iterator pi = str.begin(); + for (auto pi = str.begin(); pi != str.end(); ++pi) { if ((*pi) == quote_mark || (*pi) == '\\') { diff --git a/direct/src/dcparser/dcPacker.h b/direct/src/dcparser/dcPacker.h index 32f7e57de4c..a748de22e29 100644 --- a/direct/src/dcparser/dcPacker.h +++ b/direct/src/dcparser/dcPacker.h @@ -56,7 +56,7 @@ class EXPCL_DIRECT_DCPARSER DCPacker { void begin_repack(const DCPackerInterface *root); bool end_repack(); - bool seek(const std::string &field_name); + bool seek(std::string_view field_name); bool seek(int seek_index); INLINE bool has_nested_fields() const; @@ -77,7 +77,7 @@ class EXPCL_DIRECT_DCPARSER DCPacker { INLINE void pack_uint(unsigned int value); INLINE void pack_int64(int64_t value); INLINE void pack_uint64(uint64_t value); - INLINE void pack_string(const std::string &value); + INLINE void pack_string(std::string_view value); INLINE void pack_blob(const vector_uchar &value); INLINE void pack_literal_value(const vector_uchar &value); void pack_default_value(); @@ -110,7 +110,7 @@ class EXPCL_DIRECT_DCPARSER DCPacker { EXTENSION(void pack_object(PyObject *object)); EXTENSION(PyObject *unpack_object()); - bool parse_and_pack(const std::string &formatted_object); + bool parse_and_pack(std::string formatted_object); bool parse_and_pack(std::istream &in); std::string unpack_and_format(bool show_field_names = true); void unpack_and_format(std::ostream &out, bool show_field_names = true); @@ -152,7 +152,7 @@ class EXPCL_DIRECT_DCPARSER DCPacker { INLINE void raw_pack_uint32(unsigned int value); INLINE void raw_pack_uint64(uint64_t value); INLINE void raw_pack_float64(double value); - INLINE void raw_pack_string(const std::string &value); + INLINE void raw_pack_string(std::string_view value); INLINE void raw_pack_blob(const vector_uchar &value); // this is a hack to allw me to get in and out of 32bit Mode Faster need to @@ -187,7 +187,7 @@ class EXPCL_DIRECT_DCPARSER DCPacker { INLINE void raw_unpack_blob(vector_uchar &value); public: - static void enquote_string(std::ostream &out, char quote_mark, const std::string &str); + static void enquote_string(std::ostream &out, char quote_mark, std::string_view str); static void output_hex_string(std::ostream &out, const vector_uchar &str); private: diff --git a/direct/src/dcparser/dcPackerCatalog.I b/direct/src/dcparser/dcPackerCatalog.I index 1755db75e85..dd1e2d538ab 100644 --- a/direct/src/dcparser/dcPackerCatalog.I +++ b/direct/src/dcparser/dcPackerCatalog.I @@ -52,7 +52,7 @@ get_entry(int n) const { * get_entry(). */ int DCPackerCatalog::LiveCatalog:: -find_entry_by_name(const std::string &name) const { +find_entry_by_name(std::string_view name) const { return _catalog->find_entry_by_name(name); } diff --git a/direct/src/dcparser/dcPackerCatalog.cxx b/direct/src/dcparser/dcPackerCatalog.cxx index 86966aed1cd..a6eb1eec40f 100644 --- a/direct/src/dcparser/dcPackerCatalog.cxx +++ b/direct/src/dcparser/dcPackerCatalog.cxx @@ -58,7 +58,7 @@ DCPackerCatalog:: * get_entry(). */ int DCPackerCatalog:: -find_entry_by_name(const string &name) const { +find_entry_by_name(std::string_view name) const { EntriesByName::const_iterator ni; ni = _entries_by_name.find(name); if (ni != _entries_by_name.end()) { diff --git a/direct/src/dcparser/dcPackerCatalog.h b/direct/src/dcparser/dcPackerCatalog.h index 9a37f84a41b..6b63cc90c9c 100644 --- a/direct/src/dcparser/dcPackerCatalog.h +++ b/direct/src/dcparser/dcPackerCatalog.h @@ -58,7 +58,7 @@ class EXPCL_DIRECT_DCPARSER DCPackerCatalog { INLINE int get_num_entries() const; INLINE const Entry &get_entry(int n) const; - INLINE int find_entry_by_name(const std::string &name) const; + INLINE int find_entry_by_name(std::string_view name) const; INLINE int find_entry_by_field(const DCPackerInterface *field) const; private: @@ -71,7 +71,7 @@ class EXPCL_DIRECT_DCPARSER DCPackerCatalog { INLINE int get_num_entries() const; INLINE const Entry &get_entry(int n) const; - int find_entry_by_name(const std::string &name) const; + int find_entry_by_name(std::string_view name) const; int find_entry_by_field(const DCPackerInterface *field) const; const LiveCatalog *get_live_catalog(const char *data, size_t length) const; @@ -96,7 +96,7 @@ class EXPCL_DIRECT_DCPARSER DCPackerCatalog { typedef pvector Entries; Entries _entries; - typedef pmap EntriesByName; + typedef pmap> EntriesByName; EntriesByName _entries_by_name; typedef pmap EntriesByField; diff --git a/direct/src/dcparser/dcPackerInterface.cxx b/direct/src/dcparser/dcPackerInterface.cxx index 54784391c44..031ce34672b 100644 --- a/direct/src/dcparser/dcPackerInterface.cxx +++ b/direct/src/dcparser/dcPackerInterface.cxx @@ -23,8 +23,8 @@ using std::string; * */ DCPackerInterface:: -DCPackerInterface(const string &name) : - _name(name) +DCPackerInterface(string name) : + _name(std::move(name)) { _has_fixed_byte_size = false; _fixed_byte_size = 0; @@ -74,7 +74,7 @@ DCPackerInterface:: * seek for the field by name. */ int DCPackerInterface:: -find_seek_index(const string &name) const { +find_seek_index(std::string_view name) const { return get_catalog()->find_entry_by_name(name); } @@ -162,8 +162,8 @@ check_match(const string &description, DCFile *dcfile) const { * Sets the name of this field. */ void DCPackerInterface:: -set_name(const string &name) { - _name = name; +set_name(string name) { + _name = std::move(name); } /** @@ -242,7 +242,7 @@ pack_uint64(DCPackData &, uint64_t, bool &pack_error, bool &) const { * Packs the indicated numeric or string value into the stream. */ void DCPackerInterface:: -pack_string(DCPackData &, const string &, bool &pack_error, bool &) const { +pack_string(DCPackData &, std::string_view, bool &pack_error, bool &) const { pack_error = true; } diff --git a/direct/src/dcparser/dcPackerInterface.h b/direct/src/dcparser/dcPackerInterface.h index 1f4ac4a47f3..43339936957 100644 --- a/direct/src/dcparser/dcPackerInterface.h +++ b/direct/src/dcparser/dcPackerInterface.h @@ -66,13 +66,13 @@ END_PUBLISH */ class EXPCL_DIRECT_DCPARSER DCPackerInterface { public: - DCPackerInterface(const std::string &name = std::string()); + DCPackerInterface(std::string name = std::string()); DCPackerInterface(const DCPackerInterface ©); virtual ~DCPackerInterface(); PUBLISHED: INLINE const std::string &get_name() const; - int find_seek_index(const std::string &name) const; + int find_seek_index(std::string_view name) const; virtual DCField *as_field(); virtual const DCField *as_field() const; @@ -85,7 +85,7 @@ class EXPCL_DIRECT_DCPARSER DCPackerInterface { bool check_match(const std::string &description, DCFile *dcfile = nullptr) const; public: - virtual void set_name(const std::string &name); + virtual void set_name(std::string name); INLINE bool has_fixed_byte_size() const; INLINE size_t get_fixed_byte_size() const; INLINE bool has_fixed_structure() const; @@ -111,7 +111,7 @@ class EXPCL_DIRECT_DCPARSER DCPackerInterface { bool &pack_error, bool &range_error) const; virtual void pack_uint64(DCPackData &pack_data, uint64_t value, bool &pack_error, bool &range_error) const; - virtual void pack_string(DCPackData &pack_data, const std::string &value, + virtual void pack_string(DCPackData &pack_data, std::string_view value, bool &pack_error, bool &range_error) const; virtual void pack_blob(DCPackData &pack_data, const vector_uchar &value, bool &pack_error, bool &range_error) const; diff --git a/direct/src/dcparser/dcPacker_ext.cxx b/direct/src/dcparser/dcPacker_ext.cxx index 9ffca60ba91..4845920d22f 100644 --- a/direct/src/dcparser/dcPacker_ext.cxx +++ b/direct/src/dcparser/dcPacker_ext.cxx @@ -252,10 +252,9 @@ unpack_object() { } } } - // Fall through (if no constructor) - // If we don't know what kind of class object it is, or it doesn't have a // constructor, fall through and make a tuple. + [[fallthrough]]; default: { // First, build up a list from the nested objects. diff --git a/direct/src/dcparser/dcParameter.cxx b/direct/src/dcparser/dcParameter.cxx index 61b13ff04a2..9c4ebd58bf9 100644 --- a/direct/src/dcparser/dcParameter.cxx +++ b/direct/src/dcparser/dcParameter.cxx @@ -185,8 +185,8 @@ write(ostream &out, bool brief, int indent_level) const { */ void DCParameter:: write_instance(ostream &out, bool brief, int indent_level, - const string &prename, const string &name, - const string &postname) const { + std::string_view prename, std::string_view name, + std::string_view postname) const { indent(out, indent_level); output_instance(out, brief, prename, name, postname); output_keywords(out); @@ -202,8 +202,8 @@ write_instance(ostream &out, bool brief, int indent_level, * instead. */ void DCParameter:: -output_typedef_name(ostream &out, bool, const string &prename, - const string &name, const string &postname) const { +output_typedef_name(ostream &out, bool, std::string_view prename, + std::string_view name, std::string_view postname) const { out << get_typedef()->get_name(); if (!prename.empty() || !name.empty() || !postname.empty()) { out << " " << prename << name << postname; @@ -216,8 +216,8 @@ output_typedef_name(ostream &out, bool, const string &prename, */ void DCParameter:: write_typedef_name(ostream &out, bool brief, int indent_level, - const string &prename, const string &name, - const string &postname) const { + std::string_view prename, std::string_view name, + std::string_view postname) const { indent(out, indent_level) << get_typedef()->get_name(); if (!prename.empty() || !name.empty() || !postname.empty()) { diff --git a/direct/src/dcparser/dcParameter.h b/direct/src/dcparser/dcParameter.h index 49e6df12fe3..69a4c18ce76 100644 --- a/direct/src/dcparser/dcParameter.h +++ b/direct/src/dcparser/dcParameter.h @@ -62,16 +62,16 @@ class EXPCL_DIRECT_DCPARSER DCParameter : public DCField { virtual void output(std::ostream &out, bool brief) const; virtual void write(std::ostream &out, bool brief, int indent_level) const; - virtual void output_instance(std::ostream &out, bool brief, const std::string &prename, - const std::string &name, const std::string &postname) const=0; + virtual void output_instance(std::ostream &out, bool brief, std::string_view prename, + std::string_view name, std::string_view postname) const=0; virtual void write_instance(std::ostream &out, bool brief, int indent_level, - const std::string &prename, const std::string &name, - const std::string &postname) const; - void output_typedef_name(std::ostream &out, bool brief, const std::string &prename, - const std::string &name, const std::string &postname) const; + std::string_view prename, std::string_view name, + std::string_view postname) const; + void output_typedef_name(std::ostream &out, bool brief, std::string_view prename, + std::string_view name, std::string_view postname) const; void write_typedef_name(std::ostream &out, bool brief, int indent_level, - const std::string &prename, const std::string &name, - const std::string &postname) const; + std::string_view prename, std::string_view name, + std::string_view postname) const; virtual void generate_hash(HashGenerator &hashgen) const; private: diff --git a/direct/src/dcparser/dcParser.cxx.prebuilt b/direct/src/dcparser/dcParser.cxx.prebuilt index aeab2dc34cf..35bc3130515 100644 --- a/direct/src/dcparser/dcParser.cxx.prebuilt +++ b/direct/src/dcparser/dcParser.cxx.prebuilt @@ -122,25 +122,25 @@ static DCField *parameter_description = nullptr; //////////////////////////////////////////////////////////////////// void -dc_init_parser(istream &in, const string &filename, DCFile &file) { +dc_init_parser(istream &in, string filename, DCFile &file) { dc_file = &file; - dc_init_lexer(in, filename); + dc_init_lexer(in, std::move(filename)); } void -dc_init_parser_parameter_value(istream &in, const string &filename, +dc_init_parser_parameter_value(istream &in, string filename, DCPacker &packer) { dc_file = nullptr; current_packer = &packer; - dc_init_lexer(in, filename); + dc_init_lexer(in, std::move(filename)); dc_start_parameter_value(); } void -dc_init_parser_parameter_description(istream &in, const string &filename, +dc_init_parser_parameter_description(istream &in, string filename, DCFile *file) { dc_file = file; - dc_init_lexer(in, filename); + dc_init_lexer(in, std::move(filename)); parameter_description = nullptr; dc_start_parameter_description(); } diff --git a/direct/src/dcparser/dcParser.yxx b/direct/src/dcparser/dcParser.yxx index 9918ea99ba5..0eb840802f7 100644 --- a/direct/src/dcparser/dcParser.yxx +++ b/direct/src/dcparser/dcParser.yxx @@ -51,25 +51,25 @@ static DCField *parameter_description = nullptr; //////////////////////////////////////////////////////////////////// void -dc_init_parser(istream &in, const string &filename, DCFile &file) { +dc_init_parser(istream &in, string filename, DCFile &file) { dc_file = &file; - dc_init_lexer(in, filename); + dc_init_lexer(in, std::move(filename)); } void -dc_init_parser_parameter_value(istream &in, const string &filename, +dc_init_parser_parameter_value(istream &in, string filename, DCPacker &packer) { dc_file = nullptr; current_packer = &packer; - dc_init_lexer(in, filename); + dc_init_lexer(in, std::move(filename)); dc_start_parameter_value(); } void -dc_init_parser_parameter_description(istream &in, const string &filename, +dc_init_parser_parameter_description(istream &in, string filename, DCFile *file) { dc_file = file; - dc_init_lexer(in, filename); + dc_init_lexer(in, std::move(filename)); parameter_description = nullptr; dc_start_parameter_description(); } diff --git a/direct/src/dcparser/dcParserDefs.h b/direct/src/dcparser/dcParserDefs.h index 9c7c5897535..237d6a89f78 100644 --- a/direct/src/dcparser/dcParserDefs.h +++ b/direct/src/dcparser/dcParserDefs.h @@ -26,10 +26,10 @@ class DCParameter; class DCKeyword; class DCPacker; -void dc_init_parser(std::istream &in, const std::string &filename, DCFile &file); -void dc_init_parser_parameter_value(std::istream &in, const std::string &filename, +void dc_init_parser(std::istream &in, std::string filename, DCFile &file); +void dc_init_parser_parameter_value(std::istream &in, std::string filename, DCPacker &packer); -void dc_init_parser_parameter_description(std::istream &in, const std::string &filename, +void dc_init_parser_parameter_description(std::istream &in, std::string filename, DCFile *file); DCField *dc_get_parameter_description(); void dc_cleanup_parser(); diff --git a/direct/src/dcparser/dcSimpleParameter.cxx b/direct/src/dcparser/dcSimpleParameter.cxx index 5043307a4f1..11f44aff813 100644 --- a/direct/src/dcparser/dcSimpleParameter.cxx +++ b/direct/src/dcparser/dcSimpleParameter.cxx @@ -94,7 +94,7 @@ DCSimpleParameter(DCSubatomicType type, unsigned int divisor) : case ST_blob32: _num_length_bytes = 4; - // fall through + [[fallthrough]]; case ST_blob: // For blob and string, we will present an array interface as an array of // uint8, but we will also accept a set_value() with a string parameter. @@ -1027,7 +1027,7 @@ pack_uint64(DCPackData &pack_data, uint64_t value, * Packs the indicated numeric or string value into the stream. */ void DCSimpleParameter:: -pack_string(DCPackData &pack_data, const string &value, +pack_string(DCPackData &pack_data, std::string_view value, bool &pack_error, bool &range_error) const { size_t string_length = value.length(); @@ -2292,8 +2292,8 @@ unpack_skip(const char *data, size_t length, size_t &p, * identifier. */ void DCSimpleParameter:: -output_instance(std::ostream &out, bool brief, const string &prename, - const string &name, const string &postname) const { +output_instance(std::ostream &out, bool brief, std::string_view prename, + std::string_view name, std::string_view postname) const { if (get_typedef() != nullptr) { output_typedef_name(out, brief, prename, name, postname); diff --git a/direct/src/dcparser/dcSimpleParameter.h b/direct/src/dcparser/dcSimpleParameter.h index cafd246d628..18ebbda9970 100644 --- a/direct/src/dcparser/dcSimpleParameter.h +++ b/direct/src/dcparser/dcSimpleParameter.h @@ -60,7 +60,7 @@ class EXPCL_DIRECT_DCPARSER DCSimpleParameter : public DCParameter { bool &pack_error, bool &range_error) const; virtual void pack_uint64(DCPackData &pack_data, uint64_t value, bool &pack_error, bool &range_error) const; - virtual void pack_string(DCPackData &pack_data, const std::string &value, + virtual void pack_string(DCPackData &pack_data, std::string_view value, bool &pack_error, bool &range_error) const; virtual void pack_blob(DCPackData &pack_data, const vector_uchar &value, bool &pack_error, bool &range_error) const; @@ -85,8 +85,8 @@ class EXPCL_DIRECT_DCPARSER DCSimpleParameter : public DCParameter { virtual bool unpack_skip(const char *data, size_t length, size_t &p, bool &pack_error) const; - virtual void output_instance(std::ostream &out, bool brief, const std::string &prename, - const std::string &name, const std::string &postname) const; + virtual void output_instance(std::ostream &out, bool brief, std::string_view prename, + std::string_view name, std::string_view postname) const; virtual void generate_hash(HashGenerator &hashgen) const; protected: diff --git a/direct/src/dcparser/dcSwitch.cxx b/direct/src/dcparser/dcSwitch.cxx index dba5dacad00..43e6b29dc1a 100644 --- a/direct/src/dcparser/dcSwitch.cxx +++ b/direct/src/dcparser/dcSwitch.cxx @@ -26,8 +26,8 @@ using std::string; * via delete when the switch destructs. */ DCSwitch:: -DCSwitch(const string &name, DCField *key_parameter) : - _name(name), +DCSwitch(string name, DCField *key_parameter) : + _name(std::move(name)), _key_parameter(key_parameter) { _default_case = nullptr; @@ -164,7 +164,7 @@ get_field(int case_index, int n) const { * no field has this name. */ DCField *DCSwitch:: -get_field_by_name(int case_index, const string &name) const { +get_field_by_name(int case_index, std::string_view name) const { nassertr(case_index >= 0 && case_index < (int)_cases.size(), nullptr); const FieldsByName &fields_by_name = _cases[case_index]->_fields->_fields_by_name; @@ -314,8 +314,8 @@ write(ostream &out, bool brief, int indent_level) const { * stream. */ void DCSwitch:: -output_instance(ostream &out, bool brief, const string &prename, - const string &name, const string &postname) const { +output_instance(ostream &out, bool brief, std::string_view prename, + std::string_view name, std::string_view postname) const { out << "switch"; if (!_name.empty()) { out << " " << _name; @@ -359,8 +359,8 @@ output_instance(ostream &out, bool brief, const string &prename, */ void DCSwitch:: write_instance(ostream &out, bool brief, int indent_level, - const string &prename, const string &name, - const string &postname) const { + std::string_view prename, std::string_view name, + std::string_view postname) const { indent(out, indent_level) << "switch"; if (!_name.empty()) { @@ -554,8 +554,8 @@ start_new_case() { * */ DCSwitch::SwitchFields:: -SwitchFields(const string &name) : - DCPackerInterface(name) +SwitchFields(string name) : + DCPackerInterface(std::move(name)) { _has_nested_fields = true; _num_nested_fields = 0; diff --git a/direct/src/dcparser/dcSwitch.h b/direct/src/dcparser/dcSwitch.h index 31e69b452bd..62fd245ff44 100644 --- a/direct/src/dcparser/dcSwitch.h +++ b/direct/src/dcparser/dcSwitch.h @@ -29,7 +29,7 @@ class DCField; */ class EXPCL_DIRECT_DCPARSER DCSwitch : public DCDeclaration { public: - DCSwitch(const std::string &name, DCField *key_parameter); + DCSwitch(std::string name, DCField *key_parameter); virtual ~DCSwitch(); PUBLISHED: @@ -47,7 +47,7 @@ class EXPCL_DIRECT_DCPARSER DCSwitch : public DCDeclaration { vector_uchar get_value(int case_index) const; int get_num_fields(int case_index) const; DCField *get_field(int case_index, int n) const; - DCField *get_field_by_name(int case_index, const std::string &name) const; + DCField *get_field_by_name(int case_index, std::string_view name) const; public: bool is_field_valid() const; @@ -61,11 +61,11 @@ class EXPCL_DIRECT_DCPARSER DCSwitch : public DCDeclaration { virtual void output(std::ostream &out, bool brief) const; virtual void write(std::ostream &out, bool brief, int indent_level) const; - void output_instance(std::ostream &out, bool brief, const std::string &prename, - const std::string &name, const std::string &postname) const; + void output_instance(std::ostream &out, bool brief, std::string_view prename, + std::string_view name, std::string_view postname) const; void write_instance(std::ostream &out, bool brief, int indent_level, - const std::string &prename, const std::string &name, - const std::string &postname) const; + std::string_view prename, std::string_view name, + std::string_view postname) const; virtual void generate_hash(HashGenerator &hashgen) const; virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const; @@ -73,11 +73,11 @@ class EXPCL_DIRECT_DCPARSER DCSwitch : public DCDeclaration { public: typedef pvector Fields; - typedef pmap FieldsByName; + typedef pmap> FieldsByName; class SwitchFields : public DCPackerInterface { public: - SwitchFields(const std::string &name); + SwitchFields(std::string name); ~SwitchFields(); virtual DCPackerInterface *get_nested_field(int n) const; diff --git a/direct/src/dcparser/dcSwitchParameter.cxx b/direct/src/dcparser/dcSwitchParameter.cxx index d4f2c10394d..6269b111c02 100644 --- a/direct/src/dcparser/dcSwitchParameter.cxx +++ b/direct/src/dcparser/dcSwitchParameter.cxx @@ -155,8 +155,8 @@ apply_switch(const char *value_data, size_t length) const { * identifier. */ void DCSwitchParameter:: -output_instance(std::ostream &out, bool brief, const string &prename, - const string &name, const string &postname) const { +output_instance(std::ostream &out, bool brief, std::string_view prename, + std::string_view name, std::string_view postname) const { if (get_typedef() != nullptr) { output_typedef_name(out, brief, prename, name, postname); @@ -171,8 +171,8 @@ output_instance(std::ostream &out, bool brief, const string &prename, */ void DCSwitchParameter:: write_instance(std::ostream &out, bool brief, int indent_level, - const string &prename, const string &name, - const string &postname) const { + std::string_view prename, std::string_view name, + std::string_view postname) const { if (get_typedef() != nullptr) { write_typedef_name(out, brief, indent_level, prename, name, postname); diff --git a/direct/src/dcparser/dcSwitchParameter.h b/direct/src/dcparser/dcSwitchParameter.h index 7d123493aa8..ea5bbed2cc5 100644 --- a/direct/src/dcparser/dcSwitchParameter.h +++ b/direct/src/dcparser/dcSwitchParameter.h @@ -41,11 +41,11 @@ class EXPCL_DIRECT_DCPARSER DCSwitchParameter : public DCParameter { const DCPackerInterface *apply_switch(const char *value_data, size_t length) const; - virtual void output_instance(std::ostream &out, bool brief, const std::string &prename, - const std::string &name, const std::string &postname) const; + virtual void output_instance(std::ostream &out, bool brief, std::string_view prename, + std::string_view name, std::string_view postname) const; virtual void write_instance(std::ostream &out, bool brief, int indent_level, - const std::string &prename, const std::string &name, - const std::string &postname) const; + std::string_view prename, std::string_view name, + std::string_view postname) const; virtual void generate_hash(HashGenerator &hashgen) const; virtual bool pack_default_value(DCPackData &pack_data, bool &pack_error) const; diff --git a/direct/src/dcparser/dcTypedef.cxx b/direct/src/dcparser/dcTypedef.cxx index a83f68e895d..d05d4e0c744 100644 --- a/direct/src/dcparser/dcTypedef.cxx +++ b/direct/src/dcparser/dcTypedef.cxx @@ -35,13 +35,13 @@ DCTypedef(DCParameter *parameter, bool implicit) : * Creates a bogus typedef reference. */ DCTypedef:: -DCTypedef(const string &name) : +DCTypedef(string name) : _parameter(new DCSimpleParameter(ST_invalid)), _bogus_typedef(true), _implicit_typedef(false), _number(-1) { - _parameter->set_name(name); + _parameter->set_name(std::move(name)); } /** diff --git a/direct/src/dcparser/dcTypedef.h b/direct/src/dcparser/dcTypedef.h index 769f1f129fc..5289e8964e6 100644 --- a/direct/src/dcparser/dcTypedef.h +++ b/direct/src/dcparser/dcTypedef.h @@ -26,7 +26,7 @@ class DCParameter; class EXPCL_DIRECT_DCPARSER DCTypedef : public DCDeclaration { public: DCTypedef(DCParameter *parameter, bool implicit = false); - DCTypedef(const std::string &name); + DCTypedef(std::string name); virtual ~DCTypedef(); PUBLISHED: diff --git a/direct/src/dcparser/hashGenerator.cxx b/direct/src/dcparser/hashGenerator.cxx index bd3a6553b4f..34175e0c7d3 100644 --- a/direct/src/dcparser/hashGenerator.cxx +++ b/direct/src/dcparser/hashGenerator.cxx @@ -48,11 +48,10 @@ add_int(int num) { * Adds a string to the hash, by breaking it down into a sequence of integers. */ void HashGenerator:: -add_string(const std::string &str) { +add_string(std::string_view str) { add_int(str.length()); - std::string::const_iterator si; - for (si = str.begin(); si != str.end(); ++si) { - add_int(*si); + for (char c : str) { + add_int(c); } } diff --git a/direct/src/dcparser/hashGenerator.h b/direct/src/dcparser/hashGenerator.h index 7779dda7359..d793e254c61 100644 --- a/direct/src/dcparser/hashGenerator.h +++ b/direct/src/dcparser/hashGenerator.h @@ -25,7 +25,7 @@ class EXPCL_DIRECT_DCPARSER HashGenerator { HashGenerator(); void add_int(int num); - void add_string(const std::string &str); + void add_string(std::string_view str); void add_blob(const vector_uchar &bytes); unsigned long get_hash() const; diff --git a/direct/src/directscripts/Doxyfile.cxx b/direct/src/directscripts/Doxyfile.cxx index ecf8ff4a8bc..93e5ea2dc97 100644 --- a/direct/src/directscripts/Doxyfile.cxx +++ b/direct/src/directscripts/Doxyfile.cxx @@ -807,7 +807,6 @@ EXCLUDE = dtool/src/parser-inc \ panda/src/wgldisplay/wglext.h \ panda/src/glxdisplay/panda_glxext.h \ pandatool/src/gtk-stats \ - dtool/src/dtoolbase/fakestringstream.h \ dtool/src/dtoolbase/pdtoa.cxx \ dtool/src/dtoolutil/panda_getopt_long.h \ dtool/src/dtoolutil/panda_getopt_impl.h \ diff --git a/direct/src/dist/commands.py b/direct/src/dist/commands.py index 259ce58289f..cdfca3e12bb 100644 --- a/direct/src/dist/commands.py +++ b/direct/src/dist/commands.py @@ -315,16 +315,13 @@ def initialize_options(self): self.icons = {} self.platforms = [ 'manylinux2014_x86_64', - 'macosx_10_9_x86_64', + 'macosx_10_13_x86_64', 'win_amd64', ] if sys.version_info >= (3, 14): # This version of Python is only available for 10.15+. self.platforms[1] = 'macosx_10_15_x86_64' - elif sys.version_info >= (3, 13): - # This version of Python is only available for 10.13+. - self.platforms[1] = 'macosx_10_13_x86_64' self.plugins = [] self.embed_prc_data = True @@ -713,26 +710,18 @@ def download_wheels(self, platform): if platform.startswith('macosx_10_13_') and sys.version_info >= (3, 14): new_platform = platform.replace('macosx_10_13_', 'macosx_10_15_') self.announce('This error likely occurs because {} is not a supported target as of Python 3.14.\nChange the target platform to {} instead.'.format(platform, new_platform), distutils.log.ERROR) - elif platform.startswith('macosx_10_9_') and sys.version_info >= (3, 13): + elif platform.startswith('macosx_10_9_') or platform.startswith('macosx_10_6_'): if sys.version_info >= (3, 14): - new_platform = platform.replace('macosx_10_9_', 'macosx_10_15_') + new_platform = 'macosx_10_15_' + platform[12:] else: - new_platform = platform.replace('macosx_10_9_', 'macosx_10_13_') - self.announce('This error likely occurs because {} is not a supported target as of Python 3.13.\nChange the target platform to {} instead.'.format(platform, new_platform), distutils.log.ERROR) + new_platform = 'macosx_10_13_' + platform[12:] + self.announce('This error likely occurs because {} is no longer supported.\nChange the target platform to {} instead.'.format(platform, new_platform), distutils.log.ERROR) elif platform.startswith('manylinux2010_') and sys.version_info >= (3, 11): new_platform = platform.replace('manylinux2010_', 'manylinux2014_') self.announce('This error likely occurs because {} is not a supported target as of Python 3.11.\nChange the target platform to {} instead.'.format(platform, new_platform), distutils.log.ERROR) elif platform.startswith('manylinux1_') and sys.version_info >= (3, 10): new_platform = platform.replace('manylinux1_', 'manylinux2014_') self.announce('This error likely occurs because {} is not a supported target as of Python 3.10.\nChange the target platform to {} instead.'.format(platform, new_platform), distutils.log.ERROR) - elif platform.startswith('macosx_10_6_') and sys.version_info >= (3, 8): - if sys.version_info >= (3, 14): - new_platform = platform.replace('macosx_10_6_', 'macosx_10_15_') - elif sys.version_info >= (3, 13): - new_platform = platform.replace('macosx_10_6_', 'macosx_10_13_') - else: - new_platform = platform.replace('macosx_10_6_', 'macosx_10_9_') - self.announce('This error likely occurs because {} is not a supported target as of Python 3.8.\nChange the target platform to {} instead.'.format(platform, new_platform), distutils.log.ERROR) raise # Return a list of paths to the downloaded whls diff --git a/direct/src/distributed/cConnectionRepository.cxx b/direct/src/distributed/cConnectionRepository.cxx index 8dd11eadbe7..d6fb1605817 100644 --- a/direct/src/distributed/cConnectionRepository.cxx +++ b/direct/src/distributed/cConnectionRepository.cxx @@ -865,7 +865,7 @@ handle_update_field_owner() { * description on the indicated output stream. */ void CConnectionRepository:: -describe_message(std::ostream &out, const string &prefix, +describe_message(std::ostream &out, std::string_view prefix, const Datagram &dg) const { DCPacker packer; @@ -873,7 +873,7 @@ describe_message(std::ostream &out, const string &prefix, CHANNEL_TYPE do_id; unsigned int msg_type; bool is_update = false; - string full_prefix = "CR::" + prefix; + string full_prefix = "CR::" + string(prefix); if (!_client_datagram) { diff --git a/direct/src/distributed/cConnectionRepository.h b/direct/src/distributed/cConnectionRepository.h index 2db877215b1..5b1bcfc9c20 100644 --- a/direct/src/distributed/cConnectionRepository.h +++ b/direct/src/distributed/cConnectionRepository.h @@ -161,7 +161,7 @@ class CConnectionRepository { bool handle_update_field(); bool handle_update_field_owner(); - void describe_message(std::ostream &out, const std::string &prefix, + void describe_message(std::ostream &out, std::string_view prefix, const Datagram &dg) const; private: diff --git a/direct/src/distributed/cDistributedSmoothNodeBase.cxx b/direct/src/distributed/cDistributedSmoothNodeBase.cxx index 564ac6ac9b5..033155ae67a 100644 --- a/direct/src/distributed/cDistributedSmoothNodeBase.cxx +++ b/direct/src/distributed/cDistributedSmoothNodeBase.cxx @@ -272,7 +272,7 @@ broadcast_pos_hpr_xy() { * indicated field name, up until the arguments. */ void CDistributedSmoothNodeBase:: -begin_send_update(DCPacker &packer, const std::string &field_name) { +begin_send_update(DCPacker &packer, std::string_view field_name) { DCField *field = _dclass->get_field_by_name(field_name); nassertv(field != nullptr); diff --git a/direct/src/distributed/cDistributedSmoothNodeBase.h b/direct/src/distributed/cDistributedSmoothNodeBase.h index bebe55fcdb1..6f88bcd771b 100644 --- a/direct/src/distributed/cDistributedSmoothNodeBase.h +++ b/direct/src/distributed/cDistributedSmoothNodeBase.h @@ -68,7 +68,7 @@ class CDistributedSmoothNodeBase { INLINE void d_setSmPosHpr(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat h, PN_stdfloat p, PN_stdfloat r); INLINE void d_setSmPosHprL(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z, PN_stdfloat h, PN_stdfloat p, PN_stdfloat r, uint64_t l); - void begin_send_update(DCPacker &packer, const std::string &field_name); + void begin_send_update(DCPacker &packer, std::string_view field_name); void finish_send_update(DCPacker &packer); enum Flags { diff --git a/direct/src/interval/cConstrainHprInterval.cxx b/direct/src/interval/cConstrainHprInterval.cxx index 0cd3e26a356..3369604e885 100644 --- a/direct/src/interval/cConstrainHprInterval.cxx +++ b/direct/src/interval/cConstrainHprInterval.cxx @@ -26,10 +26,10 @@ TypeHandle CConstrainHprInterval::_type_handle; * node's local orientation will be copied unaltered. */ CConstrainHprInterval:: -CConstrainHprInterval(const std::string &name, double duration, +CConstrainHprInterval(std::string name, double duration, const NodePath &node, const NodePath &target, bool wrt, const LVecBase3 hprOffset) : - CConstraintInterval(name, duration), + CConstraintInterval(std::move(name), duration), _node(node), _target(target), _wrt(wrt) diff --git a/direct/src/interval/cConstrainHprInterval.h b/direct/src/interval/cConstrainHprInterval.h index 6338814b7d1..73a528fac32 100644 --- a/direct/src/interval/cConstrainHprInterval.h +++ b/direct/src/interval/cConstrainHprInterval.h @@ -26,7 +26,7 @@ */ class EXPCL_DIRECT_INTERVAL CConstrainHprInterval : public CConstraintInterval { PUBLISHED: - explicit CConstrainHprInterval(const std::string &name, double duration, + explicit CConstrainHprInterval(std::string name, double duration, const NodePath &node, const NodePath &target, bool wrt, const LVecBase3 hprOffset=LVector3::zero()); diff --git a/direct/src/interval/cConstrainPosHprInterval.cxx b/direct/src/interval/cConstrainPosHprInterval.cxx index 4e30d9f56e6..12367f73559 100644 --- a/direct/src/interval/cConstrainPosHprInterval.cxx +++ b/direct/src/interval/cConstrainPosHprInterval.cxx @@ -27,11 +27,11 @@ TypeHandle CConstrainPosHprInterval::_type_handle; * unaltered. */ CConstrainPosHprInterval:: -CConstrainPosHprInterval(const std::string &name, double duration, +CConstrainPosHprInterval(std::string name, double duration, const NodePath &node, const NodePath &target, bool wrt, const LVecBase3 posOffset, const LVecBase3 hprOffset) : - CConstraintInterval(name, duration), + CConstraintInterval(std::move(name), duration), _node(node), _target(target), _wrt(wrt), diff --git a/direct/src/interval/cConstrainPosHprInterval.h b/direct/src/interval/cConstrainPosHprInterval.h index a96aa097de8..77df3c563bc 100644 --- a/direct/src/interval/cConstrainPosHprInterval.h +++ b/direct/src/interval/cConstrainPosHprInterval.h @@ -26,7 +26,7 @@ */ class EXPCL_DIRECT_INTERVAL CConstrainPosHprInterval : public CConstraintInterval { PUBLISHED: - explicit CConstrainPosHprInterval(const std::string &name, double duration, + explicit CConstrainPosHprInterval(std::string name, double duration, const NodePath &node, const NodePath &target, bool wrt, const LVecBase3 posOffset=LVector3::zero(), const LVecBase3 hprOffset=LVector3::zero()); diff --git a/direct/src/interval/cConstrainPosInterval.cxx b/direct/src/interval/cConstrainPosInterval.cxx index 1cc967617c5..40490ec6b82 100644 --- a/direct/src/interval/cConstrainPosInterval.cxx +++ b/direct/src/interval/cConstrainPosInterval.cxx @@ -26,10 +26,10 @@ TypeHandle CConstrainPosInterval::_type_handle; * node's local position will be copied unaltered. */ CConstrainPosInterval:: -CConstrainPosInterval(const std::string &name, double duration, +CConstrainPosInterval(std::string name, double duration, const NodePath &node, const NodePath &target, bool wrt, const LVecBase3 posOffset) : - CConstraintInterval(name, duration), + CConstraintInterval(std::move(name), duration), _node(node), _target(target), _wrt(wrt), diff --git a/direct/src/interval/cConstrainPosInterval.h b/direct/src/interval/cConstrainPosInterval.h index edb379559f5..ec8133fdeaa 100644 --- a/direct/src/interval/cConstrainPosInterval.h +++ b/direct/src/interval/cConstrainPosInterval.h @@ -25,7 +25,7 @@ */ class EXPCL_DIRECT_INTERVAL CConstrainPosInterval : public CConstraintInterval { PUBLISHED: - explicit CConstrainPosInterval(const std::string &name, double duration, + explicit CConstrainPosInterval(std::string name, double duration, const NodePath &node, const NodePath &target, bool wrt, const LVecBase3 posOffset=LVector3::zero()); diff --git a/direct/src/interval/cConstrainTransformInterval.cxx b/direct/src/interval/cConstrainTransformInterval.cxx index a21c109bde1..9f3c664d335 100644 --- a/direct/src/interval/cConstrainTransformInterval.cxx +++ b/direct/src/interval/cConstrainTransformInterval.cxx @@ -27,10 +27,10 @@ TypeHandle CConstrainTransformInterval::_type_handle; * local transform will be copied unaltered. */ CConstrainTransformInterval:: -CConstrainTransformInterval(const std::string &name, double duration, +CConstrainTransformInterval(std::string name, double duration, const NodePath &node, const NodePath &target, bool wrt) : - CConstraintInterval(name, duration), + CConstraintInterval(std::move(name), duration), _node(node), _target(target), _wrt(wrt) diff --git a/direct/src/interval/cConstrainTransformInterval.h b/direct/src/interval/cConstrainTransformInterval.h index 41da174670a..0a2cd1468c9 100644 --- a/direct/src/interval/cConstrainTransformInterval.h +++ b/direct/src/interval/cConstrainTransformInterval.h @@ -24,7 +24,7 @@ */ class EXPCL_DIRECT_INTERVAL CConstrainTransformInterval : public CConstraintInterval { PUBLISHED: - explicit CConstrainTransformInterval(const std::string &name, double duration, + explicit CConstrainTransformInterval(std::string name, double duration, const NodePath &node, const NodePath &target, bool wrt); diff --git a/direct/src/interval/cConstraintInterval.cxx b/direct/src/interval/cConstraintInterval.cxx index 71ac457cb4d..f5c11701d59 100644 --- a/direct/src/interval/cConstraintInterval.cxx +++ b/direct/src/interval/cConstraintInterval.cxx @@ -19,7 +19,7 @@ TypeHandle CConstraintInterval::_type_handle; * */ CConstraintInterval:: -CConstraintInterval(const std::string &name, double duration) : - CInterval(name, duration, true) +CConstraintInterval(std::string name, double duration) : + CInterval(std::move(name), duration, true) { } diff --git a/direct/src/interval/cConstraintInterval.h b/direct/src/interval/cConstraintInterval.h index 97a174b51fe..8e21c92c968 100644 --- a/direct/src/interval/cConstraintInterval.h +++ b/direct/src/interval/cConstraintInterval.h @@ -26,7 +26,7 @@ class EXPCL_DIRECT_INTERVAL CConstraintInterval : public CInterval { bool bogus_variable; public: - CConstraintInterval(const std::string &name, double duration); + CConstraintInterval(std::string name, double duration); public: static TypeHandle get_class_type() { diff --git a/direct/src/interval/cInterval.I b/direct/src/interval/cInterval.I index f42fe8e62ae..2c357e1b20a 100644 --- a/direct/src/interval/cInterval.I +++ b/direct/src/interval/cInterval.I @@ -64,8 +64,8 @@ is_stopped() const { * own. */ INLINE void CInterval:: -set_done_event(const std::string &event) { - _done_event = event; +set_done_event(std::string event) { + _done_event = std::move(event); } /** diff --git a/direct/src/interval/cInterval.cxx b/direct/src/interval/cInterval.cxx index 7102a65f725..5822e7db8e1 100644 --- a/direct/src/interval/cInterval.cxx +++ b/direct/src/interval/cInterval.cxx @@ -26,24 +26,23 @@ PStatCollector CInterval::_root_pcollector("App:Tasks:ivalLoop"); TypeHandle CInterval::_type_handle; static inline string -get_pstats_name(const string &name) { - string pname = name; - size_t hyphen = pname.find('-'); - if (hyphen != string::npos) { - pname = pname.substr(0, hyphen); +get_pstats_name(std::string_view name) { + size_t hyphen = name.find('-'); + if (hyphen != std::string_view::npos) { + name = name.substr(0, hyphen); } - return pname; + return string(name); } /** * */ CInterval:: -CInterval(const string &name, double duration, bool open_ended) : +CInterval(string name, double duration, bool open_ended) : _state(S_initial), _curr_t(0.0), - _name(name), - _pname(get_pstats_name(name)), + _name(std::move(name)), + _pname(get_pstats_name(_name)), _duration(std::max(duration, 0.0)), _open_ended(open_ended), _dirty(false), diff --git a/direct/src/interval/cInterval.h b/direct/src/interval/cInterval.h index 4f1f37e3790..f887f232549 100644 --- a/direct/src/interval/cInterval.h +++ b/direct/src/interval/cInterval.h @@ -35,7 +35,7 @@ class CIntervalManager; */ class EXPCL_DIRECT_INTERVAL CInterval : public TypedReferenceCount { public: - CInterval(const std::string &name, double duration, bool open_ended); + CInterval(std::string name, double duration, bool open_ended); virtual ~CInterval(); PUBLISHED: @@ -64,7 +64,7 @@ class EXPCL_DIRECT_INTERVAL CInterval : public TypedReferenceCount { INLINE State get_state() const; INLINE bool is_stopped() const; - INLINE void set_done_event(const std::string &event); + INLINE void set_done_event(std::string event); INLINE const std::string &get_done_event() const; void set_t(double t); diff --git a/direct/src/interval/cIntervalManager.cxx b/direct/src/interval/cIntervalManager.cxx index 137f30c0ff0..dc1fe1c3942 100644 --- a/direct/src/interval/cIntervalManager.cxx +++ b/direct/src/interval/cIntervalManager.cxx @@ -108,7 +108,7 @@ add_c_interval(CInterval *interval, bool external) { * interval, or -1 if there is not. */ int CIntervalManager:: -find_c_interval(const std::string &name) const { +find_c_interval(std::string_view name) const { MutexHolder holder(_lock); NameIndex::const_iterator ni = _name_index.find(name); diff --git a/direct/src/interval/cIntervalManager.h b/direct/src/interval/cIntervalManager.h index 33f3d29ff18..b2d8ed74f4a 100644 --- a/direct/src/interval/cIntervalManager.h +++ b/direct/src/interval/cIntervalManager.h @@ -45,7 +45,7 @@ class EXPCL_DIRECT_INTERVAL CIntervalManager { INLINE EventQueue *get_event_queue() const; int add_c_interval(CInterval *interval, bool external); - int find_c_interval(const std::string &name) const; + int find_c_interval(std::string_view name) const; CInterval *get_c_interval(int index) const; void remove_c_interval(int index); @@ -79,7 +79,7 @@ class EXPCL_DIRECT_INTERVAL CIntervalManager { }; typedef pvector Intervals; Intervals _intervals; - typedef pmap NameIndex; + typedef pmap> NameIndex; NameIndex _name_index; typedef vector_int Removed; Removed _removed; diff --git a/direct/src/interval/cLerpAnimEffectInterval.I b/direct/src/interval/cLerpAnimEffectInterval.I index 08c48949f28..b3486fd4bbe 100644 --- a/direct/src/interval/cLerpAnimEffectInterval.I +++ b/direct/src/interval/cLerpAnimEffectInterval.I @@ -15,9 +15,9 @@ * */ INLINE CLerpAnimEffectInterval:: -CLerpAnimEffectInterval(const std::string &name, double duration, +CLerpAnimEffectInterval(std::string name, double duration, CLerpInterval::BlendType blend_type) : - CLerpInterval(name, duration, blend_type) + CLerpInterval(std::move(name), duration, blend_type) { } @@ -30,19 +30,19 @@ CLerpAnimEffectInterval(const std::string &name, double duration, * for output. */ INLINE void CLerpAnimEffectInterval:: -add_control(AnimControl *control, const std::string &name, +add_control(AnimControl *control, std::string name, float begin_effect, float end_effect) { - _controls.push_back(ControlDef(control, name, begin_effect, end_effect)); + _controls.push_back(ControlDef(control, std::move(name), begin_effect, end_effect)); } /** * */ INLINE CLerpAnimEffectInterval::ControlDef:: -ControlDef(AnimControl *control, const std::string &name, +ControlDef(AnimControl *control, std::string name, float begin_effect, float end_effect) : _control(control), - _name(name), + _name(std::move(name)), _begin_effect(begin_effect), _end_effect(end_effect) { diff --git a/direct/src/interval/cLerpAnimEffectInterval.h b/direct/src/interval/cLerpAnimEffectInterval.h index 6200ffea9c7..122133bc02b 100644 --- a/direct/src/interval/cLerpAnimEffectInterval.h +++ b/direct/src/interval/cLerpAnimEffectInterval.h @@ -31,10 +31,10 @@ */ class EXPCL_DIRECT_INTERVAL CLerpAnimEffectInterval : public CLerpInterval { PUBLISHED: - INLINE explicit CLerpAnimEffectInterval(const std::string &name, double duration, + INLINE explicit CLerpAnimEffectInterval(std::string name, double duration, BlendType blend_type); - INLINE void add_control(AnimControl *control, const std::string &name, + INLINE void add_control(AnimControl *control, std::string name, float begin_effect, float end_effect); virtual void priv_step(double t); @@ -44,7 +44,7 @@ class EXPCL_DIRECT_INTERVAL CLerpAnimEffectInterval : public CLerpInterval { private: class ControlDef { public: - INLINE ControlDef(AnimControl *control, const std::string &name, + INLINE ControlDef(AnimControl *control, std::string name, float begin_effect, float end_effect); PT(AnimControl) _control; std::string _name; diff --git a/direct/src/interval/cLerpInterval.I b/direct/src/interval/cLerpInterval.I index c0c101cfc4c..33faaf117e6 100644 --- a/direct/src/interval/cLerpInterval.I +++ b/direct/src/interval/cLerpInterval.I @@ -15,9 +15,9 @@ * */ INLINE CLerpInterval:: -CLerpInterval(const std::string &name, double duration, +CLerpInterval(std::string name, double duration, CLerpInterval::BlendType blend_type) : - CInterval(name, duration, true), + CInterval(std::move(name), duration, true), _blend_type(blend_type) { } diff --git a/direct/src/interval/cLerpInterval.cxx b/direct/src/interval/cLerpInterval.cxx index 43a291f94ee..10f3fe7f4db 100644 --- a/direct/src/interval/cLerpInterval.cxx +++ b/direct/src/interval/cLerpInterval.cxx @@ -21,7 +21,7 @@ TypeHandle CLerpInterval::_type_handle; * string, or BT_invalid if the string doesn't match anything. */ CLerpInterval::BlendType CLerpInterval:: -string_blend_type(const std::string &blend_type) { +string_blend_type(std::string_view blend_type) { if (blend_type == "easeIn") { return BT_ease_in; } else if (blend_type == "easeOut") { diff --git a/direct/src/interval/cLerpInterval.h b/direct/src/interval/cLerpInterval.h index 6587066f040..d531129dc17 100644 --- a/direct/src/interval/cLerpInterval.h +++ b/direct/src/interval/cLerpInterval.h @@ -32,13 +32,13 @@ class EXPCL_DIRECT_INTERVAL CLerpInterval : public CInterval { }; public: - INLINE CLerpInterval(const std::string &name, double duration, + INLINE CLerpInterval(std::string name, double duration, BlendType blend_type); PUBLISHED: INLINE BlendType get_blend_type() const; - static BlendType string_blend_type(const std::string &blend_type); + static BlendType string_blend_type(std::string_view blend_type); protected: double compute_delta(double t) const; diff --git a/direct/src/interval/cLerpNodePathInterval.cxx b/direct/src/interval/cLerpNodePathInterval.cxx index 97babae49eb..d5cef9f3a1a 100644 --- a/direct/src/interval/cLerpNodePathInterval.cxx +++ b/direct/src/interval/cLerpNodePathInterval.cxx @@ -47,11 +47,11 @@ TypeHandle CLerpNodePathInterval::_type_handle; * otherwise, it is reset. */ CLerpNodePathInterval:: -CLerpNodePathInterval(const std::string &name, double duration, +CLerpNodePathInterval(std::string name, double duration, CLerpInterval::BlendType blend_type, bool bake_in_start, bool fluid, const NodePath &node, const NodePath &other) : - CLerpInterval(name, duration, blend_type), + CLerpInterval(std::move(name), duration, blend_type), _node(node), _other(other), _flags(0), diff --git a/direct/src/interval/cLerpNodePathInterval.h b/direct/src/interval/cLerpNodePathInterval.h index d079f8eaa03..07e0fbb4ee0 100644 --- a/direct/src/interval/cLerpNodePathInterval.h +++ b/direct/src/interval/cLerpNodePathInterval.h @@ -25,7 +25,7 @@ */ class EXPCL_DIRECT_INTERVAL CLerpNodePathInterval : public CLerpInterval { PUBLISHED: - explicit CLerpNodePathInterval(const std::string &name, double duration, + explicit CLerpNodePathInterval(std::string name, double duration, BlendType blend_type, bool bake_in_start, bool fluid, const NodePath &node, const NodePath &other); diff --git a/direct/src/interval/cMetaInterval.cxx b/direct/src/interval/cMetaInterval.cxx index a203167557e..9003f9dd723 100644 --- a/direct/src/interval/cMetaInterval.cxx +++ b/direct/src/interval/cMetaInterval.cxx @@ -29,8 +29,8 @@ TypeHandle CMetaInterval::_type_handle; * */ CMetaInterval:: -CMetaInterval(const string &name) : - CInterval(name, 0.0, true) +CMetaInterval(string name) : + CInterval(std::move(name), 0.0, true) { _precision = interval_precision; _current_nesting_level = 0; @@ -98,13 +98,13 @@ clear_intervals() { * The return value is the index of the def entry created by this push. */ int CMetaInterval:: -push_level(const string &name, double rel_time, RelativeStart rel_to) { +push_level(string name, double rel_time, RelativeStart rel_to) { nassertr(_event_queue.empty() && !_processing_events, -1); _defs.push_back(IntervalDef()); IntervalDef &def = _defs.back(); def._type = DT_push_level; - def._ext_name = name; + def._ext_name = std::move(name); def._rel_time = rel_time; def._rel_to = rel_to; _current_nesting_level++; @@ -156,7 +156,7 @@ add_c_interval(CInterval *c_interval, * interval. */ int CMetaInterval:: -add_ext_index(int ext_index, const string &name, double duration, +add_ext_index(int ext_index, string name, double duration, bool open_ended, double rel_time, RelativeStart rel_to) { nassertr(_event_queue.empty() && !_processing_events, -1); @@ -165,7 +165,7 @@ add_ext_index(int ext_index, const string &name, double duration, IntervalDef &def = _defs.back(); def._type = DT_ext_index; def._ext_index = ext_index; - def._ext_name = name; + def._ext_name = std::move(name); def._ext_duration = duration; def._ext_open_ended = open_ended; def._rel_time = rel_time; @@ -208,7 +208,7 @@ pop_level(double duration) { * interval is not found, nothing is changed and false is returned. */ bool CMetaInterval:: -set_interval_start_time(const string &name, double rel_time, +set_interval_start_time(std::string_view name, double rel_time, CMetaInterval::RelativeStart rel_to) { nassertr(_event_queue.empty() && !_processing_events, false); Defs::iterator di; @@ -246,7 +246,7 @@ set_interval_start_time(const string &name, double rel_time, * is not found. */ double CMetaInterval:: -get_interval_start_time(const string &name) const { +get_interval_start_time(std::string_view name) const { recompute(); Defs::const_iterator di; for (di = _defs.begin(); di != _defs.end(); ++di) { @@ -280,7 +280,7 @@ get_interval_start_time(const string &name) const { * not found. */ double CMetaInterval:: -get_interval_end_time(const string &name) const { +get_interval_end_time(std::string_view name) const { recompute(); Defs::const_iterator di; for (di = _defs.begin(); di != _defs.end(); ++di) { diff --git a/direct/src/interval/cMetaInterval.h b/direct/src/interval/cMetaInterval.h index 40fb03d102e..4ae2e94b5d8 100644 --- a/direct/src/interval/cMetaInterval.h +++ b/direct/src/interval/cMetaInterval.h @@ -31,7 +31,7 @@ */ class EXPCL_DIRECT_INTERVAL CMetaInterval : public CInterval { PUBLISHED: - explicit CMetaInterval(const std::string &name); + explicit CMetaInterval(std::string name); virtual ~CMetaInterval(); enum RelativeStart { @@ -44,20 +44,20 @@ class EXPCL_DIRECT_INTERVAL CMetaInterval : public CInterval { INLINE double get_precision() const; void clear_intervals(); - int push_level(const std::string &name, + int push_level(std::string name, double rel_time, RelativeStart rel_to); int add_c_interval(CInterval *c_interval, double rel_time = 0.0f, RelativeStart rel_to = RS_previous_end); - int add_ext_index(int ext_index, const std::string &name, + int add_ext_index(int ext_index, std::string name, double duration, bool open_ended, double rel_time, RelativeStart rel_to); int pop_level(double duration = -1.0); - bool set_interval_start_time(const std::string &name, double rel_time, + bool set_interval_start_time(std::string_view name, double rel_time, RelativeStart rel_to = RS_level_begin); - double get_interval_start_time(const std::string &name) const; - double get_interval_end_time(const std::string &name) const; + double get_interval_start_time(std::string_view name) const; + double get_interval_end_time(std::string_view name) const; enum DefType { DT_c_interval, diff --git a/direct/src/interval/hideInterval.cxx b/direct/src/interval/hideInterval.cxx index 46498800e00..15a49766a0d 100644 --- a/direct/src/interval/hideInterval.cxx +++ b/direct/src/interval/hideInterval.cxx @@ -20,8 +20,8 @@ TypeHandle HideInterval::_type_handle; * */ HideInterval:: -HideInterval(const NodePath &node, const std::string &name) : - CInterval(name, 0.0, true), +HideInterval(const NodePath &node, std::string name) : + CInterval(std::move(name), 0.0, true), _node(node) { nassertv(!node.is_empty()); diff --git a/direct/src/interval/hideInterval.h b/direct/src/interval/hideInterval.h index 8428d3ab705..efabed4981b 100644 --- a/direct/src/interval/hideInterval.h +++ b/direct/src/interval/hideInterval.h @@ -23,7 +23,7 @@ */ class EXPCL_DIRECT_INTERVAL HideInterval : public CInterval { PUBLISHED: - explicit HideInterval(const NodePath &node, const std::string &name = std::string()); + explicit HideInterval(const NodePath &node, std::string name = std::string()); virtual void priv_instant(); virtual void priv_reverse_instant(); diff --git a/direct/src/interval/showInterval.cxx b/direct/src/interval/showInterval.cxx index b014100f2f9..63955731ebb 100644 --- a/direct/src/interval/showInterval.cxx +++ b/direct/src/interval/showInterval.cxx @@ -20,8 +20,8 @@ TypeHandle ShowInterval::_type_handle; * */ ShowInterval:: -ShowInterval(const NodePath &node, const std::string &name) : - CInterval(name, 0.0, true), +ShowInterval(const NodePath &node, std::string name) : + CInterval(std::move(name), 0.0, true), _node(node) { nassertv(!node.is_empty()); diff --git a/direct/src/interval/showInterval.h b/direct/src/interval/showInterval.h index c50db953a2c..f3934058151 100644 --- a/direct/src/interval/showInterval.h +++ b/direct/src/interval/showInterval.h @@ -23,7 +23,7 @@ */ class EXPCL_DIRECT_INTERVAL ShowInterval : public CInterval { PUBLISHED: - explicit ShowInterval(const NodePath &node, const std::string &name = std::string()); + explicit ShowInterval(const NodePath &node, std::string name = std::string()); virtual void priv_instant(); virtual void priv_reverse_instant(); diff --git a/dtool/CompilerFlags.cmake b/dtool/CompilerFlags.cmake index d50e5e2238f..85150f3cdf7 100644 --- a/dtool/CompilerFlags.cmake +++ b/dtool/CompilerFlags.cmake @@ -61,8 +61,8 @@ if(ENABLE_ASAN) endif() endif() -# Panda3D is now a C++14 project. -set(CMAKE_CXX_STANDARD 14) +# Panda3D is now a C++17 project. +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Set certain CMake flags we expect diff --git a/dtool/Config.cmake b/dtool/Config.cmake index d323cdb8c74..26be51a55fb 100644 --- a/dtool/Config.cmake +++ b/dtool/Config.cmake @@ -265,7 +265,7 @@ if(BUILD_INTERROGATE) panda3d-interrogate GIT_REPOSITORY https://github.com/panda3d/interrogate.git - GIT_TAG 7cf2550d2c8d95b8c268aa4bb0b5602e85a086dc + GIT_TAG 47ff6da7705062b1bc7f9847fc8ca0c92b82e6eb PREFIX ${_interrogate_dir} CMAKE_ARGS diff --git a/dtool/LocalSetup.cmake b/dtool/LocalSetup.cmake index 5ddea90f9aa..84279847454 100644 --- a/dtool/LocalSetup.cmake +++ b/dtool/LocalSetup.cmake @@ -67,15 +67,6 @@ if(UNIX) set(IOCTL_TERMINAL_WIDTH 1) endif() -# Do the system headers define key ios typedefs like ios::openmode -# and ios::fmtflags? -check_cxx_source_compiles(" -#include -std::ios::openmode foo; -std::ios::fmtflags bar; -int main(int argc, char *argv[]) { return 0; } -" HAVE_IOS_TYPEDEFS) - # Define if the C++ iostream library defines ios::binary. check_cxx_source_compiles(" #include @@ -114,16 +105,12 @@ endif() # Do we have all these header files? check_include_file_cxx(io.h PHAVE_IO_H) -check_include_file_cxx(iostream PHAVE_IOSTREAM) check_include_file_cxx(malloc.h PHAVE_MALLOC_H) check_include_file_cxx(sys/malloc.h PHAVE_SYS_MALLOC_H) check_include_file_cxx(alloca.h PHAVE_ALLOCA_H) check_include_file_cxx(locale.h PHAVE_LOCALE_H) check_include_file_cxx(string.h PHAVE_STRING_H) -check_include_file_cxx(stdlib.h PHAVE_STDLIB_H) check_include_file_cxx(limits.h PHAVE_LIMITS_H) -check_include_file_cxx(sstream PHAVE_SSTREAM) -check_include_file_cxx(new PHAVE_NEW) check_include_file_cxx(sys/types.h PHAVE_SYS_TYPES_H) check_include_file_cxx(sys/time.h PHAVE_SYS_TIME_H) check_include_file_cxx(unistd.h PHAVE_UNISTD_H) @@ -132,7 +119,6 @@ check_include_file_cxx(glob.h PHAVE_GLOB_H) check_include_file_cxx(dirent.h PHAVE_DIRENT_H) check_include_file_cxx(ucontext.h PHAVE_UCONTEXT_H) #TODO doesn't work on OSX, use sys/ucontext.h check_include_file_cxx(linux/input.h PHAVE_LINUX_INPUT_H) -check_include_file_cxx(stdint.h PHAVE_STDINT_H) check_include_file_cxx(execinfo.h PHAVE_EXECINFO_H) # Do we have Posix threads? diff --git a/dtool/Package.cmake b/dtool/Package.cmake index 8b9d04f9fec..a302feae831 100644 --- a/dtool/Package.cmake +++ b/dtool/Package.cmake @@ -393,12 +393,9 @@ if(HAVE_PYTHON) if(_arch_tag STREQUAL "arm64" AND _target VERSION_LESS "11.0") set(_target "11.0") - elseif(PYTHON_VERSION_STRING VERSION_GREATER_EQUAL "3.13" AND _target VERSION_LESS "10.13") + elseif(_target VERSION_LESS "10.13") set(_target "10.13") - elseif(PYTHON_VERSION_STRING VERSION_GREATER_EQUAL "3.8" AND _target VERSION_LESS "10.9") - set(_target "10.9") - endif() set(_platform "macosx-${_target}-${_arch_tag}") diff --git a/dtool/dtool_config.h.in b/dtool/dtool_config.h.in index 2c178844071..9e5fdb20f41 100644 --- a/dtool/dtool_config.h.in +++ b/dtool/dtool_config.h.in @@ -178,16 +178,9 @@ /* Define if getopt appears in getopt.h. */ #cmakedefine PHAVE_GETOPT_H -/* Do the system headers define key ios typedefs like ios::openmode - and ios::fmtflags? */ -#cmakedefine HAVE_IOS_TYPEDEFS - /* Define if you have the header file. */ #cmakedefine PHAVE_IO_H -/* Define if you have the header file. */ -#cmakedefine PHAVE_IOSTREAM - /* Define if you have the header file. */ #cmakedefine PHAVE_MALLOC_H @@ -203,18 +196,9 @@ /* Define if you have the header file. */ #cmakedefine PHAVE_STRING_H -/* Define if you have the header file. */ -#cmakedefine PHAVE_STDLIB_H - /* Define if you have the header file. */ #cmakedefine PHAVE_LIMITS_H -/* Define if you have the header file. */ -#cmakedefine PHAVE_SSTREAM - -/* Define if you have the header file. */ -#cmakedefine PHAVE_NEW - /* Define if you have the header file. */ #cmakedefine PHAVE_SYS_TYPES_H @@ -227,9 +211,6 @@ /* Do we have ? This enables us to use raw mouse input. */ #cmakedefine PHAVE_LINUX_INPUT_H -/* Do we have ? */ -#cmakedefine PHAVE_STDINT_H - /* Do we have Posix threads? */ #cmakedefine HAVE_POSIX_THREADS diff --git a/dtool/src/dtoolbase/CMakeLists.txt b/dtool/src/dtoolbase/CMakeLists.txt index 382fb20819b..b04581d7f1e 100644 --- a/dtool/src/dtoolbase/CMakeLists.txt +++ b/dtool/src/dtoolbase/CMakeLists.txt @@ -2,13 +2,6 @@ configure_file(pandaVersion.h.in pandaVersion.h) configure_file(checkPandaVersion.h.in checkPandaVersion.h) configure_file(checkPandaVersion.cxx.in checkPandaVersion.cxx) -if(CMAKE_CXX_STANDARD GREATER 16) - # This serves as a reminder to update checkPandaVersion.h.in when we upgrade - # to C++17, which supports inline variables - a cleaner way of depending on - # the Panda version symbol from a header than what we're currently doing. - message(FATAL_ERROR "Developer notice: Update checkPandaVersion.h.in for C++17!") -endif() - set(P3DTOOLBASE_HEADERS ${CMAKE_CURRENT_BINARY_DIR}/checkPandaVersion.h ${CMAKE_CURRENT_BINARY_DIR}/pandaVersion.h @@ -19,7 +12,6 @@ set(P3DTOOLBASE_HEADERS dtoolbase.h dtoolbase_cc.h dtoolsymbols.h dtool_platform.h extension.h - fakestringstream.h indent.I indent.h memoryBase.h memoryHook.h memoryHook.I diff --git a/dtool/src/dtoolbase/deletedBufferChain.h b/dtool/src/dtoolbase/deletedBufferChain.h index 28aa036d8a6..11c9eac8c05 100644 --- a/dtool/src/dtoolbase/deletedBufferChain.h +++ b/dtool/src/dtoolbase/deletedBufferChain.h @@ -62,7 +62,7 @@ class EXPCL_DTOOL_DTOOLBASE DeletedBufferChain { INLINE DeletedBufferChain(DeletedBufferChain &&from) noexcept; INLINE DeletedBufferChain(const DeletedBufferChain ©); - void *allocate(size_t size, TypeHandle type_handle); + [[nodiscard]] void *allocate(size_t size, TypeHandle type_handle); void deallocate(void *ptr, TypeHandle type_handle); INLINE bool validate(void *ptr); diff --git a/dtool/src/dtoolbase/deletedChain.h b/dtool/src/dtoolbase/deletedChain.h index f418d4ee596..c6bbe28a396 100644 --- a/dtool/src/dtoolbase/deletedChain.h +++ b/dtool/src/dtoolbase/deletedChain.h @@ -36,7 +36,7 @@ template class DeletedChain { public: - INLINE Type *allocate(size_t size, TypeHandle type_handle); + [[nodiscard]] INLINE Type *allocate(size_t size, TypeHandle type_handle); INLINE void deallocate(Type *ptr, TypeHandle type_handle); INLINE bool validate(const Type *ptr); @@ -65,7 +65,7 @@ class DeletedChain { template class StaticDeletedChain { public: - INLINE static Type *allocate(size_t size, TypeHandle type_handle); + [[nodiscard]] INLINE static Type *allocate(size_t size, TypeHandle type_handle); INLINE static void deallocate(Type *ptr, TypeHandle type_handle); INLINE static bool validate(const Type *ptr); diff --git a/dtool/src/dtoolbase/dtoolbase.h b/dtool/src/dtoolbase/dtoolbase.h index bebb3d665ac..52ad19c5665 100644 --- a/dtool/src/dtoolbase/dtoolbase.h +++ b/dtool/src/dtoolbase/dtoolbase.h @@ -185,9 +185,7 @@ typedef struct _typeobject PyTypeObject; #include #endif // PHAVE_STRING_H -#ifdef PHAVE_STDLIB_H #include -#endif // PHAVE_STDLIB_H #ifdef PHAVE_LIMITS_H #include @@ -197,9 +195,7 @@ typedef struct _typeobject PyTypeObject; #include #endif // PHAVE_SYS_TIME_H -#ifdef PHAVE_STDINT_H #include -#endif // PHAVE_STDINT_H #ifdef CPPPARSER #include diff --git a/dtool/src/dtoolbase/dtoolbase_cc.h b/dtool/src/dtoolbase/dtoolbase_cc.h index ed556881941..78896436cff 100644 --- a/dtool/src/dtoolbase/dtoolbase_cc.h +++ b/dtool/src/dtoolbase/dtoolbase_cc.h @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -56,42 +57,20 @@ typedef int ios_seekdir; #else // CPPPARSER -#ifdef PHAVE_IOSTREAM #include #include #include -#else -#include -#include -#include -#endif - -#ifdef PHAVE_SSTREAM #include -#else -#include "fakestringstream.h" -#endif - -#ifdef PHAVE_NEW #include -#endif - #include +#include #include #include -#ifndef HAVE_IOS_TYPEDEFS -typedef int ios_openmode; -typedef int ios_fmtflags; -typedef int ios_iostate; -// Old iostream libraries used ios::seek_dir instead of ios::seekdir. -typedef ios::seek_dir ios_seekdir; -#else typedef std::ios::openmode ios_openmode; typedef std::ios::fmtflags ios_fmtflags; typedef std::ios::iostate ios_iostate; typedef std::ios::seekdir ios_seekdir; -#endif #ifdef _MSC_VER #define ALWAYS_INLINE __forceinline diff --git a/dtool/src/dtoolbase/fakestringstream.h b/dtool/src/dtoolbase/fakestringstream.h deleted file mode 100644 index da2ba6880f8..00000000000 --- a/dtool/src/dtoolbase/fakestringstream.h +++ /dev/null @@ -1,97 +0,0 @@ -/** - * PANDA 3D SOFTWARE - * Copyright (c) Carnegie Mellon University. All rights reserved. - * - * All use of this software is subject to the terms of the revised BSD - * license. You should have received a copy of this license along - * with this source code in a file named "LICENSE." - * - * @file fakestringstream.h - * @author cary - * @date 1999-02-04 - */ - -#ifndef FAKESTRINGSTREAM_H -#define FAKESTRINGSTREAM_H - -#include -#include -#include - -class fake_istream_buffer { -public: - fake_istream_buffer() { - _len = 0; - _str = ""; - } - fake_istream_buffer(const std::string &source) { - _len = source.length(); - if (_len == 0) { - _str = ""; - } else { - _str = new char[_len]; - memcpy(_str, source.data(), _len); - } - } - ~fake_istream_buffer() { - if (_len != 0) { - delete[] _str; - } - } - - int _len; - char *_str; -}; - -class std::istringstream : public fake_istream_buffer, public istrstream { -public: - std::istringstream(const std::string &input) : - fake_istream_buffer(input), - istrstream(_str, _len) { } -}; - -class std::ostringstream : public ostrstream { -public: - std::string str() { - // We must capture the length before we take the str(). - int length = pcount(); - char *s = ostrstream::str(); - std::string result(s, length); - delete[] s; - return result; - } -}; - -class stringstream : public fake_istream_buffer, public strstream { -public: - stringstream() : strstream() { - _owns_str = true; - } - std::stringstream(const std::string &input) : - fake_istream_buffer(input), - strstream(_str, _len, std::ios::in) - { - _owns_str = false; - } - - // str() doesn't seem to compile cross-platform too reliably--Irix doesn't - // define pcount() for some reason. On the other hand, why are you calling - // str() on a stringstream? Just use an ostringstream. - - /* - string str() { - int length = pcount(); - char *s = strstream::str(); - string result(s, length); - if (_owns_str) { - delete[] s; - } - return result; - } - */ - -private: - bool _owns_str; -}; - -#endif diff --git a/dtool/src/dtoolbase/memoryHook.h b/dtool/src/dtoolbase/memoryHook.h index a6460bca6c0..b953014ad58 100644 --- a/dtool/src/dtoolbase/memoryHook.h +++ b/dtool/src/dtoolbase/memoryHook.h @@ -42,11 +42,11 @@ class EXPCL_DTOOL_DTOOLBASE MemoryHook { MemoryHook(const MemoryHook ©); virtual ~MemoryHook() = default; - virtual void *heap_alloc_single(size_t size); + [[nodiscard]] virtual void *heap_alloc_single(size_t size); virtual void heap_free_single(void *ptr); - virtual void *heap_alloc_array(size_t size); - virtual void *heap_realloc_array(void *ptr, size_t size); + [[nodiscard]] virtual void *heap_alloc_array(size_t size); + [[nodiscard]] virtual void *heap_realloc_array(void *ptr, size_t size); virtual void heap_free_array(void *ptr); INLINE void inc_heap(size_t size); @@ -58,7 +58,7 @@ class EXPCL_DTOOL_DTOOLBASE MemoryHook { return MEMORY_HOOK_ALIGNMENT; } - virtual void *mmap_alloc(size_t size, bool allow_exec); + [[nodiscard]] virtual void *mmap_alloc(size_t size, bool allow_exec); virtual void mmap_free(void *ptr, size_t size); INLINE size_t get_page_size() const; INLINE size_t round_up_to_page_size(size_t size) const; diff --git a/dtool/src/dtoolbase/neverFreeMemory.h b/dtool/src/dtoolbase/neverFreeMemory.h index 118614f4fb9..660e9b05b16 100644 --- a/dtool/src/dtoolbase/neverFreeMemory.h +++ b/dtool/src/dtoolbase/neverFreeMemory.h @@ -35,7 +35,7 @@ class EXPCL_DTOOL_DTOOLBASE NeverFreeMemory { NeverFreeMemory(); public: - INLINE static void *alloc(size_t size); + [[nodiscard]] INLINE static void *alloc(size_t size); PUBLISHED: INLINE static size_t get_total_alloc(); diff --git a/dtool/src/dtoolbase/patomic.I b/dtool/src/dtoolbase/patomic.I index b6798347139..d1395c9e900 100644 --- a/dtool/src/dtoolbase/patomic.I +++ b/dtool/src/dtoolbase/patomic.I @@ -454,12 +454,6 @@ patomic_notify_one(volatile uint32_t *value) { #elif defined(_WIN32) _patomic_wake_one_func((void *)value); #elif defined(__APPLE__) -#ifndef __arm64__ - if (UNLIKELY(__ulock_wake == nullptr || __ulock_wait == nullptr)) { - _patomic_notify_all(value); - return; - } -#endif __ulock_wake(UL_COMPARE_AND_WAIT, (void *)value, 0); #elif defined(HAVE_POSIX_THREADS) _patomic_notify_all(value); @@ -478,12 +472,6 @@ patomic_notify_all(volatile uint32_t *value) { #elif defined(_WIN32) _patomic_wake_all_func((void *)value); #elif defined(__APPLE__) -#ifndef __arm64__ - if (UNLIKELY(__ulock_wake == nullptr || __ulock_wait == nullptr)) { - _patomic_notify_all(value); - return; - } -#endif __ulock_wake(UL_COMPARE_AND_WAIT | ULF_WAKE_ALL, (void *)value, 0); #elif defined(HAVE_POSIX_THREADS) _patomic_notify_all(value); diff --git a/dtool/src/dtoolbase/patomic.cxx b/dtool/src/dtoolbase/patomic.cxx index 26949e564ad..1b939a58c69 100644 --- a/dtool/src/dtoolbase/patomic.cxx +++ b/dtool/src/dtoolbase/patomic.cxx @@ -125,7 +125,7 @@ initialize_wait(volatile VOID *addr, PVOID cmp, SIZE_T size, DWORD timeout) { return emulated_wait(addr, cmp, size, timeout); } -#elif !defined(CPPPARSER) && !defined(__linux__) && (!defined(__APPLE__) || !defined(__arm64__)) && defined(HAVE_POSIX_THREADS) +#elif !defined(CPPPARSER) && !defined(__linux__) && !defined(__APPLE__) && defined(HAVE_POSIX_THREADS) // Same as above, but using pthreads. struct alignas(64) WaitTableEntry { diff --git a/dtool/src/dtoolbase/patomic.h b/dtool/src/dtoolbase/patomic.h index 2b0fdaacc07..470a9d2858d 100644 --- a/dtool/src/dtoolbase/patomic.h +++ b/dtool/src/dtoolbase/patomic.h @@ -170,17 +170,12 @@ ALWAYS_INLINE void patomic_notify_all(volatile uint32_t *value); EXPCL_DTOOL_DTOOLBASE extern BOOL (__stdcall *_patomic_wait_func)(volatile VOID *, PVOID, SIZE_T, DWORD); EXPCL_DTOOL_DTOOLBASE extern void (__stdcall *_patomic_wake_one_func)(PVOID); EXPCL_DTOOL_DTOOLBASE extern void (__stdcall *_patomic_wake_all_func)(PVOID); -#elif defined(__APPLE__) && defined(__arm64__) +#elif defined(__APPLE__) extern "C" int __ulock_wait(uint32_t op, void *addr, uint64_t value, uint32_t timeout); extern "C" int __ulock_wake(uint32_t op, void *addr, uint64_t wake_value); #elif !defined(__linux__) && defined(HAVE_POSIX_THREADS) EXPCL_DTOOL_DTOOLBASE void _patomic_wait(const volatile uint32_t *value, uint32_t old); EXPCL_DTOOL_DTOOLBASE void _patomic_notify_all(volatile uint32_t *value); -#ifdef __APPLE__ -// Use conditionally since we can't count on support before 10.12. -extern "C" int __ulock_wait(uint32_t op, void *addr, uint64_t value, uint32_t timeout) __attribute__((weak_import)); -extern "C" int __ulock_wake(uint32_t op, void *addr, uint64_t wake_value) __attribute__((weak_import)); -#endif #endif #include "patomic.I" diff --git a/dtool/src/dtoolbase/register_type.I b/dtool/src/dtoolbase/register_type.I index f1108fc0ca2..21d191fe595 100644 --- a/dtool/src/dtoolbase/register_type.I +++ b/dtool/src/dtoolbase/register_type.I @@ -19,11 +19,11 @@ * Register() and record_derivation() yourself. */ INLINE void -register_type(TypeHandle &type_handle, const std::string &name) { +register_type(TypeHandle &type_handle, std::string_view name) { TypeRegistry::ptr()->register_type(type_handle, name); } INLINE void -register_type(TypeHandle &type_handle, const std::string &name, +register_type(TypeHandle &type_handle, std::string_view name, TypeHandle parent1) { TypeRegistry *registry = TypeRegistry::ptr(); if (registry->register_type(type_handle, name)) { @@ -31,7 +31,7 @@ register_type(TypeHandle &type_handle, const std::string &name, } } INLINE void -register_type(TypeHandle &type_handle, const std::string &name, +register_type(TypeHandle &type_handle, std::string_view name, TypeHandle parent1, TypeHandle parent2) { TypeRegistry *registry = TypeRegistry::ptr(); if (registry->register_type(type_handle, name)) { @@ -40,7 +40,7 @@ register_type(TypeHandle &type_handle, const std::string &name, } } INLINE void -register_type(TypeHandle &type_handle, const std::string &name, +register_type(TypeHandle &type_handle, std::string_view name, TypeHandle parent1, TypeHandle parent2, TypeHandle parent3) { TypeRegistry *registry = TypeRegistry::ptr(); @@ -51,7 +51,7 @@ register_type(TypeHandle &type_handle, const std::string &name, } } INLINE void -register_type(TypeHandle &type_handle, const std::string &name, +register_type(TypeHandle &type_handle, std::string_view name, TypeHandle parent1, TypeHandle parent2, TypeHandle parent3, TypeHandle parent4) { TypeRegistry *registry = TypeRegistry::ptr(); @@ -70,18 +70,18 @@ register_type(TypeHandle &type_handle, const std::string &name, * reference. */ INLINE TypeHandle -register_dynamic_type(const std::string &name) { +register_dynamic_type(std::string_view name) { return TypeRegistry::ptr()->register_dynamic_type(name); } INLINE TypeHandle -register_dynamic_type(const std::string &name, TypeHandle parent1) { +register_dynamic_type(std::string_view name, TypeHandle parent1) { TypeRegistry *registry = TypeRegistry::ptr(); TypeHandle type_handle = registry->register_dynamic_type(name); registry->record_derivation(type_handle, parent1); return type_handle; } INLINE TypeHandle -register_dynamic_type(const std::string &name, +register_dynamic_type(std::string_view name, TypeHandle parent1, TypeHandle parent2) { TypeRegistry *registry = TypeRegistry::ptr(); TypeHandle type_handle = registry->register_dynamic_type(name); @@ -90,7 +90,7 @@ register_dynamic_type(const std::string &name, return type_handle; } INLINE TypeHandle -register_dynamic_type(const std::string &name, +register_dynamic_type(std::string_view name, TypeHandle parent1, TypeHandle parent2, TypeHandle parent3) { TypeRegistry *registry = TypeRegistry::ptr(); @@ -101,7 +101,7 @@ register_dynamic_type(const std::string &name, return type_handle; } INLINE TypeHandle -register_dynamic_type(const std::string &name, +register_dynamic_type(std::string_view name, TypeHandle parent1, TypeHandle parent2, TypeHandle parent3, TypeHandle parent4) { TypeRegistry *registry = TypeRegistry::ptr(); diff --git a/dtool/src/dtoolbase/register_type.h b/dtool/src/dtoolbase/register_type.h index 95b2c485489..cee579e717f 100644 --- a/dtool/src/dtoolbase/register_type.h +++ b/dtool/src/dtoolbase/register_type.h @@ -30,23 +30,23 @@ class pvector; * Register() and record_derivation() yourself. */ INLINE void -register_type(TypeHandle &type_handle, const std::string &name); +register_type(TypeHandle &type_handle, std::string_view name); INLINE void -register_type(TypeHandle &type_handle, const std::string &name, +register_type(TypeHandle &type_handle, std::string_view name, TypeHandle parent1); INLINE void -register_type(TypeHandle &type_handle, const std::string &name, +register_type(TypeHandle &type_handle, std::string_view name, TypeHandle parent1, TypeHandle parent2); INLINE void -register_type(TypeHandle &type_handle, const std::string &name, +register_type(TypeHandle &type_handle, std::string_view name, TypeHandle parent1, TypeHandle parent2, TypeHandle parent3); INLINE void -register_type(TypeHandle &type_handle, const std::string &name, +register_type(TypeHandle &type_handle, std::string_view name, TypeHandle parent1, TypeHandle parent2, TypeHandle parent3, TypeHandle parent4); @@ -58,22 +58,22 @@ register_type(TypeHandle &type_handle, const std::string &name, * reference. */ INLINE TypeHandle -register_dynamic_type(const std::string &name); +register_dynamic_type(std::string_view name); INLINE TypeHandle -register_dynamic_type(const std::string &name, TypeHandle parent1); +register_dynamic_type(std::string_view name, TypeHandle parent1); INLINE TypeHandle -register_dynamic_type(const std::string &name, +register_dynamic_type(std::string_view name, TypeHandle parent1, TypeHandle parent2); INLINE TypeHandle -register_dynamic_type(const std::string &name, +register_dynamic_type(std::string_view name, TypeHandle parent1, TypeHandle parent2, TypeHandle parent3); INLINE TypeHandle -register_dynamic_type(const std::string &name, +register_dynamic_type(std::string_view name, TypeHandle parent1, TypeHandle parent2, TypeHandle parent3, TypeHandle parent4); diff --git a/dtool/src/dtoolbase/staticObject.h b/dtool/src/dtoolbase/staticObject.h index a350da181ad..870e8dab901 100644 --- a/dtool/src/dtoolbase/staticObject.h +++ b/dtool/src/dtoolbase/staticObject.h @@ -37,11 +37,11 @@ class StaticObject { } operator T *() { - return (T *)_storage; + return std::launder(reinterpret_cast(_storage)); } T *operator ->() { - return (T *)_storage; + return std::launder(reinterpret_cast(_storage)); } private: diff --git a/dtool/src/dtoolbase/stl_compares.h b/dtool/src/dtoolbase/stl_compares.h index 946eab9b649..841f56b6779 100644 --- a/dtool/src/dtoolbase/stl_compares.h +++ b/dtool/src/dtoolbase/stl_compares.h @@ -150,13 +150,19 @@ class floating_point_hash : public stl_hash_compare { * This hash_compare class hashes a string. It assumes the Key is a string or * provides begin() and end() methods that iterate through Key::value_type. */ -template > +template > class sequence_hash : public stl_hash_compare { public: + using is_transparent = void; // Enables map.find(string_view) etc. + INLINE size_t operator () (const Key &key) const; INLINE bool operator () (const Key &a, const Key &b) const { return stl_hash_compare::operator () (a, b); } + template + INLINE bool operator () (const A &a, const B &b) const { + return Compare{}(a, b); + } INLINE static size_t add_hash(size_t start, const Key &key); }; diff --git a/dtool/src/dtoolbase/typeRegistry.cxx b/dtool/src/dtoolbase/typeRegistry.cxx index dc60264f379..4dbd7799a7d 100644 --- a/dtool/src/dtoolbase/typeRegistry.cxx +++ b/dtool/src/dtoolbase/typeRegistry.cxx @@ -36,7 +36,7 @@ TypeRegistry *TypeRegistry::_global_pointer = nullptr; * defined before, false if it was. */ bool TypeRegistry:: -register_type(TypeHandle &type_handle, const string &name) { +register_type(TypeHandle &type_handle, std::string_view name) { _lock.lock(); if (type_handle != TypeHandle::none()) { @@ -61,9 +61,9 @@ register_type(TypeHandle &type_handle, const string &name) { TypeHandle new_handle; new_handle._index = (int)_handle_registry.size(); - TypeRegistryNode *rnode = new TypeRegistryNode(new_handle, name, type_handle); + TypeRegistryNode *rnode = new TypeRegistryNode(new_handle, std::string(name), type_handle); _handle_registry.push_back(rnode); - _name_registry[name] = rnode; + _name_registry[rnode->_name] = rnode; _derivations_fresh = false; type_handle = new_handle; @@ -118,7 +118,7 @@ register_type(TypeHandle &type_handle, const string &name) { * TypeHandle that was last used for this typename is returned. */ TypeHandle TypeRegistry:: -register_dynamic_type(const string &name) { +register_dynamic_type(std::string_view name) { _lock.lock(); NameRegistry::iterator ri; @@ -134,9 +134,9 @@ register_dynamic_type(const string &name) { TypeHandle *new_handle = new TypeHandle; new_handle->_index = (int)_handle_registry.size(); - TypeRegistryNode *rnode = new TypeRegistryNode(*new_handle, name, *new_handle); + TypeRegistryNode *rnode = new TypeRegistryNode(*new_handle, std::string(name), *new_handle); _handle_registry.push_back(rnode); - _name_registry[name] = rnode; + _name_registry[rnode->_name] = rnode; _derivations_fresh = false; _lock.unlock(); @@ -186,13 +186,13 @@ record_derivation(TypeHandle child, TypeHandle parent) { * correctly read from old Bam files. */ void TypeRegistry:: -record_alternate_name(TypeHandle type, const string &name) { +record_alternate_name(TypeHandle type, std::string_view name) { _lock.lock(); TypeRegistryNode *rnode = look_up(type, nullptr); if (rnode != nullptr) { NameRegistry::iterator ri = - _name_registry.insert(NameRegistry::value_type(name, rnode)).first; + _name_registry.insert(NameRegistry::value_type(std::string(name), rnode)).first; if ((*ri).second != rnode) { _lock.unlock(); @@ -231,7 +231,7 @@ record_python_type(TypeHandle type, PyTypeObject *cls, PythonWrapFunc *wrap_func * TypeHandle if it exists, or TypeHandle::none() if there is no such type. */ TypeHandle TypeRegistry:: -find_type(const string &name) const { +find_type(std::string_view name) const { _lock.lock(); TypeHandle handle = TypeHandle::none(); diff --git a/dtool/src/dtoolbase/typeRegistry.h b/dtool/src/dtoolbase/typeRegistry.h index bc506eaad60..d0bd06ce63f 100644 --- a/dtool/src/dtoolbase/typeRegistry.h +++ b/dtool/src/dtoolbase/typeRegistry.h @@ -38,23 +38,23 @@ class EXPCL_DTOOL_DTOOLBASE TypeRegistry : public MemoryBase { // User code shouldn't generally need to call TypeRegistry::register_type() // or record_derivation() directly; instead, use the register_type // convenience function, defined in register_type.h. - bool register_type(TypeHandle &type_handle, const std::string &name); + bool register_type(TypeHandle &type_handle, std::string_view name); #ifdef HAVE_PYTHON typedef PyObject *PythonWrapFunc(void *ptr, PyTypeObject *cast_from); #endif PUBLISHED: - TypeHandle register_dynamic_type(const std::string &name); + TypeHandle register_dynamic_type(std::string_view name); void record_derivation(TypeHandle child, TypeHandle parent); - void record_alternate_name(TypeHandle type, const std::string &name); + void record_alternate_name(TypeHandle type, std::string_view name); #ifdef HAVE_PYTHON void record_python_type(TypeHandle type, PyTypeObject *cls, PythonWrapFunc *wrap_func); #endif - TypeHandle find_type(const std::string &name) const; + TypeHandle find_type(std::string_view name) const; TypeHandle find_type_by_id(int id) const; std::string get_name(TypeHandle type, TypedObject *object) const; @@ -109,7 +109,7 @@ class EXPCL_DTOOL_DTOOLBASE TypeRegistry : public MemoryBase { typedef std::vector HandleRegistry; HandleRegistry _handle_registry; - typedef std::map NameRegistry; + typedef std::map > NameRegistry; NameRegistry _name_registry; typedef std::vector RootClasses; diff --git a/dtool/src/dtoolbase/typeRegistryNode.cxx b/dtool/src/dtoolbase/typeRegistryNode.cxx index 0aabc97de12..1b7db2c66b0 100644 --- a/dtool/src/dtoolbase/typeRegistryNode.cxx +++ b/dtool/src/dtoolbase/typeRegistryNode.cxx @@ -22,8 +22,8 @@ bool TypeRegistryNode::_paranoid_inheritance = false; * */ TypeRegistryNode:: -TypeRegistryNode(TypeHandle handle, const std::string &name, TypeHandle &ref) : - _handle(handle), _name(name), _ref(ref), _memory_usage{} +TypeRegistryNode(TypeHandle handle, std::string name, TypeHandle &ref) : + _handle(handle), _name(std::move(name)), _ref(ref), _memory_usage{} { clear_subtree(); } diff --git a/dtool/src/dtoolbase/typeRegistryNode.h b/dtool/src/dtoolbase/typeRegistryNode.h index 6a6e0833a4b..16938f9cfeb 100644 --- a/dtool/src/dtoolbase/typeRegistryNode.h +++ b/dtool/src/dtoolbase/typeRegistryNode.h @@ -32,7 +32,7 @@ class EXPCL_DTOOL_DTOOLBASE TypeRegistryNode { public: typedef PyObject *PythonWrapFunc(void *ptr, PyTypeObject *cast_from); - TypeRegistryNode(TypeHandle handle, const std::string &name, TypeHandle &ref); + TypeRegistryNode(TypeHandle handle, std::string name, TypeHandle &ref); static bool is_derived_from(const TypeRegistryNode *child, const TypeRegistryNode *base); diff --git a/dtool/src/dtoolutil/dSearchPath.I b/dtool/src/dtoolutil/dSearchPath.I index 66055a74667..73b86ca6369 100644 --- a/dtool/src/dtoolutil/dSearchPath.I +++ b/dtool/src/dtoolutil/dSearchPath.I @@ -48,8 +48,8 @@ find_all_files(const Filename &filename) const { * searches that. */ INLINE Filename DSearchPath:: -search_path(const Filename &filename, const std::string &path, - const std::string &separator) { +search_path(const Filename &filename, std::string_view path, + std::string_view separator) { DSearchPath search(path, separator); return search.find_file(filename); } diff --git a/dtool/src/dtoolutil/dSearchPath.cxx b/dtool/src/dtoolutil/dSearchPath.cxx index b8c388c804e..1d6bcce780d 100644 --- a/dtool/src/dtoolutil/dSearchPath.cxx +++ b/dtool/src/dtoolutil/dSearchPath.cxx @@ -120,7 +120,7 @@ write(ostream &out, int indent_level) const { * */ DSearchPath:: -DSearchPath(const string &path, const string &separator) { +DSearchPath(std::string_view path, std::string_view separator) { append_path(path, separator); } @@ -161,8 +161,8 @@ prepend_directory(const Filename &directory) { * search list. */ void DSearchPath:: -append_path(const string &path, const string &separator) { - string pathsep = separator; +append_path(std::string_view path, std::string_view separator) { + string pathsep(separator); if (pathsep.empty()) { pathsep = DEFAULT_PATHSEP; } @@ -324,12 +324,12 @@ find_all_files(const Filename &filename, * */ void DSearchPath:: -output(ostream &out, const string &separator) const { - string pathsep = separator; +output(ostream &out, std::string_view separator) const { + std::string_view pathsep(separator); if (pathsep.empty()) { pathsep = DEFAULT_PATHSEP; if (!pathsep.empty()) { - pathsep = pathsep[0]; + pathsep = pathsep.substr(0, 1); } } diff --git a/dtool/src/dtoolutil/dSearchPath.h b/dtool/src/dtoolutil/dSearchPath.h index 7fcd56a2489..095fccacdec 100644 --- a/dtool/src/dtoolutil/dSearchPath.h +++ b/dtool/src/dtoolutil/dSearchPath.h @@ -53,7 +53,7 @@ class EXPCL_DTOOL_DTOOLUTIL DSearchPath { }; DSearchPath() = default; - explicit DSearchPath(const std::string &path, const std::string &separator = std::string()); + explicit DSearchPath(std::string_view path, std::string_view separator = std::string_view()); explicit DSearchPath(const Filename &directory); DSearchPath(const DSearchPath ©) = default; DSearchPath(DSearchPath &&from) = default; @@ -65,8 +65,8 @@ class EXPCL_DTOOL_DTOOLUTIL DSearchPath { void clear(); void append_directory(const Filename &directory); void prepend_directory(const Filename &directory); - void append_path(const std::string &path, - const std::string &separator = std::string()); + void append_path(std::string_view path, + std::string_view separator = std::string_view()); void append_path(const DSearchPath &path); void prepend_path(const DSearchPath &path); @@ -81,10 +81,10 @@ class EXPCL_DTOOL_DTOOLUTIL DSearchPath { INLINE Results find_all_files(const Filename &filename) const; INLINE static Filename - search_path(const Filename &filename, const std::string &path, - const std::string &separator = std::string()); + search_path(const Filename &filename, std::string_view path, + std::string_view separator = std::string_view()); - void output(std::ostream &out, const std::string &separator = std::string()) const; + void output(std::ostream &out, std::string_view separator = std::string_view()) const; void write(std::ostream &out, int indent_level = 0) const; private: diff --git a/dtool/src/dtoolutil/executionEnvironment.I b/dtool/src/dtoolutil/executionEnvironment.I index 4639ab0a365..5fb40c23a78 100644 --- a/dtool/src/dtoolutil/executionEnvironment.I +++ b/dtool/src/dtoolutil/executionEnvironment.I @@ -97,14 +97,14 @@ get_dtool_name() { * Do not use. */ INLINE void ExecutionEnvironment:: -set_binary_name(const std::string &name) { - get_ptr()->_binary_name = name; +set_binary_name(std::string name) { + get_ptr()->_binary_name = std::move(name); } /** * Do not use. */ INLINE void ExecutionEnvironment:: -set_dtool_name(const std::string &name) { - get_ptr()->_dtool_name = name; +set_dtool_name(std::string name) { + get_ptr()->_dtool_name = std::move(name); } diff --git a/dtool/src/dtoolutil/executionEnvironment.cxx b/dtool/src/dtoolutil/executionEnvironment.cxx index 371a2116128..1df2f92f8c1 100644 --- a/dtool/src/dtoolutil/executionEnvironment.cxx +++ b/dtool/src/dtoolutil/executionEnvironment.cxx @@ -160,7 +160,7 @@ ExecutionEnvironment() { * Returns the expanded string. */ string ExecutionEnvironment:: -expand_string(const string &str) { +expand_string(std::string_view str) { string result; size_t last = 0; diff --git a/dtool/src/dtoolutil/executionEnvironment.h b/dtool/src/dtoolutil/executionEnvironment.h index ddb83fcecc5..a1f956b182e 100644 --- a/dtool/src/dtoolutil/executionEnvironment.h +++ b/dtool/src/dtoolutil/executionEnvironment.h @@ -45,7 +45,7 @@ class EXPCL_DTOOL_DTOOLUTIL ExecutionEnvironment { INLINE static void shadow_environment_variable(const std::string &var, const std::string &value); INLINE static void clear_shadow(const std::string &var); - static std::string expand_string(const std::string &str); + static std::string expand_string(std::string_view str); INLINE static size_t get_num_args(); INLINE static std::string get_arg(size_t n); @@ -53,8 +53,8 @@ class EXPCL_DTOOL_DTOOLUTIL ExecutionEnvironment { INLINE static std::string get_binary_name(); INLINE static std::string get_dtool_name(); - INLINE static void set_binary_name(const std::string &name); - INLINE static void set_dtool_name(const std::string &name); + INLINE static void set_binary_name(std::string name); + INLINE static void set_dtool_name(std::string name); static Filename get_cwd(); diff --git a/dtool/src/dtoolutil/filename.I b/dtool/src/dtoolutil/filename.I index c7776673519..8cc06ca9c98 100644 --- a/dtool/src/dtoolutil/filename.I +++ b/dtool/src/dtoolutil/filename.I @@ -29,6 +29,24 @@ Filename(const std::wstring &filename) { (*this) = filename; } +/** + * + */ +INLINE Filename:: +Filename(std::string_view filename) { + _flags = 0; + (*this) = filename; +} + +/** + * + */ +INLINE Filename:: +Filename(std::wstring_view filename) { + _flags = 0; + (*this) = filename; +} + /** * */ @@ -96,78 +114,79 @@ Filename() : * */ INLINE Filename Filename:: -text_filename(const Filename &filename) { - Filename result(filename); - result.set_text(); - return result; +text_filename(Filename filename) { + filename.set_text(); + return filename; } /** * */ INLINE Filename Filename:: -text_filename(const std::string &filename) { - Filename result(filename); - result.set_text(); - return result; +binary_filename(Filename filename) { + filename.set_binary(); + return filename; } /** * */ INLINE Filename Filename:: -binary_filename(const Filename &filename) { - Filename result(filename); - result.set_binary(); - return result; +dso_filename(Filename filename) { + filename.set_type(T_dso); + return filename; } /** * */ INLINE Filename Filename:: -binary_filename(const std::string &filename) { - Filename result(filename); - result.set_binary(); - return result; +executable_filename(Filename filename) { + filename.set_type(T_executable); + return filename; } /** - * + * Constructs a filename that represents a sequence of numbered files. See + * set_pattern(). */ INLINE Filename Filename:: -dso_filename(const std::string &filename) { +pattern_filename(std::string_view filename) { Filename result(filename); - result.set_type(T_dso); + result.set_pattern(true); return result; } /** * */ -INLINE Filename Filename:: -executable_filename(const std::string &filename) { - Filename result(filename); - result.set_type(T_executable); - return result; +INLINE Filename &Filename:: +operator = (const char *filename) { + assert(filename != nullptr); + return operator = (std::string_view(filename)); } /** - * Constructs a filename that represents a sequence of numbered files. See - * set_pattern(). + * */ -INLINE Filename Filename:: -pattern_filename(const std::string &filename) { - Filename result(filename); - result.set_pattern(true); - return result; +INLINE Filename &Filename:: +operator = (const std::string &filename) { + return operator = (std::string_view(filename)); } /** * */ INLINE Filename &Filename:: -operator = (const std::string &filename) { +operator = (const std::wstring &filename) { + return operator = (std::wstring_view(filename)); +} + +/** + * + */ +INLINE Filename &Filename:: +operator = (std::string_view filename) { _filename = filename; locate_basename(); @@ -180,22 +199,13 @@ operator = (const std::string &filename) { * */ INLINE Filename &Filename:: -operator = (const std::wstring &filename) { +operator = (std::wstring_view filename) { TextEncoder encoder; encoder.set_encoding(get_filesystem_encoding()); encoder.set_wtext(filename); return operator = (encoder.get_text()); } -/** - * - */ -INLINE Filename &Filename:: -operator = (const char *filename) { - assert(filename != nullptr); - return (*this) = std::string(filename); -} - /** * */ @@ -249,6 +259,14 @@ operator const std::string & () const { return _filename; } +/** + * + */ +INLINE Filename:: +operator std::string_view () const { + return _filename; +} + /** * */ @@ -304,7 +322,7 @@ substr(size_t begin, size_t end) const { * two parameters. */ INLINE void Filename:: -operator += (const std::string &other) { +operator += (std::string_view other) { _filename += other; locate_basename(); locate_extension(); @@ -315,7 +333,7 @@ operator += (const std::string &other) { * Returns a new Filename representing the concatenation of the two filenames. */ INLINE Filename Filename:: -operator + (const std::string &other) const { +operator + (std::string_view other) const { Filename a(*this); a += other; return a; @@ -569,7 +587,7 @@ is_fully_qualified() const { * */ INLINE bool Filename:: -operator == (const std::string &other) const { +operator == (std::string_view other) const { return (*(std::string *)this) == other; } @@ -577,7 +595,7 @@ operator == (const std::string &other) const { * */ INLINE bool Filename:: -operator != (const std::string &other) const { +operator != (std::string_view other) const { return (*(std::string *)this) != other; } @@ -585,7 +603,7 @@ operator != (const std::string &other) const { * */ INLINE bool Filename:: -operator < (const std::string &other) const { +operator < (std::string_view other) const { return (*(std::string *)this) < other; } diff --git a/dtool/src/dtoolutil/filename.cxx b/dtool/src/dtoolutil/filename.cxx index 6eb4ee45bfb..0ef75e3bd69 100644 --- a/dtool/src/dtoolutil/filename.cxx +++ b/dtool/src/dtoolutil/filename.cxx @@ -123,8 +123,8 @@ static const char *hosts_prefix = "/hosts/"; static size_t hosts_prefix_length = 7; static string -front_to_back_slash(const string &str) { - string result = str; +front_to_back_slash(std::string_view str) { + string result(str); string::iterator si; for (si = result.begin(); si != result.end(); ++si) { if ((*si) == '/') { @@ -136,8 +136,8 @@ front_to_back_slash(const string &str) { } static string -back_to_front_slash(const string &str) { - string result = str; +back_to_front_slash(std::string_view str) { + string result(str); string::iterator si; for (si = result.begin(); si != result.end(); ++si) { if ((*si) == '\\') { @@ -337,7 +337,7 @@ Filename(const Filename &dirname, const Filename &basename) { * and some forward slashes. */ Filename Filename:: -from_os_specific(const string &os_specific, Filename::Type type) { +from_os_specific(std::string_view os_specific, Filename::Type type) { #ifdef _WIN32 string result = back_to_front_slash(os_specific); const string &panda_root = get_panda_root(); @@ -403,7 +403,7 @@ from_os_specific(const string &os_specific, Filename::Type type) { * converted from an os-specific wide-character string. */ Filename Filename:: -from_os_specific_w(const wstring &os_specific, Filename::Type type) { +from_os_specific_w(std::wstring_view os_specific, Filename::Type type) { TextEncoder encoder; encoder.set_encoding(get_filesystem_encoding()); encoder.set_wtext(os_specific); @@ -416,7 +416,7 @@ from_os_specific_w(const wstring &os_specific, Filename::Type type) { * automatically elevates the file to its true case if needed. */ Filename Filename:: -expand_from(const string &os_specific, Filename::Type type) { +expand_from(std::string_view os_specific, Filename::Type type) { Filename file = from_os_specific(ExecutionEnvironment::expand_string(os_specific), type); file.make_true_case(); @@ -433,7 +433,7 @@ expand_from(const string &os_specific, Filename::Type type) { * process could simultaneously create a file by the same name. */ Filename Filename:: -temporary(const string &dirname, const string &prefix, const string &suffix, +temporary(std::string_view dirname, const string &prefix, const string &suffix, Type type) { Filename fdirname = dirname; #if defined(_WIN32) || defined(ANDROID) || defined(__wasi__) @@ -722,7 +722,7 @@ get_common_appdata_directory() { * also be achieved with the assignment operator. */ void Filename:: -set_fullpath(const string &s) { +set_fullpath(std::string_view s) { (*this) = s; } @@ -731,7 +731,7 @@ set_fullpath(const string &s) { * filename up to, but not including the rightmost slash. */ void Filename:: -set_dirname(const string &s) { +set_dirname(std::string_view s) { if (s.empty()) { // Remove the directory prefix altogether. _filename.replace(0, _basename_start, ""); @@ -747,11 +747,9 @@ set_dirname(const string &s) { // Replace the existing directory prefix, or insert a new one. // We build the string ss to include the terminal slash. - string ss; - if (s[s.length()-1] == '/') { - ss = s; - } else { - ss = s+'/'; + string ss(s); + if (ss.back() != '/') { + ss += '/'; } int length_change = (int)ss.length() - (int)_basename_start; @@ -781,19 +779,18 @@ set_dirname(const string &s) { * filename after the rightmost slash, including any extensions. */ void Filename:: -set_basename(const string &s) { +set_basename(std::string_view s) { _filename.replace(_basename_start, string::npos, s); locate_extension(); locate_hash(); } - /** * Replaces the full filename--directory and basename parts--except for the * extension. */ void Filename:: -set_fullpath_wo_extension(const string &s) { +set_fullpath_wo_extension(std::string_view s) { int length_change = (int)s.length() - (int)_basename_end; _filename.replace(0, _basename_end, s); @@ -805,12 +802,11 @@ set_fullpath_wo_extension(const string &s) { locate_hash(); } - /** * Replaces the basename part of the filename, without the file extension. */ void Filename:: -set_basename_wo_extension(const string &s) { +set_basename_wo_extension(std::string_view s) { int length_change = (int)s.length() - (int)(_basename_end - _basename_start); if (_basename_end == string::npos) { @@ -825,13 +821,12 @@ set_basename_wo_extension(const string &s) { locate_hash(); } - /** * Replaces the file extension. This is everything after the rightmost dot, * if there is one, or the empty string if there is not. */ void Filename:: -set_extension(const string &s) { +set_extension(std::string_view s) { if (s.empty()) { // Remove the extension altogether. if (_basename_end != string::npos) { @@ -844,7 +839,8 @@ set_extension(const string &s) { // Insert an extension where there was none before. _basename_end = _filename.length(); _extension_start = _filename.length() + 1; - _filename += '.' + s; + _filename += '.'; + _filename += s; } else { // Replace an existing extension. @@ -883,7 +879,7 @@ get_filename_index(int index) const { * to the end of the filename. */ void Filename:: -set_hash_to_end(const string &s) { +set_hash_to_end(std::string_view s) { _filename.replace(_hash_start, string::npos, s); locate_basename(); @@ -1618,7 +1614,7 @@ get_file_size() const { */ bool Filename:: resolve_filename(const DSearchPath &searchpath, - const string &default_extension) { + std::string_view default_extension) { Filename found; if (is_local()) { @@ -2681,8 +2677,8 @@ get_hash() const { */ bool Filename:: atomic_compare_and_exchange_contents(string &orig_contents, - const string &old_contents, - const string &new_contents) const { + std::string_view old_contents, + std::string_view new_contents) const { #ifdef _WIN32 wstring os_specific = to_os_specific_w(); HANDLE hfile = CreateFileW(os_specific.c_str(), GENERIC_READ | GENERIC_WRITE, @@ -3039,7 +3035,7 @@ locate_hash() { * common to both filenames. */ size_t Filename:: -get_common_prefix(const string &other) const { +get_common_prefix(std::string_view other) const { size_t len = 0; // First, get the length of the common initial substring. @@ -3061,9 +3057,9 @@ get_common_prefix(const string &other) const { * counting a terminal slash. */ int Filename:: -count_slashes(const string &str) { +count_slashes(std::string_view str) { int count = 0; - string::const_iterator si; + std::string_view::const_iterator si; si = str.begin(); while (si != str.end()) { diff --git a/dtool/src/dtoolutil/filename.h b/dtool/src/dtoolutil/filename.h index f28f08753c8..315309a99dc 100644 --- a/dtool/src/dtoolutil/filename.h +++ b/dtool/src/dtoolutil/filename.h @@ -63,6 +63,8 @@ class EXPCL_DTOOL_DTOOLUTIL Filename { INLINE Filename(const char *filename); INLINE Filename(const std::string &filename); INLINE Filename(const std::wstring &filename); + INLINE Filename(std::string_view filename); + INLINE Filename(std::wstring_view filename); INLINE Filename(const Filename ©); INLINE Filename(std::string &&filename) noexcept; INLINE Filename(Filename &&from) noexcept; @@ -78,22 +80,20 @@ class EXPCL_DTOOL_DTOOLUTIL Filename { // Static constructors to explicitly create a filename that refers to a text // or binary file. This is in lieu of calling set_text() or set_binary() or // set_type(). - INLINE static Filename text_filename(const Filename &filename); - INLINE static Filename text_filename(const std::string &filename); - INLINE static Filename binary_filename(const Filename &filename); - INLINE static Filename binary_filename(const std::string &filename); - INLINE static Filename dso_filename(const std::string &filename); - INLINE static Filename executable_filename(const std::string &filename); + INLINE static Filename text_filename(Filename filename); + INLINE static Filename binary_filename(Filename filename); + INLINE static Filename dso_filename(Filename filename); + INLINE static Filename executable_filename(Filename filename); - INLINE static Filename pattern_filename(const std::string &filename); + INLINE static Filename pattern_filename(std::string_view filename); - static Filename from_os_specific(const std::string &os_specific, + static Filename from_os_specific(std::string_view os_specific, Type type = T_general); - static Filename from_os_specific_w(const std::wstring &os_specific, + static Filename from_os_specific_w(std::wstring_view os_specific, Type type = T_general); - static Filename expand_from(const std::string &user_string, + static Filename expand_from(std::string_view user_string, Type type = T_general); - static Filename temporary(const std::string &dirname, const std::string &prefix, + static Filename temporary(std::string_view dirname, const std::string &prefix, const std::string &suffix = std::string(), Type type = T_general); @@ -103,15 +103,21 @@ class EXPCL_DTOOL_DTOOLUTIL Filename { static const Filename &get_common_appdata_directory(); // Assignment is via the = operator. +public: + INLINE Filename &operator = (const char *filename); INLINE Filename &operator = (const std::string &filename); INLINE Filename &operator = (const std::wstring &filename); - INLINE Filename &operator = (const char *filename); + +PUBLISHED: + INLINE Filename &operator = (std::string_view filename); + INLINE Filename &operator = (std::wstring_view filename); INLINE Filename &operator = (const Filename ©); INLINE Filename &operator = (std::string &&filename) noexcept; INLINE Filename &operator = (Filename &&from) noexcept; // And retrieval is by any of the classic string operations. INLINE operator const std::string & () const; + INLINE operator std::string_view () const; INLINE const char *c_str() const; INLINE bool empty() const; INLINE size_t length() const; @@ -122,8 +128,8 @@ class EXPCL_DTOOL_DTOOLUTIL Filename { INLINE std::string substr(size_t begin) const; INLINE std::string substr(size_t begin, size_t end) const; - INLINE void operator += (const std::string &other); - INLINE Filename operator + (const std::string &other) const; + INLINE void operator += (std::string_view other); + INLINE Filename operator + (std::string_view other) const; INLINE Filename operator / (const Filename &other) const; @@ -137,12 +143,12 @@ class EXPCL_DTOOL_DTOOLUTIL Filename { INLINE std::string get_extension() const; // You can also use any of these to reassign pieces of the filename. - void set_fullpath(const std::string &s); - void set_dirname(const std::string &s); - void set_basename(const std::string &s); - void set_fullpath_wo_extension(const std::string &s); - void set_basename_wo_extension(const std::string &s); - void set_extension(const std::string &s); + void set_fullpath(std::string_view s); + void set_dirname(std::string_view s); + void set_basename(std::string_view s); + void set_fullpath_wo_extension(std::string_view s); + void set_basename_wo_extension(std::string_view s); + void set_extension(std::string_view s); // Setting these flags appropriately is helpful when opening or searching // for a file; it helps the Filename resolve OS-specific conventions (for @@ -164,7 +170,7 @@ class EXPCL_DTOOL_DTOOLUTIL Filename { Filename get_filename_index(int index) const; INLINE std::string get_hash_to_end() const; - void set_hash_to_end(const std::string &s); + void set_hash_to_end(std::string_view s); void extract_components(vector_string &components) const; void standardize(); @@ -198,7 +204,7 @@ class EXPCL_DTOOL_DTOOLUTIL Filename { std::streamsize get_file_size() const; bool resolve_filename(const DSearchPath &searchpath, - const std::string &default_extension = std::string()); + std::string_view default_extension = std::string_view()); bool make_relative_to(Filename directory, bool allow_backups = true); int find_on_searchpath(const DSearchPath &searchpath); @@ -230,9 +236,9 @@ class EXPCL_DTOOL_DTOOLUTIL Filename { bool rmdir() const; // Comparison operators are handy. - INLINE bool operator == (const std::string &other) const; - INLINE bool operator != (const std::string &other) const; - INLINE bool operator < (const std::string &other) const; + INLINE bool operator == (std::string_view other) const; + INLINE bool operator != (std::string_view other) const; + INLINE bool operator < (std::string_view other) const; INLINE int compare_to(const Filename &other) const; INLINE bool __bool__() const; int get_hash() const; @@ -243,15 +249,15 @@ class EXPCL_DTOOL_DTOOLUTIL Filename { INLINE static TextEncoder::Encoding get_filesystem_encoding(); public: - bool atomic_compare_and_exchange_contents(std::string &orig_contents, const std::string &old_contents, const std::string &new_contents) const; + bool atomic_compare_and_exchange_contents(std::string &orig_contents, std::string_view old_contents, std::string_view new_contents) const; bool atomic_read_contents(std::string &contents) const; protected: void locate_basename(); void locate_extension(); void locate_hash(); - size_t get_common_prefix(const std::string &other) const; - static int count_slashes(const std::string &str); + size_t get_common_prefix(std::string_view other) const; + static int count_slashes(std::string_view str); bool r_make_canonical(const Filename &cwd); std::string _filename; diff --git a/dtool/src/dtoolutil/globPattern.I b/dtool/src/dtoolutil/globPattern.I index f0ab3a6c0e1..1723c9c8d2e 100644 --- a/dtool/src/dtoolutil/globPattern.I +++ b/dtool/src/dtoolutil/globPattern.I @@ -15,7 +15,7 @@ * */ INLINE GlobPattern:: -GlobPattern(const std::string &pattern) : _pattern(pattern) { +GlobPattern(std::string pattern) : _pattern(std::move(pattern)) { _case_sensitive = true; } @@ -69,8 +69,8 @@ operator < (const GlobPattern &other) const { * Changes the pattern string that the GlobPattern object matches. */ INLINE void GlobPattern:: -set_pattern(const std::string &pattern) { - _pattern = pattern; +set_pattern(std::string pattern) { + _pattern = std::move(pattern); } /** @@ -103,8 +103,8 @@ get_case_sensitive() const { * Specifies a set of characters that are not matched by * or ?. */ INLINE void GlobPattern:: -set_nomatch_chars(const std::string &nomatch_chars) { - _nomatch_chars = nomatch_chars; +set_nomatch_chars(std::string nomatch_chars) { + _nomatch_chars = std::move(nomatch_chars); } /** @@ -119,9 +119,9 @@ get_nomatch_chars() const { * Returns true if the candidate string matches the pattern, false otherwise. */ INLINE bool GlobPattern:: -matches(const std::string &candidate) const { - return matches_substr(_pattern.begin(), _pattern.end(), - candidate.begin(), candidate.end()); +matches(std::string_view candidate) const { + return matches_substr(_pattern.data(), _pattern.data() + _pattern.length(), + candidate.data(), candidate.data() + candidate.length()); } /** diff --git a/dtool/src/dtoolutil/globPattern.cxx b/dtool/src/dtoolutil/globPattern.cxx index d2ea9164668..e32c1e9c215 100644 --- a/dtool/src/dtoolutil/globPattern.cxx +++ b/dtool/src/dtoolutil/globPattern.cxx @@ -352,8 +352,8 @@ r_matches_file(const string &pattern, const Filename &candidate) const { * false otherwise. */ bool GlobPattern:: -matches_substr(string::const_iterator pi, string::const_iterator pend, - string::const_iterator ci, string::const_iterator cend) const { +matches_substr(const char *pi, const char *pend, + const char *ci, const char *cend) const { // If we run out of pattern or candidate string, it's a match only if they // both ran out at the same time. if (pi == pend || ci == cend) { @@ -412,7 +412,7 @@ matches_substr(string::const_iterator pi, string::const_iterator pend, if (pi == pend) { return false; } - // fall through. + [[fallthrough]]; default: // Anything else means to match exactly that. @@ -438,8 +438,7 @@ matches_substr(string::const_iterator pi, string::const_iterator pend, * false otherwise. */ bool GlobPattern:: -matches_set(string::const_iterator &pi, string::const_iterator pend, - char ch) const { +matches_set(const char *&pi, const char *pend, char ch) const { bool matched = false; while (pi != pend && (*pi) != ']') { diff --git a/dtool/src/dtoolutil/globPattern.h b/dtool/src/dtoolutil/globPattern.h index af181691abc..2325b77372c 100644 --- a/dtool/src/dtoolutil/globPattern.h +++ b/dtool/src/dtoolutil/globPattern.h @@ -31,7 +31,7 @@ */ class EXPCL_DTOOL_DTOOLUTIL GlobPattern { PUBLISHED: - INLINE GlobPattern(const std::string &pattern = std::string()); + INLINE GlobPattern(std::string pattern = std::string()); INLINE GlobPattern(const GlobPattern ©); INLINE void operator = (const GlobPattern ©); @@ -39,7 +39,7 @@ class EXPCL_DTOOL_DTOOLUTIL GlobPattern { INLINE bool operator != (const GlobPattern &other) const; INLINE bool operator < (const GlobPattern &other) const; - INLINE void set_pattern(const std::string &pattern); + INLINE void set_pattern(std::string pattern); INLINE const std::string &get_pattern() const; MAKE_PROPERTY(pattern, get_pattern, set_pattern); @@ -47,11 +47,11 @@ class EXPCL_DTOOL_DTOOLUTIL GlobPattern { INLINE bool get_case_sensitive() const; MAKE_PROPERTY(case_sensitive, get_case_sensitive, set_case_sensitive); - INLINE void set_nomatch_chars(const std::string &nomatch_chars); + INLINE void set_nomatch_chars(std::string nomatch_chars); INLINE const std::string &get_nomatch_chars() const; MAKE_PROPERTY(nomatch_chars, get_nomatch_chars, set_nomatch_chars); - INLINE bool matches(const std::string &candidate) const; + INLINE bool matches(std::string_view candidate) const; bool matches_file(Filename candidate) const; INLINE void output(std::ostream &out) const; @@ -64,14 +64,10 @@ class EXPCL_DTOOL_DTOOLUTIL GlobPattern { #endif private: - bool matches_substr(std::string::const_iterator pi, - std::string::const_iterator pend, - std::string::const_iterator ci, - std::string::const_iterator cend) const; - - bool matches_set(std::string::const_iterator &pi, - std::string::const_iterator pend, - char ch) const; + bool matches_substr(const char *pi, const char *pend, + const char *ci, const char *cend) const; + + bool matches_set(const char *&pi, const char *pend, char ch) const; int r_match_files(const Filename &prefix, const std::string &suffix, vector_string &results, const Filename &cwd); diff --git a/dtool/src/dtoolutil/load_dso.cxx b/dtool/src/dtoolutil/load_dso.cxx index ea212009a73..5ead262a4ae 100644 --- a/dtool/src/dtoolutil/load_dso.cxx +++ b/dtool/src/dtoolutil/load_dso.cxx @@ -25,7 +25,7 @@ static Filename resolve_dso(const DSearchPath &path, const Filename &filename) { // This is a special case, meaning to search in the same directory in // which libp3dtool.dll, or the exe, was started from. Filename dtoolpath = ExecutionEnvironment::get_dtool_name(); - DSearchPath spath(dtoolpath.get_dirname()); + DSearchPath spath(Filename(dtoolpath.get_dirname())); return spath.find_file(filename); #endif } else { diff --git a/dtool/src/dtoolutil/pandaFileStreamBuf.cxx b/dtool/src/dtoolutil/pandaFileStreamBuf.cxx index e5891c71582..39dbbce7b33 100644 --- a/dtool/src/dtoolutil/pandaFileStreamBuf.cxx +++ b/dtool/src/dtoolutil/pandaFileStreamBuf.cxx @@ -56,24 +56,12 @@ PandaFileStreamBuf() { _fd = -1; #endif // _WIN32 -#ifdef PHAVE_IOSTREAM _buffer = (char *)PANDA_MALLOC_ARRAY(file_buffer_size * 2); char *ebuf = _buffer + file_buffer_size * 2; char *mbuf = _buffer + file_buffer_size; setg(_buffer, mbuf, mbuf); setp(mbuf, ebuf); -#else - allocate(); - // Chop the buffer in half. The bottom half goes to the get buffer; the top - // half goes to the put buffer. - char *b = base(); - char *t = ebuf(); - char *m = b + (t - b) / 2; - setg(b, m, m); - setp(b, m); -#endif - _gpos = 0; _ppos = 0; } @@ -84,9 +72,7 @@ PandaFileStreamBuf() { PandaFileStreamBuf:: ~PandaFileStreamBuf() { close(); -#ifdef PHAVE_IOSTREAM PANDA_FREE_ARRAY(_buffer); -#endif } /** diff --git a/dtool/src/dtoolutil/pandaSystem.cxx b/dtool/src/dtoolutil/pandaSystem.cxx index 96491c54578..38c8dd6fc79 100644 --- a/dtool/src/dtoolutil/pandaSystem.cxx +++ b/dtool/src/dtoolutil/pandaSystem.cxx @@ -235,7 +235,7 @@ get_platform() { * implementation defined. */ bool PandaSystem:: -has_system(const string &system) const { +has_system(std::string_view system) const { Systems::const_iterator si; si = _systems.find(system); return (si != _systems.end()); @@ -278,7 +278,7 @@ get_system(size_t n) const { * or if does not define the indicated tag. */ string PandaSystem:: -get_system_tag(const string &system, const string &tag) const { +get_system_tag(std::string_view system, std::string_view tag) const { Systems::const_iterator si; si = _systems.find(system); if (si != _systems.end()) { @@ -297,7 +297,7 @@ get_system_tag(const string &system, const string &tag) const { * Intended for use by each subsystem to register itself at startup. */ void PandaSystem:: -add_system(const string &system) { +add_system(std::string_view system) { bool inserted = _systems.insert(Systems::value_type(system, SystemTags(get_class_type()))).second; if (inserted) { _system_names_dirty = true; @@ -309,8 +309,7 @@ add_system(const string &system) { * startup. */ void PandaSystem:: -set_system_tag(const string &system, const string &tag, - const string &value) { +set_system_tag(std::string_view system, std::string tag, std::string value) { std::pair result; result = _systems.insert(Systems::value_type(system, SystemTags(get_class_type()))); if (result.second) { @@ -318,7 +317,7 @@ set_system_tag(const string &system, const string &tag, } SystemTags &tags = (*result.first).second; - tags[tag] = value; + tags[std::move(tag)] = std::move(value); } /** diff --git a/dtool/src/dtoolutil/pandaSystem.h b/dtool/src/dtoolutil/pandaSystem.h index 640338edbc1..3d377d35c17 100644 --- a/dtool/src/dtoolutil/pandaSystem.h +++ b/dtool/src/dtoolutil/pandaSystem.h @@ -60,17 +60,16 @@ class EXPCL_DTOOL_DTOOLUTIL PandaSystem { MAKE_PROPERTY(platform, get_platform); - bool has_system(const std::string &system) const; + bool has_system(std::string_view system) const; size_t get_num_systems() const; std::string get_system(size_t n) const; MAKE_SEQ(get_systems, get_num_systems, get_system); MAKE_SEQ_PROPERTY(systems, get_num_systems, get_system); - std::string get_system_tag(const std::string &system, const std::string &tag) const; + std::string get_system_tag(std::string_view system, std::string_view tag) const; - void add_system(const std::string &system); - void set_system_tag(const std::string &system, const std::string &tag, - const std::string &value); + void add_system(std::string_view system); + void set_system_tag(std::string_view system, std::string tag, std::string value); bool heap_trim(size_t pad); @@ -82,8 +81,8 @@ class EXPCL_DTOOL_DTOOLUTIL PandaSystem { private: void reset_system_names(); - typedef pmap SystemTags; - typedef pmap Systems; + typedef pmap > SystemTags; + typedef pmap > Systems; typedef pvector SystemNames; Systems _systems; diff --git a/dtool/src/dtoolutil/pfstreamBuf.cxx b/dtool/src/dtoolutil/pfstreamBuf.cxx index a9a2abd12ad..07db8d368a5 100644 --- a/dtool/src/dtoolutil/pfstreamBuf.cxx +++ b/dtool/src/dtoolutil/pfstreamBuf.cxx @@ -24,18 +24,6 @@ PipeStreamBuf::PipeStreamBuf(PipeStreamBuf::Direction dir) : _dir(dir) { init_pipe(); - -#ifndef PHAVE_IOSTREAM - // These lines, which are essential on older implementations of the iostream - // library, are not understood by more recent versions. - allocate(); - assert((dir == Input) || (dir == Output)); - if (dir == Input) { - setg(base(), ebuf(), ebuf()); - } else { - setp(base(), ebuf()); - } -#endif /* PHAVE_IOSTREAM */ } PipeStreamBuf:: @@ -109,22 +97,14 @@ int PipeStreamBuf::underflow(void) { if (eof_pipe()) { return EOF; } -#ifdef PHAVE_IOSTREAM size_t len = 4096; -#else /* PHAVE_IOSTREAM */ - size_t len = ebuf() - base(); -#endif /* PHAVE_IOSTREAM */ char* buf = new char[len]; size_t n = read_pipe(buf, len); int ret = buf[0]; if (n == 0) ret = EOF; else { -#ifdef PHAVE_IOSTREAM memcpy(eback()+(len-n), buf, n); -#else /* PHAVE_IOSTREAM */ - memcpy(base()+(len-n), buf, n); -#endif /* PHAVE_IOSTREAM */ gbump(-((int)n)); } delete[] buf; diff --git a/dtool/src/dtoolutil/stringDecoder.I b/dtool/src/dtoolutil/stringDecoder.I index ce128833d09..4448735d33e 100644 --- a/dtool/src/dtoolutil/stringDecoder.I +++ b/dtool/src/dtoolutil/stringDecoder.I @@ -15,7 +15,7 @@ * */ INLINE StringDecoder:: -StringDecoder(const std::string &input) : _input(input) { +StringDecoder(std::string_view input) : _input(input) { _p = 0; _eof = false; } @@ -46,12 +46,12 @@ test_eof() { * */ INLINE StringUtf8Decoder:: -StringUtf8Decoder(const std::string &input) : StringDecoder(input) { +StringUtf8Decoder(std::string_view input) : StringDecoder(input) { } /** * */ INLINE StringUnicodeDecoder:: -StringUtf16Decoder(const std::string &input) : StringDecoder(input) { +StringUtf16Decoder(std::string_view input) : StringDecoder(input) { } diff --git a/dtool/src/dtoolutil/stringDecoder.h b/dtool/src/dtoolutil/stringDecoder.h index 6885f77e086..fcf09442fa5 100644 --- a/dtool/src/dtoolutil/stringDecoder.h +++ b/dtool/src/dtoolutil/stringDecoder.h @@ -23,7 +23,7 @@ */ class EXPCL_DTOOL_DTOOLUTIL StringDecoder { public: - INLINE StringDecoder(const std::string &input); + INLINE StringDecoder(std::string_view input); virtual ~StringDecoder(); virtual char32_t get_next_character(); @@ -46,7 +46,7 @@ class EXPCL_DTOOL_DTOOLUTIL StringDecoder { */ class StringUtf8Decoder : public StringDecoder { public: - INLINE StringUtf8Decoder(const std::string &input); + INLINE StringUtf8Decoder(std::string_view input); virtual char32_t get_next_character(); }; @@ -57,7 +57,7 @@ class StringUtf8Decoder : public StringDecoder { */ class StringUtf16Decoder : public StringDecoder { public: - INLINE StringUtf16Decoder(const std::string &input); + INLINE StringUtf16Decoder(std::string_view input); virtual char32_t get_next_character(); }; diff --git a/dtool/src/dtoolutil/string_utils.I b/dtool/src/dtoolutil/string_utils.I index d821deffdff..2e50ebd524f 100644 --- a/dtool/src/dtoolutil/string_utils.I +++ b/dtool/src/dtoolutil/string_utils.I @@ -20,8 +20,8 @@ format_string(const Thing &thing) { } INLINE std::string -format_string(const std::string &value) { - return value; +format_string(std::string_view value) { + return std::string(value); } INLINE std::string diff --git a/dtool/src/dtoolutil/string_utils.cxx b/dtool/src/dtoolutil/string_utils.cxx index 50d5d538024..0cb8f208d24 100644 --- a/dtool/src/dtoolutil/string_utils.cxx +++ b/dtool/src/dtoolutil/string_utils.cxx @@ -23,9 +23,9 @@ using std::wstring; // Case-insensitive string comparison, from Stroustrup's C++ third edition. // Works like strcmp(). int -cmp_nocase(const string &s, const string &s2) { - string::const_iterator p = s.begin(); - string::const_iterator p2 = s2.begin(); +cmp_nocase(std::string_view s, std::string_view s2) { + std::string_view::const_iterator p = s.begin(); + std::string_view::const_iterator p2 = s2.begin(); while (p != s.end() && p2 != s2.end()) { if (toupper(*p) != toupper(*p2)) { @@ -46,9 +46,9 @@ toupper_uh(int ch) { int -cmp_nocase_uh(const string &s, const string &s2) { - string::const_iterator p = s.begin(); - string::const_iterator p2 = s2.begin(); +cmp_nocase_uh(std::string_view s, std::string_view s2) { + std::string_view::const_iterator p = s.begin(); + std::string_view::const_iterator p2 = s2.begin(); while (p != s.end() && p2 != s2.end()) { if (toupper_uh(*p) != toupper_uh(*p2)) { @@ -68,10 +68,10 @@ cmp_nocase_uh(const string &s, const string &s2) { * Returns the input string with all uppercase letters converted to lowercase. */ string -downcase(const string &s) { +downcase(std::string_view s) { string result; result.reserve(s.size()); - string::const_iterator p; + std::string_view::const_iterator p; for (p = s.begin(); p != s.end(); ++p) { result += tolower(*p); } @@ -82,10 +82,10 @@ downcase(const string &s) { * Returns the input string with all lowercase letters converted to uppercase. */ string -upcase(const string &s) { +upcase(std::string_view s) { string result; result.reserve(s.size()); - string::const_iterator p; + std::string_view::const_iterator p; for (p = s.begin(); p != s.end(); ++p) { result += toupper(*p); } @@ -102,7 +102,7 @@ upcase(const string &s) { * The return value is the number of words extracted. */ int -extract_words(const string &str, vector_string &words) { +extract_words(std::string_view str, vector_string &words) { int num_words = 0; size_t pos = 0; @@ -114,7 +114,7 @@ extract_words(const string &str, vector_string &words) { while (pos < str.length() && !isspace((unsigned int)str[pos])) { pos++; } - words.push_back(str.substr(word_start, pos - word_start)); + words.push_back(string(str.substr(word_start, pos - word_start))); num_words++; while (pos < str.length() && isspace((unsigned int)str[pos])) { @@ -134,7 +134,7 @@ extract_words(const string &str, vector_string &words) { * The return value is the number of words extracted. */ int -extract_words(const wstring &str, pvector &words) { +extract_words(std::wstring_view str, pvector &words) { int num_words = 0; size_t pos = 0; @@ -146,7 +146,7 @@ extract_words(const wstring &str, pvector &words) { while (pos < str.length() && !TextEncoder::unicode_isspace(str[pos])) { pos++; } - words.push_back(str.substr(word_start, pos - word_start)); + words.push_back(wstring(str.substr(word_start, pos - word_start))); num_words++; while (pos < str.length() && TextEncoder::unicode_isspace(str[pos])) { @@ -167,19 +167,19 @@ extract_words(const wstring &str, pvector &words) { * end of the vector. */ void -tokenize(const string &str, vector_string &words, const string &delimiters, +tokenize(std::string_view str, vector_string &words, std::string_view delimiters, bool discard_repeated_delimiters) { size_t p = 0; while (p < str.length()) { size_t q = str.find_first_of(delimiters, p); if (q == string::npos) { if (q - p || !discard_repeated_delimiters){ - words.push_back(str.substr(p)); + words.push_back(string(str.substr(p))); } return; } if (q - p || !discard_repeated_delimiters){ - words.push_back(str.substr(p, q - p)); + words.push_back(string(str.substr(p, q - p))); } p = q + 1; } @@ -196,19 +196,19 @@ tokenize(const string &str, vector_string &words, const string &delimiters, * end of the vector. */ void -tokenize(const wstring &str, pvector &words, const wstring &delimiters, +tokenize(std::wstring_view str, pvector &words, std::wstring_view delimiters, bool discard_repeated_delimiters) { size_t p = 0; while (p < str.length()) { size_t q = str.find_first_of(delimiters, p); if (q == string::npos) { if (q - p || !discard_repeated_delimiters){ - words.push_back(str.substr(p)); + words.push_back(wstring(str.substr(p))); } return; } if (q - p || !discard_repeated_delimiters){ - words.push_back(str.substr(p, q - p)); + words.push_back(wstring(str.substr(p, q - p))); } p = q + 1; } @@ -220,13 +220,13 @@ tokenize(const wstring &str, pvector &words, const wstring &delimiters, * leading whitespace removed. */ string -trim_left(const string &str) { +trim_left(std::string_view str) { size_t begin = 0; while (begin < str.size() && isspace((unsigned int)str[begin])) { begin++; } - return str.substr(begin); + return string(str.substr(begin)); } /** @@ -234,13 +234,13 @@ trim_left(const string &str) { * leading whitespace removed. */ wstring -trim_left(const wstring &str) { +trim_left(std::wstring_view str) { size_t begin = 0; while (begin < str.size() && TextEncoder::unicode_isspace(str[begin])) { begin++; } - return str.substr(begin); + return wstring(str.substr(begin)); } /** @@ -248,14 +248,14 @@ trim_left(const wstring &str) { * trailing whitespace removed. */ string -trim_right(const string &str) { +trim_right(std::string_view str) { size_t begin = 0; size_t end = str.size(); while (end > begin && isspace((unsigned int)str[end - 1])) { end--; } - return str.substr(begin, end - begin); + return string(str.substr(begin, end - begin)); } /** @@ -263,14 +263,14 @@ trim_right(const string &str) { * trailing whitespace removed. */ wstring -trim_right(const wstring &str) { +trim_right(std::wstring_view str) { size_t begin = 0; size_t end = str.size(); while (end > begin && TextEncoder::unicode_isspace(str[end - 1])) { end--; } - return str.substr(begin, end - begin); + return wstring(str.substr(begin, end - begin)); } /** @@ -278,7 +278,7 @@ trim_right(const wstring &str) { * both leading and trailing whitespace removed. */ string -trim(const string &str) { +trim(std::string_view str) { size_t begin = 0; while (begin < str.size() && isspace((unsigned int)str[begin])) { begin++; @@ -289,7 +289,7 @@ trim(const string &str) { end--; } - return str.substr(begin, end - begin); + return string(str.substr(begin, end - begin)); } /** @@ -297,7 +297,7 @@ trim(const string &str) { * both leading and trailing whitespace removed. */ wstring -trim(const wstring &str) { +trim(std::wstring_view str) { size_t begin = 0; while (begin < str.size() && TextEncoder::unicode_isspace(str[begin])) { begin++; @@ -308,7 +308,7 @@ trim(const wstring &str) { end--; } - return str.substr(begin, end - begin); + return wstring(str.substr(begin, end - begin)); } /** diff --git a/dtool/src/dtoolutil/string_utils.h b/dtool/src/dtoolutil/string_utils.h index 01f7616fa93..f60900410f5 100644 --- a/dtool/src/dtoolutil/string_utils.h +++ b/dtool/src/dtoolutil/string_utils.h @@ -22,36 +22,36 @@ // Case-insensitive string comparison, from Stroustrup's C++ third edition. // Works like strcmp(). -EXPCL_DTOOL_DTOOLUTIL int cmp_nocase(const std::string &s, const std::string &s2); +EXPCL_DTOOL_DTOOLUTIL int cmp_nocase(std::string_view s, std::string_view s2); // Similar, except it also accepts hyphen and underscore as equivalent. -EXPCL_DTOOL_DTOOLUTIL int cmp_nocase_uh(const std::string &s, const std::string &s2); +EXPCL_DTOOL_DTOOLUTIL int cmp_nocase_uh(std::string_view s, std::string_view s2); // Returns the string converted to lowercase. -EXPCL_DTOOL_DTOOLUTIL std::string downcase(const std::string &s); +EXPCL_DTOOL_DTOOLUTIL std::string downcase(std::string_view s); // Returns the string converted to uppercase. -EXPCL_DTOOL_DTOOLUTIL std::string upcase(const std::string &s); +EXPCL_DTOOL_DTOOLUTIL std::string upcase(std::string_view s); // Separates the string into words according to whitespace. -EXPCL_DTOOL_DTOOLUTIL int extract_words(const std::string &str, vector_string &words); -EXPCL_DTOOL_DTOOLUTIL int extract_words(const std::wstring &str, pvector &words); +EXPCL_DTOOL_DTOOLUTIL int extract_words(std::string_view str, vector_string &words); +EXPCL_DTOOL_DTOOLUTIL int extract_words(std::wstring_view str, pvector &words); // Separates the string into words according to the indicated delimiters. -EXPCL_DTOOL_DTOOLUTIL void tokenize(const std::string &str, vector_string &words, - const std::string &delimiters, +EXPCL_DTOOL_DTOOLUTIL void tokenize(std::string_view str, vector_string &words, + std::string_view delimiters, bool discard_repeated_delimiters = false); -EXPCL_DTOOL_DTOOLUTIL void tokenize(const std::wstring &str, pvector &words, - const std::wstring &delimiters, +EXPCL_DTOOL_DTOOLUTIL void tokenize(std::wstring_view str, pvector &words, + std::wstring_view delimiters, bool discard_repeated_delimiters = false); // Trims leading andor trailing whitespace from the string. -EXPCL_DTOOL_DTOOLUTIL std::string trim_left(const std::string &str); -EXPCL_DTOOL_DTOOLUTIL std::wstring trim_left(const std::wstring &str); -EXPCL_DTOOL_DTOOLUTIL std::string trim_right(const std::string &str); -EXPCL_DTOOL_DTOOLUTIL std::wstring trim_right(const std::wstring &str); -EXPCL_DTOOL_DTOOLUTIL std::string trim(const std::string &str); -EXPCL_DTOOL_DTOOLUTIL std::wstring trim(const std::wstring &str); +EXPCL_DTOOL_DTOOLUTIL std::string trim_left(std::string_view str); +EXPCL_DTOOL_DTOOLUTIL std::wstring trim_left(std::wstring_view str); +EXPCL_DTOOL_DTOOLUTIL std::string trim_right(std::string_view str); +EXPCL_DTOOL_DTOOLUTIL std::wstring trim_right(std::wstring_view str); +EXPCL_DTOOL_DTOOLUTIL std::string trim(std::string_view str); +EXPCL_DTOOL_DTOOLUTIL std::wstring trim(std::wstring_view str); // Functions to parse numeric values out of a string. EXPCL_DTOOL_DTOOLUTIL int string_to_int(const std::string &str, std::string &tail); @@ -67,7 +67,7 @@ template INLINE std::string format_string(const Thing &thing); // Fast specializations for some primitive types. -INLINE std::string format_string(const std::string &value); +INLINE std::string format_string(std::string_view value); INLINE std::string format_string(bool value); INLINE std::string format_string(float value); INLINE std::string format_string(double value); diff --git a/dtool/src/dtoolutil/textEncoder.I b/dtool/src/dtoolutil/textEncoder.I index aa6b42fdb53..b4e19655cb4 100644 --- a/dtool/src/dtoolutil/textEncoder.I +++ b/dtool/src/dtoolutil/textEncoder.I @@ -47,8 +47,8 @@ TextEncoder(const TextEncoder ©) : INLINE void TextEncoder:: set_encoding(TextEncoder::Encoding encoding) { // Force the previously-set strings to be encoded or decoded now. - get_text(); - get_wtext(); + ensure_text(); + ensure_wtext(); _encoding = encoding; } @@ -86,7 +86,7 @@ get_default_encoding() { * decoded version of the string. */ INLINE void TextEncoder:: -set_text(const std::string &text) { +set_text(std::string_view text) { if (!has_text() || _text != text) { _text = text; _flags = (_flags | F_got_text) & ~F_got_wtext; @@ -101,7 +101,7 @@ set_text(const std::string &text) { * whichever encoding is specified by set_encoding(). */ INLINE void TextEncoder:: -set_text(const std::string &text, TextEncoder::Encoding encoding) { +set_text(std::string_view text, TextEncoder::Encoding encoding) { if (encoding == _encoding) { set_text(text); } else { @@ -137,10 +137,7 @@ has_text() const { */ INLINE std::string TextEncoder:: get_text() const { - if ((_flags & F_got_text) == 0) { - ((TextEncoder *)this)->_text = encode_wtext(_wtext); - ((TextEncoder *)this)->_flags |= F_got_text; - } + ensure_text(); return _text; } @@ -149,16 +146,18 @@ get_text() const { */ INLINE std::string TextEncoder:: get_text(TextEncoder::Encoding encoding) const { - return encode_wtext(get_wtext(), encoding); + ensure_wtext(); + return encode_wtext(_wtext, encoding); } /** * Appends the indicates string to the end of the stored text. */ INLINE void TextEncoder:: -append_text(const std::string &text) { +append_text(std::string_view text) { if (!text.empty()) { - _text = get_text() + text; + ensure_text(); + _text += text; _flags = (_flags | F_got_text) & ~F_got_wtext; text_changed(); } @@ -170,12 +169,13 @@ append_text(const std::string &text) { */ INLINE void TextEncoder:: append_unicode_char(char32_t character) { + ensure_wtext(); #if WCHAR_MAX >= 0x10FFFF // wchar_t might be UTF-32. - _wtext = get_wtext() + std::wstring(1, (wchar_t)character); + _wtext += (wchar_t)character; #else if ((character & ~0xffff) == 0) { - _wtext = get_wtext() + std::wstring(1, (wchar_t)character); + _wtext += (wchar_t)character; } else { // Encode as a surrogate pair. uint32_t v = (uint32_t)character - 0x10000u; @@ -183,7 +183,7 @@ append_unicode_char(char32_t character) { (wchar_t)((v >> 10u) | 0xd800u), (wchar_t)((v & 0x3ffu) | 0xdc00u), }; - _wtext = get_wtext() + std::wstring(wstr, 2); + _wtext += std::wstring_view(wstr, 2); } #endif _flags = (_flags | F_got_wtext) & ~F_got_text; @@ -197,7 +197,8 @@ append_unicode_char(char32_t character) { */ INLINE size_t TextEncoder:: get_num_chars() const { - return get_wtext().length(); + ensure_wtext(); + return _wtext.length(); } /** @@ -207,7 +208,7 @@ get_num_chars() const { */ INLINE int TextEncoder:: get_unicode_char(size_t index) const { - get_wtext(); + ensure_wtext(); if (index < _wtext.length()) { return _wtext[index]; } @@ -221,7 +222,7 @@ get_unicode_char(size_t index) const { */ INLINE void TextEncoder:: set_unicode_char(size_t index, char32_t character) { - get_wtext(); + ensure_wtext(); if (index < _wtext.length()) { _wtext[index] = character; _flags &= ~F_got_text; @@ -273,7 +274,7 @@ get_text_as_ascii() const { * properties on the TextEncoder itself. */ INLINE std::string TextEncoder:: -reencode_text(const std::string &text, TextEncoder::Encoding from, +reencode_text(std::string_view text, TextEncoder::Encoding from, TextEncoder::Encoding to) { return encode_wtext(decode_text(text, from), to); } @@ -395,7 +396,7 @@ unicode_tolower(char32_t character) { * default encoding. */ INLINE std::string TextEncoder:: -upper(const std::string &source) { +upper(std::string_view source) { return upper(source, get_default_encoding()); } @@ -404,7 +405,7 @@ upper(const std::string &source) { * indicated encoding. */ INLINE std::string TextEncoder:: -upper(const std::string &source, TextEncoder::Encoding encoding) { +upper(std::string_view source, TextEncoder::Encoding encoding) { TextEncoder encoder; encoder.set_encoding(encoding); encoder.set_text(source); @@ -417,7 +418,7 @@ upper(const std::string &source, TextEncoder::Encoding encoding) { * default encoding. */ INLINE std::string TextEncoder:: -lower(const std::string &source) { +lower(std::string_view source) { return lower(source, get_default_encoding()); } @@ -426,7 +427,7 @@ lower(const std::string &source) { * indicated encoding. */ INLINE std::string TextEncoder:: -lower(const std::string &source, TextEncoder::Encoding encoding) { +lower(std::string_view source, TextEncoder::Encoding encoding) { TextEncoder encoder; encoder.set_encoding(encoding); encoder.set_text(source); @@ -440,7 +441,7 @@ lower(const std::string &source, TextEncoder::Encoding encoding) { * encoded version of the string. */ INLINE void TextEncoder:: -set_wtext(const std::wstring &wtext) { +set_wtext(std::wstring_view wtext) { if (!has_text() || _wtext != wtext) { _wtext = wtext; _flags = (_flags | F_got_wtext) & ~F_got_text; @@ -465,9 +466,10 @@ get_wtext() const { * Appends the indicates string to the end of the stored wide-character text. */ INLINE void TextEncoder:: -append_wtext(const std::wstring &wtext) { +append_wtext(std::wstring_view wtext) { if (!wtext.empty()) { - _wtext = get_wtext() + wtext; + (void)get_wtext(); + _wtext += wtext; _flags = (_flags | F_got_wtext) & ~F_got_text; text_changed(); } @@ -478,7 +480,7 @@ append_wtext(const std::wstring &wtext) { * current encoding. */ INLINE std::string TextEncoder:: -encode_wtext(const std::wstring &wtext) const { +encode_wtext(std::wstring_view wtext) const { return encode_wtext(wtext, _encoding); } @@ -487,10 +489,32 @@ encode_wtext(const std::wstring &wtext) const { * encoding system. */ INLINE std::wstring TextEncoder:: -decode_text(const std::string &text) const { +decode_text(std::string_view text) const { return decode_text(text, _encoding); } +/** + * + */ +INLINE void TextEncoder:: +ensure_text() const { + if ((_flags & F_got_text) == 0) { + ((TextEncoder *)this)->_text = encode_wtext(_wtext); + ((TextEncoder *)this)->_flags |= F_got_text; + } +} + +/** + * + */ +INLINE void TextEncoder:: +ensure_wtext() const { + if ((_flags & F_got_wtext) == 0) { + ((TextEncoder *)this)->_wtext = decode_text(_text); + ((TextEncoder *)this)->_flags |= F_got_wtext; + } +} + /** * Uses the current default encoding to output the wstring. */ diff --git a/dtool/src/dtoolutil/textEncoder.cxx b/dtool/src/dtoolutil/textEncoder.cxx index 1c9bca49a3c..ee6ce5ccbf6 100644 --- a/dtool/src/dtoolutil/textEncoder.cxx +++ b/dtool/src/dtoolutil/textEncoder.cxx @@ -65,7 +65,7 @@ TextEncoder::Encoding TextEncoder::_default_encoding = TextEncoder::E_utf8; */ void TextEncoder:: make_upper() { - get_wtext(); + ensure_wtext(); wstring::iterator si; for (si = _wtext.begin(); si != _wtext.end(); ++si) { (*si) = unicode_toupper(*si); @@ -80,7 +80,7 @@ make_upper() { */ void TextEncoder:: make_lower() { - get_wtext(); + ensure_wtext(); wstring::iterator si; for (si = _wtext.begin(); si != _wtext.end(); ++si) { (*si) = unicode_tolower(*si); @@ -104,7 +104,7 @@ make_lower() { */ wstring TextEncoder:: get_wtext_as_ascii() const { - get_wtext(); + ensure_wtext(); wstring result; wstring::const_iterator si; for (si = _wtext.begin(); si != _wtext.end(); ++si) { @@ -133,7 +133,7 @@ get_wtext_as_ascii() const { */ bool TextEncoder:: is_wtext() const { - get_wtext(); + ensure_wtext(); wstring::const_iterator ti; for (ti = _wtext.begin(); ti != _wtext.end(); ++ti) { if (((*ti) & ~0x7f) != 0) { @@ -237,7 +237,7 @@ encode_wchar(char32_t ch, TextEncoder::Encoding encoding) { * given encoding. */ string TextEncoder:: -encode_wtext(const wstring &wtext, TextEncoder::Encoding encoding) { +encode_wtext(std::wstring_view wtext, TextEncoder::Encoding encoding) { string result; for (size_t i = 0; i < wtext.size(); ++i) { @@ -269,7 +269,7 @@ encode_wtext(const wstring &wtext, TextEncoder::Encoding encoding) { * encoding system. */ wstring TextEncoder:: -decode_text(const string &text, TextEncoder::Encoding encoding) { +decode_text(std::string_view text, TextEncoder::Encoding encoding) { switch (encoding) { case E_utf8: { diff --git a/dtool/src/dtoolutil/textEncoder.h b/dtool/src/dtoolutil/textEncoder.h index 29a523b2c11..360d307c333 100644 --- a/dtool/src/dtoolutil/textEncoder.h +++ b/dtool/src/dtoolutil/textEncoder.h @@ -58,8 +58,8 @@ class EXPCL_DTOOL_DTOOLUTIL TextEncoder { EXTEND void set_text(PyObject *text); EXTEND void set_text(PyObject *text, Encoding encoding); #else - INLINE void set_text(const std::string &text); - INLINE void set_text(const std::string &text, Encoding encoding); + INLINE void set_text(std::string_view text); + INLINE void set_text(std::string_view text, Encoding encoding); #endif INLINE void clear_text(); INLINE bool has_text() const; @@ -74,7 +74,7 @@ class EXPCL_DTOOL_DTOOLUTIL TextEncoder { #else INLINE std::string get_text() const; INLINE std::string get_text(Encoding encoding) const; - INLINE void append_text(const std::string &text); + INLINE void append_text(std::string_view text); #endif INLINE void append_unicode_char(char32_t character); INLINE size_t get_num_chars() const; @@ -84,7 +84,7 @@ class EXPCL_DTOOL_DTOOLUTIL TextEncoder { INLINE std::string get_encoded_char(size_t index, Encoding encoding) const; INLINE std::string get_text_as_ascii() const; - INLINE static std::string reencode_text(const std::string &text, Encoding from, Encoding to); + INLINE static std::string reencode_text(std::string_view text, Encoding from, Encoding to); INLINE static bool unicode_isalpha(char32_t character); INLINE static bool unicode_isdigit(char32_t character); @@ -95,36 +95,39 @@ class EXPCL_DTOOL_DTOOLUTIL TextEncoder { INLINE static int unicode_toupper(char32_t character); INLINE static int unicode_tolower(char32_t character); - INLINE static std::string upper(const std::string &source); - INLINE static std::string upper(const std::string &source, Encoding encoding); - INLINE static std::string lower(const std::string &source); - INLINE static std::string lower(const std::string &source, Encoding encoding); + INLINE static std::string upper(std::string_view source); + INLINE static std::string upper(std::string_view source, Encoding encoding); + INLINE static std::string lower(std::string_view source); + INLINE static std::string lower(std::string_view source, Encoding encoding); // Direct support for wide-character strings. Now publishable with the new // wstring support in interrogate. - INLINE void set_wtext(const std::wstring &wtext); + INLINE void set_wtext(std::wstring_view wtext); INLINE const std::wstring &get_wtext() const; - INLINE void append_wtext(const std::wstring &text); + INLINE void append_wtext(std::wstring_view text); std::wstring get_wtext_as_ascii() const; bool is_wtext() const; #if defined(CPPPARSER) && defined(HAVE_PYTHON) EXTEND static PyObject *encode_wchar(char32_t ch, Encoding encoding); - EXTEND INLINE PyObject *encode_wtext(const std::wstring &wtext) const; - EXTEND static PyObject *encode_wtext(const std::wstring &wtext, Encoding encoding); + EXTEND INLINE PyObject *encode_wtext(std::wstring_view wtext) const; + EXTEND static PyObject *encode_wtext(std::wstring_view wtext, Encoding encoding); EXTEND INLINE PyObject *decode_text(PyObject *text) const; EXTEND static PyObject *decode_text(PyObject *text, Encoding encoding); #else static std::string encode_wchar(char32_t ch, Encoding encoding); - INLINE std::string encode_wtext(const std::wstring &wtext) const; - static std::string encode_wtext(const std::wstring &wtext, Encoding encoding); - INLINE std::wstring decode_text(const std::string &text) const; - static std::wstring decode_text(const std::string &text, Encoding encoding); + INLINE std::string encode_wtext(std::wstring_view wtext) const; + static std::string encode_wtext(std::wstring_view wtext, Encoding encoding); + INLINE std::wstring decode_text(std::string_view text) const; + static std::wstring decode_text(std::string_view text, Encoding encoding); #endif MAKE_PROPERTY(text, get_text, set_text); protected: + INLINE void ensure_text() const; + INLINE void ensure_wtext() const; + virtual void text_changed(); private: diff --git a/dtool/src/dtoolutil/textEncoder_ext.I b/dtool/src/dtoolutil/textEncoder_ext.I index 2924fda0110..597f603ff1a 100644 --- a/dtool/src/dtoolutil/textEncoder_ext.I +++ b/dtool/src/dtoolutil/textEncoder_ext.I @@ -16,7 +16,7 @@ * current encoding. */ INLINE PyObject *Extension:: -encode_wtext(const std::wstring &wtext) const { +encode_wtext(std::wstring_view wtext) const { return encode_wtext(wtext, _this->get_encoding()); } diff --git a/dtool/src/dtoolutil/textEncoder_ext.cxx b/dtool/src/dtoolutil/textEncoder_ext.cxx index 21faa26a675..2e63c382e00 100644 --- a/dtool/src/dtoolutil/textEncoder_ext.cxx +++ b/dtool/src/dtoolutil/textEncoder_ext.cxx @@ -94,7 +94,7 @@ encode_wchar(char32_t ch, TextEncoder::Encoding encoding) { * given encoding. */ PyObject *Extension:: -encode_wtext(const std::wstring &wtext, TextEncoder::Encoding encoding) { +encode_wtext(std::wstring_view wtext, TextEncoder::Encoding encoding) { std::string value = TextEncoder::encode_wtext(wtext, encoding); return PyBytes_FromStringAndSize((char *)value.data(), (Py_ssize_t)value.size()); } diff --git a/dtool/src/dtoolutil/textEncoder_ext.h b/dtool/src/dtoolutil/textEncoder_ext.h index 049c16e4938..2761da7c935 100644 --- a/dtool/src/dtoolutil/textEncoder_ext.h +++ b/dtool/src/dtoolutil/textEncoder_ext.h @@ -37,8 +37,8 @@ class Extension : public ExtensionBase { void append_text(PyObject *text); static PyObject *encode_wchar(char32_t ch, TextEncoder::Encoding encoding); - INLINE PyObject *encode_wtext(const std::wstring &wtext) const; - static PyObject *encode_wtext(const std::wstring &wtext, TextEncoder::Encoding encoding); + INLINE PyObject *encode_wtext(std::wstring_view wtext) const; + static PyObject *encode_wtext(std::wstring_view wtext, TextEncoder::Encoding encoding); INLINE PyObject *decode_text(PyObject *text) const; static PyObject *decode_text(PyObject *text, TextEncoder::Encoding encoding); }; diff --git a/dtool/src/parser-inc/string_view b/dtool/src/parser-inc/string_view new file mode 100644 index 00000000000..88223a2b908 --- /dev/null +++ b/dtool/src/parser-inc/string_view @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace std { + template struct char_traits; + template> + class basic_string_view; + + using string_view = std::basic_string_view; + using u8string_view = std::basic_string_view; + using u16string_view = std::basic_string_view; + using u32string_view = std::basic_string_view; + using wstring_view = std::basic_string_view; + + template struct hash; + template<> struct hash; + template<> struct hash; + template<> struct hash; + template<> struct hash; + template<> struct hash; +} diff --git a/dtool/src/prc/configDeclaration.I b/dtool/src/prc/configDeclaration.I index 670f49e38a9..c2ceefe3670 100644 --- a/dtool/src/prc/configDeclaration.I +++ b/dtool/src/prc/configDeclaration.I @@ -58,8 +58,8 @@ get_string_value() const { * Changes the value assigned to this variable. */ INLINE void ConfigDeclaration:: -set_string_value(const std::string &string_value) { - _string_value = string_value; +set_string_value(std::string string_value) { + _string_value = std::move(string_value); _got_words = false; invalidate_cache(); } diff --git a/dtool/src/prc/configDeclaration.cxx b/dtool/src/prc/configDeclaration.cxx index 3f8e7582cd0..f151aacf324 100644 --- a/dtool/src/prc/configDeclaration.cxx +++ b/dtool/src/prc/configDeclaration.cxx @@ -29,10 +29,10 @@ static MutexImpl this_prc_dir_lock; */ ConfigDeclaration:: ConfigDeclaration(ConfigPage *page, ConfigVariableCore *variable, - const string &string_value, int decl_seq) : + std::string string_value, int decl_seq) : _page(page), _variable(variable), - _string_value(string_value), + _string_value(std::move(string_value)), _decl_seq(decl_seq), _got_words(false) { @@ -56,7 +56,7 @@ ConfigDeclaration:: * words. */ void ConfigDeclaration:: -set_string_word(size_t n, const string &value) { +set_string_word(size_t n, std::string_view value) { if (!_got_words) { get_words(); } @@ -401,7 +401,7 @@ check_double_word(size_t n) { * The return value is the number of words extracted. */ size_t ConfigDeclaration:: -extract_words(const string &str, vector_string &words) { +extract_words(std::string_view str, vector_string &words) { size_t num_words = 0; size_t pos = 0; @@ -413,7 +413,7 @@ extract_words(const string &str, vector_string &words) { while (pos < str.length() && !isspace((unsigned int)str[pos])) { pos++; } - words.push_back(str.substr(word_start, pos - word_start)); + words.emplace_back(str.substr(word_start, pos - word_start)); num_words++; while (pos < str.length() && isspace((unsigned int)str[pos])) { @@ -428,10 +428,10 @@ extract_words(const string &str, vector_string &words) { * Returns the input string with all uppercase letters converted to lowercase. */ string ConfigDeclaration:: -downcase(const string &s) { +downcase(std::string_view s) { string result; result.reserve(s.size()); - string::const_iterator p; + std::string_view::const_iterator p; for (p = s.begin(); p != s.end(); ++p) { result += (char)tolower(*p); } diff --git a/dtool/src/prc/configDeclaration.h b/dtool/src/prc/configDeclaration.h index 665848ccd47..503d72def02 100644 --- a/dtool/src/prc/configDeclaration.h +++ b/dtool/src/prc/configDeclaration.h @@ -33,7 +33,7 @@ class ConfigVariableCore; class EXPCL_DTOOL_PRC ConfigDeclaration : public ConfigFlags { private: ConfigDeclaration(ConfigPage *page, ConfigVariableCore *variable, - const std::string &string_value, int decl_seq); + std::string string_value, int decl_seq); ~ConfigDeclaration(); public: @@ -46,7 +46,7 @@ class EXPCL_DTOOL_PRC ConfigDeclaration : public ConfigFlags { MAKE_PROPERTY(variable, get_variable); INLINE const std::string &get_string_value() const; - INLINE void set_string_value(const std::string &value); + INLINE void set_string_value(std::string value); INLINE size_t get_num_words() const; @@ -62,7 +62,7 @@ class EXPCL_DTOOL_PRC ConfigDeclaration : public ConfigFlags { INLINE int64_t get_int64_word(size_t n) const; INLINE double get_double_word(size_t n) const; - void set_string_word(size_t n, const std::string &value); + void set_string_word(size_t n, std::string_view value); void set_bool_word(size_t n, bool value); void set_int_word(size_t n, int value); void set_int64_word(size_t n, int64_t value); @@ -76,8 +76,8 @@ class EXPCL_DTOOL_PRC ConfigDeclaration : public ConfigFlags { void write(std::ostream &out) const; public: - static size_t extract_words(const std::string &str, vector_string &words); - static std::string downcase(const std::string &s); + static size_t extract_words(std::string_view str, vector_string &words); + static std::string downcase(std::string_view s); private: void get_words(); diff --git a/dtool/src/prc/configPage.cxx b/dtool/src/prc/configPage.cxx index af53f661228..c12f13d74f6 100644 --- a/dtool/src/prc/configPage.cxx +++ b/dtool/src/prc/configPage.cxx @@ -37,8 +37,8 @@ ConfigPage *ConfigPage::_local_page = nullptr; * the ConfigPageManager make_page() interface. */ ConfigPage:: -ConfigPage(const string &name, bool implicit_load, int page_seq) : - _name(name), +ConfigPage(std::string name, bool implicit_load, int page_seq) : + _name(std::move(name)), _implicit_load(implicit_load), _page_seq(page_seq), _sort(implicit_load ? 10 : 0), @@ -221,7 +221,7 @@ read_prc(istream &in) { * Note that if the password is incorrect, the result may be garbage. */ bool ConfigPage:: -read_encrypted_prc(istream &in, const string &password) { +read_encrypted_prc(istream &in, std::string_view password) { #ifdef HAVE_OPENSSL IDecryptStream decrypt(&in, false, password); return read_prc(decrypt); @@ -234,18 +234,18 @@ read_encrypted_prc(istream &in, const string &password) { * Adds the indicated variable/value pair as a new declaration on the page. */ ConfigDeclaration *ConfigPage:: -make_declaration(const string &variable, const string &value) { +make_declaration(std::string_view variable, std::string value) { ConfigVariableManager *variable_mgr = ConfigVariableManager::get_global_ptr(); - return make_declaration(variable_mgr->make_variable(variable), value); + return make_declaration(variable_mgr->make_variable(variable), std::move(value)); } /** * Adds the indicated variable/value pair as a new declaration on the page. */ ConfigDeclaration *ConfigPage:: -make_declaration(ConfigVariableCore *variable, const string &value) { +make_declaration(ConfigVariableCore *variable, std::string value) { ConfigDeclaration *decl = new ConfigDeclaration - (this, variable, value, _next_decl_seq); + (this, variable, std::move(value), _next_decl_seq); _next_decl_seq++; _declarations.push_back(decl); @@ -380,7 +380,7 @@ write(ostream &out) const { * internally by read_prc() for each line. */ void ConfigPage:: -read_prc_line(const string &line) { +read_prc_line(std::string_view line) { if (line.substr(0, 7) == "##!sig ") { // This is a signature. Accumulate it into the signature and return, and // don't count it as contributing to the hash. @@ -433,10 +433,10 @@ read_prc_line(const string &line) { } size_t value_end = p; - string variable = line.substr(variable_begin, variable_end - variable_begin); - string value = line.substr(value_begin, value_end - value_begin); + std::string_view variable = line.substr(variable_begin, variable_end - variable_begin); + std::string_view value = line.substr(value_begin, value_end - value_begin); - make_declaration(variable, value); + make_declaration(variable, std::string(value)); } /** diff --git a/dtool/src/prc/configPage.h b/dtool/src/prc/configPage.h index 8dd0d822c17..0ca9b7a5906 100644 --- a/dtool/src/prc/configPage.h +++ b/dtool/src/prc/configPage.h @@ -29,7 +29,7 @@ class ConfigVariableCore; */ class EXPCL_DTOOL_PRC ConfigPage { private: - ConfigPage(const std::string &name, bool implicit_load, int page_seq); + ConfigPage(std::string name, bool implicit_load, int page_seq); ~ConfigPage(); public: @@ -61,10 +61,10 @@ class EXPCL_DTOOL_PRC ConfigPage { void clear(); bool read_prc(std::istream &in); - bool read_encrypted_prc(std::istream &in, const std::string &password); + bool read_encrypted_prc(std::istream &in, std::string_view password); - ConfigDeclaration *make_declaration(const std::string &variable, const std::string &value); - ConfigDeclaration *make_declaration(ConfigVariableCore *variable, const std::string &value); + ConfigDeclaration *make_declaration(std::string_view variable, std::string value); + ConfigDeclaration *make_declaration(ConfigVariableCore *variable, std::string value); bool delete_declaration(ConfigDeclaration *decl); size_t get_num_declarations() const; @@ -82,7 +82,7 @@ class EXPCL_DTOOL_PRC ConfigPage { private: INLINE void make_dirty(); - void read_prc_line(const std::string &line); + void read_prc_line(std::string_view line); static unsigned int hex_digit(unsigned char digit); std::string _name; diff --git a/dtool/src/prc/configPageManager.cxx b/dtool/src/prc/configPageManager.cxx index e3dbcfa69be..e814f01a09b 100644 --- a/dtool/src/prc/configPageManager.cxx +++ b/dtool/src/prc/configPageManager.cxx @@ -545,8 +545,8 @@ reload_implicit_pages() { * declarations that are defined in previous pages. */ ConfigPage *ConfigPageManager:: -make_explicit_page(const string &name) { - ConfigPage *page = new ConfigPage(name, false, _next_page_seq); +make_explicit_page(std::string name) { + ConfigPage *page = new ConfigPage(std::move(name), false, _next_page_seq); ++_next_page_seq; _explicit_pages.push_back(page); _pages_sorted = false; diff --git a/dtool/src/prc/configPageManager.h b/dtool/src/prc/configPageManager.h index 9a775f7b631..f8073447a2a 100644 --- a/dtool/src/prc/configPageManager.h +++ b/dtool/src/prc/configPageManager.h @@ -49,7 +49,7 @@ class EXPCL_DTOOL_PRC ConfigPageManager : public ConfigFlags { INLINE size_t get_num_prc_executable_patterns() const; INLINE std::string get_prc_executable_pattern(size_t n) const; - ConfigPage *make_explicit_page(const std::string &name); + ConfigPage *make_explicit_page(std::string name); bool delete_explicit_page(ConfigPage *page); INLINE size_t get_num_implicit_pages() const; diff --git a/dtool/src/prc/configVariable.I b/dtool/src/prc/configVariable.I index 53d73ff4c8b..646c4f382f8 100644 --- a/dtool/src/prc/configVariable.I +++ b/dtool/src/prc/configVariable.I @@ -16,7 +16,7 @@ * ConfigVariableFoo derived class. */ INLINE ConfigVariable:: -ConfigVariable(const std::string &name, ConfigVariable::ValueType value_type) : +ConfigVariable(std::string_view name, ConfigVariable::ValueType value_type) : ConfigVariableBase(name, value_type) { } @@ -26,8 +26,8 @@ ConfigVariable(const std::string &name, ConfigVariable::ValueType value_type) : * ConfigVariableFoo derived class. */ INLINE ConfigVariable:: -ConfigVariable(const std::string &name, ConfigVariable::ValueType value_type, - const std::string &description, int flags) : +ConfigVariable(std::string_view name, ConfigVariable::ValueType value_type, + std::string_view description, int flags) : ConfigVariableBase(name, value_type, description, flags) { } @@ -38,7 +38,7 @@ ConfigVariable(const std::string &name, ConfigVariable::ValueType value_type, * ConfigVariable of a specific type, without having to know what type it is. */ INLINE ConfigVariable:: -ConfigVariable(const std::string &name) : +ConfigVariable(std::string_view name) : ConfigVariableBase(name, VT_undefined) { _core->set_used(); @@ -77,9 +77,9 @@ get_string_value() const { * clear_local_value() is called. */ INLINE void ConfigVariable:: -set_string_value(const std::string &string_value) { +set_string_value(std::string string_value) { nassertv(is_constructed()); - _core->make_local_value()->set_string_value(string_value); + _core->make_local_value()->set_string_value(std::move(string_value)); } /** @@ -219,7 +219,7 @@ get_double_word(size_t n) const { * words. */ INLINE void ConfigVariable:: -set_string_word(size_t n, const std::string &value) { +set_string_word(size_t n, std::string_view value) { nassertv(is_constructed()); _core->make_local_value()->set_string_word(n, value); } diff --git a/dtool/src/prc/configVariable.h b/dtool/src/prc/configVariable.h index a4744777283..75d61bc3b60 100644 --- a/dtool/src/prc/configVariable.h +++ b/dtool/src/prc/configVariable.h @@ -30,16 +30,16 @@ */ class EXPCL_DTOOL_PRC ConfigVariable : public ConfigVariableBase { protected: - INLINE ConfigVariable(const std::string &name, ValueType type); - INLINE ConfigVariable(const std::string &name, ValueType type, - const std::string &description, int flags); + INLINE ConfigVariable(std::string_view name, ValueType type); + INLINE ConfigVariable(std::string_view name, ValueType type, + std::string_view description, int flags); PUBLISHED: - INLINE explicit ConfigVariable(const std::string &name); + INLINE explicit ConfigVariable(std::string_view name); INLINE ~ConfigVariable(); INLINE const std::string &get_string_value() const; - INLINE void set_string_value(const std::string &value); + INLINE void set_string_value(std::string value); INLINE void clear_value(); INLINE size_t get_num_words() const; @@ -61,7 +61,7 @@ class EXPCL_DTOOL_PRC ConfigVariable : public ConfigVariableBase { INLINE int64_t get_int64_word(size_t n) const; INLINE double get_double_word(size_t n) const; - INLINE void set_string_word(size_t n, const std::string &value); + INLINE void set_string_word(size_t n, std::string_view value); INLINE void set_bool_word(size_t n, bool value); INLINE void set_int_word(size_t n, int value); INLINE void set_int64_word(size_t n, int64_t value); diff --git a/dtool/src/prc/configVariableBase.I b/dtool/src/prc/configVariableBase.I index e57bceeb213..962b161384f 100644 --- a/dtool/src/prc/configVariableBase.I +++ b/dtool/src/prc/configVariableBase.I @@ -16,7 +16,7 @@ * ConfigVariableFoo derived class. */ INLINE ConfigVariableBase:: -ConfigVariableBase(const std::string &name, +ConfigVariableBase(std::string_view name, ConfigVariableBase::ValueType value_type) : _core(ConfigVariableManager::get_global_ptr()->make_variable(name)) { diff --git a/dtool/src/prc/configVariableBase.cxx b/dtool/src/prc/configVariableBase.cxx index 0b4e728b940..fedcd4f33c0 100644 --- a/dtool/src/prc/configVariableBase.cxx +++ b/dtool/src/prc/configVariableBase.cxx @@ -21,9 +21,9 @@ ConfigVariableBase::Unconstructed *ConfigVariableBase::_unconstructed; * ConfigVariableFoo derived class. */ ConfigVariableBase:: -ConfigVariableBase(const std::string &name, +ConfigVariableBase(std::string_view name, ConfigVariableBase::ValueType value_type, - const std::string &description, int flags) : + std::string_view description, int flags) : _core(ConfigVariableManager::get_global_ptr()->make_variable(name)) { #ifndef NDEBUG diff --git a/dtool/src/prc/configVariableBase.h b/dtool/src/prc/configVariableBase.h index 56ff035e5c2..85a51ef8d65 100644 --- a/dtool/src/prc/configVariableBase.h +++ b/dtool/src/prc/configVariableBase.h @@ -45,9 +45,9 @@ */ class EXPCL_DTOOL_PRC ConfigVariableBase : public ConfigFlags, public MemoryBase { protected: - INLINE ConfigVariableBase(const std::string &name, ValueType type); - ConfigVariableBase(const std::string &name, ValueType type, - const std::string &description, int flags); + INLINE ConfigVariableBase(std::string_view name, ValueType type); + ConfigVariableBase(std::string_view name, ValueType type, + std::string_view description, int flags); INLINE ~ConfigVariableBase(); PUBLISHED: diff --git a/dtool/src/prc/configVariableBool.I b/dtool/src/prc/configVariableBool.I index 8551815e67e..2ee4a9b42b1 100644 --- a/dtool/src/prc/configVariableBool.I +++ b/dtool/src/prc/configVariableBool.I @@ -15,7 +15,7 @@ * */ INLINE ConfigVariableBool:: -ConfigVariableBool(const std::string &name) : +ConfigVariableBool(std::string_view name) : ConfigVariable(name, VT_bool), _local_modified(initial_invalid_cache()) { @@ -26,12 +26,12 @@ ConfigVariableBool(const std::string &name) : * */ INLINE ConfigVariableBool:: -ConfigVariableBool(const std::string &name, bool default_value, - const std::string &description, int flags) : +ConfigVariableBool(std::string_view name, bool default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariable(name, VT_bool, description, flags), #else - ConfigVariable(name, VT_bool, std::string(), flags), + ConfigVariable(name, VT_bool, std::string_view(), flags), #endif _local_modified(initial_invalid_cache()) { @@ -43,12 +43,12 @@ ConfigVariableBool(const std::string &name, bool default_value, * */ INLINE ConfigVariableBool:: -ConfigVariableBool(const std::string &name, const std::string &default_value, - const std::string &description, int flags) : +ConfigVariableBool(std::string_view name, std::string_view default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariable(name, VT_bool, description, flags), #else - ConfigVariable(name, VT_bool, std::string(), flags), + ConfigVariable(name, VT_bool, std::string_view(), flags), #endif _local_modified(initial_invalid_cache()) { diff --git a/dtool/src/prc/configVariableBool.h b/dtool/src/prc/configVariableBool.h index fcde6c6fa0f..5e0b9d202d5 100644 --- a/dtool/src/prc/configVariableBool.h +++ b/dtool/src/prc/configVariableBool.h @@ -22,14 +22,14 @@ */ class EXPCL_DTOOL_PRC ConfigVariableBool : public ConfigVariable { PUBLISHED: - INLINE explicit ConfigVariableBool(const std::string &name); - INLINE explicit ConfigVariableBool(const std::string &name, + INLINE explicit ConfigVariableBool(std::string_view name); + INLINE explicit ConfigVariableBool(std::string_view name, bool default_value, - const std::string &description = std::string(), + std::string_view description = std::string_view(), int flags = 0); - INLINE explicit ConfigVariableBool(const std::string &name, - const std::string &default_value, - const std::string &description = std::string(), + INLINE explicit ConfigVariableBool(std::string_view name, + std::string_view default_value, + std::string_view description = std::string_view(), int flags = 0); INLINE void operator = (bool value); diff --git a/dtool/src/prc/configVariableCore.cxx b/dtool/src/prc/configVariableCore.cxx index 8ae104efd8d..17fbf256f89 100644 --- a/dtool/src/prc/configVariableCore.cxx +++ b/dtool/src/prc/configVariableCore.cxx @@ -31,8 +31,8 @@ using std::string; * ConfigVariableCore. */ ConfigVariableCore:: -ConfigVariableCore(const string &name) : - _name(name), +ConfigVariableCore(std::string name) : + _name(std::move(name)), _is_used(false), _value_type(VT_undefined), _flags(0), @@ -52,8 +52,8 @@ ConfigVariableCore(const string &name) : * pre-defined. */ ConfigVariableCore:: -ConfigVariableCore(const ConfigVariableCore &templ, const string &name) : - _name(name), +ConfigVariableCore(const ConfigVariableCore &templ, std::string name) : + _name(std::move(name)), _is_used(templ._is_used), _value_type(templ._value_type), _description(templ._description), @@ -147,7 +147,7 @@ set_flags(int flags) { * printed. */ void ConfigVariableCore:: -set_description(const string &description) { +set_description(std::string_view description) { if (_value_queried && _description != description) { if ((_flags & F_dconfig) != 0) { // As a special exception, if the flags include F_dconfig, we don't @@ -188,11 +188,11 @@ set_description(const string &description) { * prc file. */ void ConfigVariableCore:: -set_default_value(const string &default_value) { +set_default_value(std::string_view default_value) { if (_default_value == nullptr) { // Defining the default value for the first time. ConfigPage *default_page = ConfigPage::get_default_page(); - _default_value = default_page->make_declaration(this, default_value); + _default_value = default_page->make_declaration(this, std::string(default_value)); } else { // Modifying an existing default value. @@ -201,7 +201,7 @@ set_default_value(const string &default_value) { // when the config variable in question happens to be consulted in // NotifyCategory::out() (for instance, notify-timestamp). string orig_default_value = _default_value->get_string_value(); - _default_value->set_string_value(default_value); + _default_value->set_string_value(std::string(default_value)); if (orig_default_value != default_value) { if ((_flags & F_dconfig) != 0) { diff --git a/dtool/src/prc/configVariableCore.h b/dtool/src/prc/configVariableCore.h index d9dcb7658d7..4fd7596f90c 100644 --- a/dtool/src/prc/configVariableCore.h +++ b/dtool/src/prc/configVariableCore.h @@ -34,8 +34,8 @@ class ConfigDeclaration; */ class EXPCL_DTOOL_PRC ConfigVariableCore : public ConfigFlags, public MemoryBase { private: - ConfigVariableCore(const std::string &name); - ConfigVariableCore(const ConfigVariableCore &templ, const std::string &name); + ConfigVariableCore(std::string name); + ConfigVariableCore(const ConfigVariableCore &templ, std::string name); ~ConfigVariableCore(); PUBLISHED: @@ -52,8 +52,8 @@ class EXPCL_DTOOL_PRC ConfigVariableCore : public ConfigFlags, public MemoryBase void set_value_type(ValueType value_type); void set_flags(int flags); - void set_description(const std::string &description); - void set_default_value(const std::string &default_value); + void set_description(std::string_view description); + void set_default_value(std::string_view default_value); INLINE void set_used(); ConfigDeclaration *make_local_value(); diff --git a/dtool/src/prc/configVariableDouble.I b/dtool/src/prc/configVariableDouble.I index 53a4b847b04..ae932869ce2 100644 --- a/dtool/src/prc/configVariableDouble.I +++ b/dtool/src/prc/configVariableDouble.I @@ -15,7 +15,7 @@ * */ INLINE ConfigVariableDouble:: -ConfigVariableDouble(const std::string &name) : +ConfigVariableDouble(std::string_view name) : ConfigVariable(name, VT_double), _local_modified(initial_invalid_cache()) { @@ -26,12 +26,12 @@ ConfigVariableDouble(const std::string &name) : * */ INLINE ConfigVariableDouble:: -ConfigVariableDouble(const std::string &name, double default_value, - const std::string &description, int flags) : +ConfigVariableDouble(std::string_view name, double default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariable(name, ConfigVariableCore::VT_double, description, flags), #else - ConfigVariable(name, ConfigVariableCore::VT_double, std::string(), flags), + ConfigVariable(name, ConfigVariableCore::VT_double, std::string_view(), flags), #endif _local_modified(initial_invalid_cache()) { @@ -43,12 +43,12 @@ ConfigVariableDouble(const std::string &name, double default_value, * */ INLINE ConfigVariableDouble:: -ConfigVariableDouble(const std::string &name, const std::string &default_value, - const std::string &description, int flags) : +ConfigVariableDouble(std::string_view name, std::string_view default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariable(name, ConfigVariableCore::VT_double, description, flags), #else - ConfigVariable(name, ConfigVariableCore::VT_double, std::string(), flags), + ConfigVariable(name, ConfigVariableCore::VT_double, std::string_view(), flags), #endif _local_modified(initial_invalid_cache()) { diff --git a/dtool/src/prc/configVariableDouble.h b/dtool/src/prc/configVariableDouble.h index 0620433ac8d..c9809866bad 100644 --- a/dtool/src/prc/configVariableDouble.h +++ b/dtool/src/prc/configVariableDouble.h @@ -23,14 +23,14 @@ */ class EXPCL_DTOOL_PRC ConfigVariableDouble : public ConfigVariable { PUBLISHED: - INLINE explicit ConfigVariableDouble(const std::string &name); - INLINE explicit ConfigVariableDouble(const std::string &name, + INLINE explicit ConfigVariableDouble(std::string_view name); + INLINE explicit ConfigVariableDouble(std::string_view name, double default_value, - const std::string &description = std::string(), + std::string_view description = std::string_view(), int flags = 0); - INLINE explicit ConfigVariableDouble(const std::string &name, - const std::string &default_value, - const std::string &description = std::string(), + INLINE explicit ConfigVariableDouble(std::string_view name, + std::string_view default_value, + std::string_view description = std::string_view(), int flags = 0); INLINE void operator = (double value); diff --git a/dtool/src/prc/configVariableEnum.I b/dtool/src/prc/configVariableEnum.I index a13076e7942..8f7de31faa2 100644 --- a/dtool/src/prc/configVariableEnum.I +++ b/dtool/src/prc/configVariableEnum.I @@ -16,12 +16,12 @@ */ template INLINE ConfigVariableEnum:: -ConfigVariableEnum(const std::string &name, EnumType default_value, - const std::string &description, int flags) : +ConfigVariableEnum(std::string_view name, EnumType default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariable(name, ConfigVariableCore::VT_enum, description, flags), #else - ConfigVariable(name, ConfigVariableCore::VT_enum, std::string(), flags), + ConfigVariable(name, ConfigVariableCore::VT_enum, std::string_view(), flags), #endif _got_default_value(true), _default_value(default_value), @@ -36,12 +36,12 @@ ConfigVariableEnum(const std::string &name, EnumType default_value, */ template INLINE ConfigVariableEnum:: -ConfigVariableEnum(const std::string &name, const std::string &default_value, - const std::string &description, int flags) : +ConfigVariableEnum(std::string_view name, const std::string &default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariable(name, ConfigVariableCore::VT_enum, description, flags), #else - ConfigVariable(name, ConfigVariableCore::VT_enum, std::string(), flags), + ConfigVariable(name, ConfigVariableCore::VT_enum, std::string_view(), flags), #endif _got_default_value(true), _default_value(parse_string(default_value)), @@ -160,7 +160,8 @@ set_word(size_t n, EnumType value) { template INLINE EnumType ConfigVariableEnum:: parse_string(const std::string &value) const { - std::istringstream strm(value); + //NB. Change in C++20 when std::istringstream takes a string by std::move. + std::istringstream strm{std::string(value)}; EnumType result; strm >> result; return result; diff --git a/dtool/src/prc/configVariableEnum.h b/dtool/src/prc/configVariableEnum.h index 21cbf493eb9..5ffb6809dd8 100644 --- a/dtool/src/prc/configVariableEnum.h +++ b/dtool/src/prc/configVariableEnum.h @@ -30,11 +30,11 @@ template class ConfigVariableEnum : public ConfigVariable { public: - INLINE ConfigVariableEnum(const std::string &name, EnumType default_value, - const std::string &description = std::string(), + INLINE ConfigVariableEnum(std::string_view name, EnumType default_value, + std::string_view description = std::string_view(), int flags = 0); - INLINE ConfigVariableEnum(const std::string &name, const std::string &default_value, - const std::string &description = std::string(), + INLINE ConfigVariableEnum(std::string_view name, const std::string &default_value, + std::string_view description = std::string_view(), int flags = 0); INLINE ~ConfigVariableEnum(); diff --git a/dtool/src/prc/configVariableFilename.I b/dtool/src/prc/configVariableFilename.I index 56386cc1705..e0506e9c3c4 100644 --- a/dtool/src/prc/configVariableFilename.I +++ b/dtool/src/prc/configVariableFilename.I @@ -15,7 +15,7 @@ * */ INLINE ConfigVariableFilename:: -ConfigVariableFilename(const std::string &name) : +ConfigVariableFilename(std::string_view name) : ConfigVariable(name, VT_filename), _local_modified(initial_invalid_cache()) { @@ -26,12 +26,12 @@ ConfigVariableFilename(const std::string &name) : * */ INLINE ConfigVariableFilename:: -ConfigVariableFilename(const std::string &name, const Filename &default_value, - const std::string &description, int flags) : +ConfigVariableFilename(std::string_view name, const Filename &default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariable(name, VT_filename, description, flags), #else - ConfigVariable(name, VT_filename, std::string(), flags), + ConfigVariable(name, VT_filename, std::string_view(), flags), #endif _local_modified(initial_invalid_cache()) { diff --git a/dtool/src/prc/configVariableFilename.h b/dtool/src/prc/configVariableFilename.h index 1c85cdd6cb3..9e1d5adab56 100644 --- a/dtool/src/prc/configVariableFilename.h +++ b/dtool/src/prc/configVariableFilename.h @@ -26,10 +26,10 @@ */ class EXPCL_DTOOL_PRC ConfigVariableFilename : public ConfigVariable { PUBLISHED: - INLINE explicit ConfigVariableFilename(const std::string &name); - INLINE explicit ConfigVariableFilename(const std::string &name, + INLINE explicit ConfigVariableFilename(std::string_view name); + INLINE explicit ConfigVariableFilename(std::string_view name, const Filename &default_value, - const std::string &description = std::string(), + std::string_view description = std::string_view(), int flags = 0); INLINE void operator = (const Filename &value); diff --git a/dtool/src/prc/configVariableInt.I b/dtool/src/prc/configVariableInt.I index a2c7d644876..aaefbb516a6 100644 --- a/dtool/src/prc/configVariableInt.I +++ b/dtool/src/prc/configVariableInt.I @@ -15,7 +15,7 @@ * */ INLINE ConfigVariableInt:: -ConfigVariableInt(const std::string &name) : +ConfigVariableInt(std::string_view name) : ConfigVariable(name, VT_int), _local_modified(initial_invalid_cache()) { @@ -26,12 +26,12 @@ ConfigVariableInt(const std::string &name) : * */ INLINE ConfigVariableInt:: -ConfigVariableInt(const std::string &name, int default_value, - const std::string &description, int flags) : +ConfigVariableInt(std::string_view name, int default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariable(name, ConfigVariableCore::VT_int, description, flags), #else - ConfigVariable(name, ConfigVariableCore::VT_int, std::string(), flags), + ConfigVariable(name, ConfigVariableCore::VT_int, std::string_view(), flags), #endif _local_modified(initial_invalid_cache()) { @@ -43,12 +43,12 @@ ConfigVariableInt(const std::string &name, int default_value, * */ INLINE ConfigVariableInt:: -ConfigVariableInt(const std::string &name, const std::string &default_value, - const std::string &description, int flags) : +ConfigVariableInt(std::string_view name, std::string_view default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariable(name, ConfigVariableCore::VT_int, description, flags), #else - ConfigVariable(name, ConfigVariableCore::VT_int, std::string(), flags), + ConfigVariable(name, ConfigVariableCore::VT_int, std::string_view(), flags), #endif _local_modified(initial_invalid_cache()) { diff --git a/dtool/src/prc/configVariableInt.h b/dtool/src/prc/configVariableInt.h index f09a3ad8fd1..014834d8842 100644 --- a/dtool/src/prc/configVariableInt.h +++ b/dtool/src/prc/configVariableInt.h @@ -23,14 +23,14 @@ */ class EXPCL_DTOOL_PRC ConfigVariableInt : public ConfigVariable { PUBLISHED: - INLINE explicit ConfigVariableInt(const std::string &name); - INLINE explicit ConfigVariableInt(const std::string &name, + INLINE explicit ConfigVariableInt(std::string_view name); + INLINE explicit ConfigVariableInt(std::string_view name, int default_value, - const std::string &description = std::string(), + std::string_view description = std::string_view(), int flags = 0); - INLINE explicit ConfigVariableInt(const std::string &name, - const std::string &default_value, - const std::string &description = std::string(), + INLINE explicit ConfigVariableInt(std::string_view name, + std::string_view default_value, + std::string_view description = std::string_view(), int flags = 0); INLINE void operator = (int value); diff --git a/dtool/src/prc/configVariableInt64.I b/dtool/src/prc/configVariableInt64.I index 68695a29f6d..311eabf5de0 100644 --- a/dtool/src/prc/configVariableInt64.I +++ b/dtool/src/prc/configVariableInt64.I @@ -15,7 +15,7 @@ * */ INLINE ConfigVariableInt64:: -ConfigVariableInt64(const std::string &name) : +ConfigVariableInt64(std::string_view name) : ConfigVariable(name, VT_int64), _local_modified(initial_invalid_cache()) { @@ -26,12 +26,12 @@ ConfigVariableInt64(const std::string &name) : * */ INLINE ConfigVariableInt64:: -ConfigVariableInt64(const std::string &name, int64_t default_value, - const std::string &description, int flags) : +ConfigVariableInt64(std::string_view name, int64_t default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariable(name, ConfigVariableCore::VT_int64, description, flags), #else - ConfigVariable(name, ConfigVariableCore::VT_int64, std::string(), flags), + ConfigVariable(name, ConfigVariableCore::VT_int64, std::string_view(), flags), #endif _local_modified(initial_invalid_cache()) { @@ -43,12 +43,12 @@ ConfigVariableInt64(const std::string &name, int64_t default_value, * */ INLINE ConfigVariableInt64:: -ConfigVariableInt64(const std::string &name, const std::string &default_value, - const std::string &description, int flags) : +ConfigVariableInt64(std::string_view name, std::string_view default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariable(name, ConfigVariableCore::VT_int64, description, flags), #else - ConfigVariable(name, ConfigVariableCore::VT_int64, std::string(), flags), + ConfigVariable(name, ConfigVariableCore::VT_int64, std::string_view(), flags), #endif _local_modified(initial_invalid_cache()) { diff --git a/dtool/src/prc/configVariableInt64.h b/dtool/src/prc/configVariableInt64.h index 7acce805867..fda0604a72c 100644 --- a/dtool/src/prc/configVariableInt64.h +++ b/dtool/src/prc/configVariableInt64.h @@ -24,14 +24,14 @@ */ class EXPCL_DTOOL_PRC ConfigVariableInt64 : public ConfigVariable { PUBLISHED: - INLINE explicit ConfigVariableInt64(const std::string &name); - INLINE explicit ConfigVariableInt64(const std::string &name, + INLINE explicit ConfigVariableInt64(std::string_view name); + INLINE explicit ConfigVariableInt64(std::string_view name, int64_t default_value, - const std::string &description = std::string(), + std::string_view description = std::string_view(), int flags = 0); - INLINE explicit ConfigVariableInt64(const std::string &name, - const std::string &default_value, - const std::string &description = std::string(), + INLINE explicit ConfigVariableInt64(std::string_view name, + std::string_view default_value, + std::string_view description = std::string_view(), int flags = 0); INLINE void operator = (int64_t value); diff --git a/dtool/src/prc/configVariableList.I b/dtool/src/prc/configVariableList.I index 606d8d47fd3..ce5f1a134d5 100644 --- a/dtool/src/prc/configVariableList.I +++ b/dtool/src/prc/configVariableList.I @@ -22,12 +22,12 @@ INLINE ConfigVariableList:: * */ INLINE ConfigVariableList:: -ConfigVariableList(const std::string &name, - const std::string &description, int flags) : +ConfigVariableList(std::string_view name, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariableBase(name, VT_list, description, flags) #else - ConfigVariableBase(name, VT_list, std::string(), flags) + ConfigVariableBase(name, VT_list, std::string_view(), flags) #endif { // A list variable implicitly defines a default value of the empty string. diff --git a/dtool/src/prc/configVariableList.h b/dtool/src/prc/configVariableList.h index c0128af3748..3cf16c153cd 100644 --- a/dtool/src/prc/configVariableList.h +++ b/dtool/src/prc/configVariableList.h @@ -30,8 +30,8 @@ */ class EXPCL_DTOOL_PRC ConfigVariableList : public ConfigVariableBase { PUBLISHED: - INLINE explicit ConfigVariableList(const std::string &name, - const std::string &description = std::string(), + INLINE explicit ConfigVariableList(std::string_view name, + std::string_view description = std::string_view(), int flags = 0); INLINE ~ConfigVariableList(); diff --git a/dtool/src/prc/configVariableManager.cxx b/dtool/src/prc/configVariableManager.cxx index 8097acae0df..a292b0e930f 100644 --- a/dtool/src/prc/configVariableManager.cxx +++ b/dtool/src/prc/configVariableManager.cxx @@ -46,7 +46,7 @@ ConfigVariableManager:: * that one instead. */ ConfigVariableCore *ConfigVariableManager:: -make_variable(const string &name) { +make_variable(std::string_view name) { VariablesByName::iterator ni; ni = _variables_by_name.find(name); if (ni != _variables_by_name.end()) { @@ -63,15 +63,15 @@ make_variable(const string &name) { const GlobPattern &pattern = (*ti).first; ConfigVariableCore *templ = (*ti).second; if (pattern.matches(name)) { - variable = new ConfigVariableCore(*templ, name); + variable = new ConfigVariableCore(*templ, std::string(name)); } } if (variable == nullptr) { - variable = new ConfigVariableCore(name); + variable = new ConfigVariableCore(std::string(name)); } - _variables_by_name[name] = variable; + _variables_by_name[variable->get_name()] = variable; _variables.push_back(variable); return variable; @@ -97,19 +97,19 @@ make_variable(const string &name) { * glob pattern. */ ConfigVariableCore *ConfigVariableManager:: -make_variable_template(const string &pattern, +make_variable_template(std::string_view pattern, ConfigFlags::ValueType value_type, - const string &default_value, - const string &description, int flags) { + std::string_view default_value, + std::string_view description, int flags) { ConfigVariableCore *core; - GlobPattern gp(pattern); + GlobPattern gp{std::string(pattern)}; VariableTemplates::const_iterator ti = _variable_templates.find(gp); if (ti != _variable_templates.end()) { core = (*ti).second; } else { - core = new ConfigVariableCore(pattern); + core = new ConfigVariableCore(std::string(pattern)); _variable_templates[gp] = core; } diff --git a/dtool/src/prc/configVariableManager.h b/dtool/src/prc/configVariableManager.h index 22c0c6e3f54..3a8d8343ea7 100644 --- a/dtool/src/prc/configVariableManager.h +++ b/dtool/src/prc/configVariableManager.h @@ -34,11 +34,11 @@ class EXPCL_DTOOL_PRC ConfigVariableManager { ~ConfigVariableManager(); PUBLISHED: - ConfigVariableCore *make_variable(const std::string &name); - ConfigVariableCore *make_variable_template(const std::string &pattern, + ConfigVariableCore *make_variable(std::string_view name); + ConfigVariableCore *make_variable_template(std::string_view pattern, ConfigFlags::ValueType type, - const std::string &default_value, - const std::string &description = std::string(), + std::string_view default_value, + std::string_view description = std::string_view(), int flags = 0); @@ -70,7 +70,7 @@ class EXPCL_DTOOL_PRC ConfigVariableManager { typedef std::vector Variables; Variables _variables; - typedef std::map VariablesByName; + typedef std::map> VariablesByName; VariablesByName _variables_by_name; typedef std::map VariableTemplates; diff --git a/dtool/src/prc/configVariableSearchPath.I b/dtool/src/prc/configVariableSearchPath.I index 37c4383c027..3bda4f25521 100644 --- a/dtool/src/prc/configVariableSearchPath.I +++ b/dtool/src/prc/configVariableSearchPath.I @@ -15,12 +15,12 @@ * */ INLINE ConfigVariableSearchPath:: -ConfigVariableSearchPath(const std::string &name, - const std::string &description, int flags) : +ConfigVariableSearchPath(std::string_view name, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariableBase(name, VT_search_path, description, flags), #else - ConfigVariableBase(name, VT_search_path, std::string(), flags), + ConfigVariableBase(name, VT_search_path, std::string_view(), flags), #endif _default_value(Filename(".")), _local_modified(initial_invalid_cache()) @@ -38,13 +38,13 @@ ConfigVariableSearchPath(const std::string &name, * */ INLINE ConfigVariableSearchPath:: -ConfigVariableSearchPath(const std::string &name, +ConfigVariableSearchPath(std::string_view name, const DSearchPath &default_value, - const std::string &description, int flags) : + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariableBase(name, VT_search_path, description, flags), #else - ConfigVariableBase(name, VT_search_path, std::string(), flags), + ConfigVariableBase(name, VT_search_path, std::string_view(), flags), #endif _default_value(default_value), _local_modified(initial_invalid_cache()) @@ -62,13 +62,13 @@ ConfigVariableSearchPath(const std::string &name, * */ INLINE ConfigVariableSearchPath:: -ConfigVariableSearchPath(const std::string &name, - const std::string &default_value, - const std::string &description, int flags) : +ConfigVariableSearchPath(std::string_view name, + std::string_view default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariableBase(name, VT_search_path, description, flags), #else - ConfigVariableBase(name, VT_search_path, std::string(), flags), + ConfigVariableBase(name, VT_search_path, std::string_view(), flags), #endif _default_value(Filename(default_value)), _local_modified(initial_invalid_cache()) @@ -179,7 +179,7 @@ prepend_directory(const Filename &directory) { * search list. */ INLINE void ConfigVariableSearchPath:: -append_path(const std::string &path, const std::string &separator) { +append_path(std::string_view path, std::string_view separator) { _lock.lock(); _postfix.append_path(path, separator); _local_modified = initial_invalid_cache(); diff --git a/dtool/src/prc/configVariableSearchPath.h b/dtool/src/prc/configVariableSearchPath.h index b7cae14eee4..934ab38448a 100644 --- a/dtool/src/prc/configVariableSearchPath.h +++ b/dtool/src/prc/configVariableSearchPath.h @@ -35,16 +35,16 @@ */ class EXPCL_DTOOL_PRC ConfigVariableSearchPath : public ConfigVariableBase { PUBLISHED: - INLINE explicit ConfigVariableSearchPath(const std::string &name, - const std::string &description = std::string(), + INLINE explicit ConfigVariableSearchPath(std::string_view name, + std::string_view description = std::string_view(), int flags = 0); - INLINE explicit ConfigVariableSearchPath(const std::string &name, + INLINE explicit ConfigVariableSearchPath(std::string_view name, const DSearchPath &default_value, - const std::string &description, + std::string_view description, int flags = 0); - INLINE explicit ConfigVariableSearchPath(const std::string &name, - const std::string &default_value, - const std::string &description, + INLINE explicit ConfigVariableSearchPath(std::string_view name, + std::string_view default_value, + std::string_view description, int flags = 0); INLINE ~ConfigVariableSearchPath(); @@ -59,8 +59,8 @@ class EXPCL_DTOOL_PRC ConfigVariableSearchPath : public ConfigVariableBase { INLINE void clear(); INLINE void append_directory(const Filename &directory); INLINE void prepend_directory(const Filename &directory); - INLINE void append_path(const std::string &path, - const std::string &separator = std::string()); + INLINE void append_path(std::string_view path, + std::string_view separator = std::string_view()); INLINE void append_path(const DSearchPath &path); INLINE void prepend_path(const DSearchPath &path); diff --git a/dtool/src/prc/configVariableString.I b/dtool/src/prc/configVariableString.I index 062439553d1..122dc85137d 100644 --- a/dtool/src/prc/configVariableString.I +++ b/dtool/src/prc/configVariableString.I @@ -15,7 +15,7 @@ * */ INLINE ConfigVariableString:: -ConfigVariableString(const std::string &name) : +ConfigVariableString(std::string_view name) : ConfigVariable(name, VT_string), _local_modified(initial_invalid_cache()) { @@ -26,12 +26,12 @@ ConfigVariableString(const std::string &name) : * */ INLINE ConfigVariableString:: -ConfigVariableString(const std::string &name, const std::string &default_value, - const std::string &description, int flags) : +ConfigVariableString(std::string_view name, std::string_view default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariable(name, VT_string, description, flags), #else - ConfigVariable(name, VT_string, std::string(), flags), + ConfigVariable(name, VT_string, std::string_view(), flags), #endif _local_modified(initial_invalid_cache()) { @@ -43,8 +43,8 @@ ConfigVariableString(const std::string &name, const std::string &default_value, * Reassigns the variable's local value. */ INLINE void ConfigVariableString:: -operator = (const std::string &value) { - set_value(value); +operator = (std::string value) { + set_value(std::move(value)); } /** @@ -55,6 +55,14 @@ operator const std::string & () const { return get_value(); } +/** + * Returns the variable's value. + */ +INLINE ConfigVariableString:: +operator std::string_view () const { + return get_value(); +} + /** * */ @@ -116,8 +124,8 @@ operator < (const std::string &other) const { * Reassigns the variable's local value. */ INLINE void ConfigVariableString:: -set_value(const std::string &value) { - set_string_value(value); +set_value(std::string value) { + set_string_value(std::move(value)); } /** @@ -157,7 +165,7 @@ get_word(size_t n) const { * variable's overall value. */ INLINE void ConfigVariableString:: -set_word(size_t n, const std::string &value) { +set_word(size_t n, std::string_view value) { set_string_word(n, value); } diff --git a/dtool/src/prc/configVariableString.h b/dtool/src/prc/configVariableString.h index 9ae662b6beb..ee6eaef4dbf 100644 --- a/dtool/src/prc/configVariableString.h +++ b/dtool/src/prc/configVariableString.h @@ -22,14 +22,15 @@ */ class EXPCL_DTOOL_PRC ConfigVariableString : public ConfigVariable { PUBLISHED: - INLINE explicit ConfigVariableString(const std::string &name); - INLINE explicit ConfigVariableString(const std::string &name, - const std::string &default_value, - const std::string &description = std::string(), + INLINE explicit ConfigVariableString(std::string_view name); + INLINE explicit ConfigVariableString(std::string_view name, + std::string_view default_value, + std::string_view description = std::string_view(), int flags = 0); - INLINE void operator = (const std::string &value); + INLINE void operator = (std::string value); INLINE operator const std::string & () const; + INLINE operator std::string_view () const; // These methods help the ConfigVariableString act like a C++ string object. INLINE const char *c_str() const; @@ -42,14 +43,14 @@ class EXPCL_DTOOL_PRC ConfigVariableString : public ConfigVariable { INLINE bool operator != (const std::string &other) const; INLINE bool operator < (const std::string &other) const; - INLINE void set_value(const std::string &value); + INLINE void set_value(std::string value); INLINE const std::string &get_value() const; INLINE std::string get_default_value() const; MAKE_PROPERTY(value, get_value, set_value); MAKE_PROPERTY(default_value, get_default_value); INLINE std::string get_word(size_t n) const; - INLINE void set_word(size_t n, const std::string &value); + INLINE void set_word(size_t n, std::string_view value); INLINE bool __bool__() const; diff --git a/dtool/src/prc/emscriptenLogStream.h b/dtool/src/prc/emscriptenLogStream.h index 4af8a973d58..626f2d88aba 100644 --- a/dtool/src/prc/emscriptenLogStream.h +++ b/dtool/src/prc/emscriptenLogStream.h @@ -41,7 +41,7 @@ class EmscriptenLogStream : public std::ostream { void write_char(char c); int _flags; - string _data; + std::string _data; }; EmscriptenLogStream(int flags); diff --git a/dtool/src/prc/encryptStream.I b/dtool/src/prc/encryptStream.I index f93e6c01a3b..4eeb66e13d9 100644 --- a/dtool/src/prc/encryptStream.I +++ b/dtool/src/prc/encryptStream.I @@ -23,7 +23,7 @@ IDecryptStream() : std::istream(&_buf) { */ INLINE IDecryptStream:: IDecryptStream(std::istream *source, bool owns_source, - const std::string &password) : std::istream(&_buf) { + std::string_view password) : std::istream(&_buf) { open(source, owns_source, password); } @@ -31,7 +31,7 @@ IDecryptStream(std::istream *source, bool owns_source, * */ INLINE IDecryptStream &IDecryptStream:: -open(std::istream *source, bool owns_source, const std::string &password) { +open(std::istream *source, bool owns_source, std::string_view password) { clear((ios_iostate)0); _buf.open_read(source, owns_source, password); return *this; @@ -83,7 +83,7 @@ OEncryptStream() : std::ostream(&_buf) { * */ INLINE OEncryptStream:: -OEncryptStream(std::ostream *dest, bool owns_dest, const std::string &password) : +OEncryptStream(std::ostream *dest, bool owns_dest, std::string_view password) : std::ostream(&_buf) { open(dest, owns_dest, password); @@ -93,7 +93,7 @@ OEncryptStream(std::ostream *dest, bool owns_dest, const std::string &password) * */ INLINE OEncryptStream &OEncryptStream:: -open(std::ostream *dest, bool owns_dest, const std::string &password) { +open(std::ostream *dest, bool owns_dest, std::string_view password) { clear((ios_iostate)0); _buf.open_write(dest, owns_dest, password); return *this; @@ -143,8 +143,8 @@ get_iteration_count() const { * code, but open() will fail. */ INLINE void OEncryptStream:: -set_algorithm(const std::string &algorithm) { - _buf.set_algorithm(algorithm); +set_algorithm(std::string algorithm) { + _buf.set_algorithm(std::move(algorithm)); } /** diff --git a/dtool/src/prc/encryptStream.h b/dtool/src/prc/encryptStream.h index 6605ea59988..39846911d81 100644 --- a/dtool/src/prc/encryptStream.h +++ b/dtool/src/prc/encryptStream.h @@ -35,14 +35,14 @@ class EXPCL_DTOOL_PRC IDecryptStream : public std::istream { PUBLISHED: INLINE IDecryptStream(); INLINE explicit IDecryptStream(std::istream *source, bool owns_source, - const std::string &password); + std::string_view password); #if _MSC_VER >= 1800 INLINE IDecryptStream(const IDecryptStream ©) = delete; #endif INLINE IDecryptStream &open(std::istream *source, bool owns_source, - const std::string &password); + std::string_view password); INLINE IDecryptStream &close(); INLINE const std::string &get_algorithm() const; @@ -73,14 +73,14 @@ class EXPCL_DTOOL_PRC OEncryptStream : public std::ostream { PUBLISHED: INLINE OEncryptStream(); INLINE explicit OEncryptStream(std::ostream *dest, bool owns_dest, - const std::string &password); + std::string_view password); #if _MSC_VER >= 1800 INLINE OEncryptStream(const OEncryptStream ©) = delete; #endif INLINE OEncryptStream &open(std::ostream *dest, bool owns_dest, - const std::string &password); + std::string_view password); INLINE OEncryptStream &close(); public: @@ -89,7 +89,7 @@ class EXPCL_DTOOL_PRC OEncryptStream : public std::ostream { INLINE int get_iteration_count() const; PUBLISHED: - INLINE void set_algorithm(const std::string &algorithm); + INLINE void set_algorithm(std::string algorithm); INLINE void set_key_length(int key_length); INLINE void set_iteration_count(int iteration_count); diff --git a/dtool/src/prc/encryptStreamBuf.I b/dtool/src/prc/encryptStreamBuf.I index b840625fc14..1582915264b 100644 --- a/dtool/src/prc/encryptStreamBuf.I +++ b/dtool/src/prc/encryptStreamBuf.I @@ -21,8 +21,8 @@ * code, but open_write() will fail. */ INLINE void EncryptStreamBuf:: -set_algorithm(const std::string &algorithm) { - _algorithm = algorithm; +set_algorithm(std::string algorithm) { + _algorithm = std::move(algorithm); } /** diff --git a/dtool/src/prc/encryptStreamBuf.cxx b/dtool/src/prc/encryptStreamBuf.cxx index a7020296f6d..11435a5bb47 100644 --- a/dtool/src/prc/encryptStreamBuf.cxx +++ b/dtool/src/prc/encryptStreamBuf.cxx @@ -101,17 +101,10 @@ EncryptStreamBuf() { _read_overflow_buffer = nullptr; _in_read_overflow_buffer = 0; -#ifdef PHAVE_IOSTREAM char *buf = new char[4096]; char *ebuf = buf + 4096; setg(buf, ebuf, ebuf); setp(buf, ebuf); - -#else - allocate(); - setg(base(), ebuf(), ebuf()); - setp(base(), ebuf()); -#endif } /** @@ -122,16 +115,14 @@ EncryptStreamBuf:: close_read(); close_write(); -#ifdef PHAVE_IOSTREAM delete[] eback(); -#endif } /** * */ void EncryptStreamBuf:: -open_read(std::istream *source, bool owns_source, const std::string &password) { +open_read(std::istream *source, bool owns_source, std::string_view password) { OpenSSL_add_all_algorithms(); _source = source; @@ -263,7 +254,7 @@ close_read() { * */ void EncryptStreamBuf:: -open_write(std::ostream *dest, bool owns_dest, const std::string &password) { +open_write(std::ostream *dest, bool owns_dest, std::string_view password) { OpenSSL_add_all_algorithms(); close_write(); diff --git a/dtool/src/prc/encryptStreamBuf.h b/dtool/src/prc/encryptStreamBuf.h index 2922aec9393..80a703e894f 100644 --- a/dtool/src/prc/encryptStreamBuf.h +++ b/dtool/src/prc/encryptStreamBuf.h @@ -29,13 +29,13 @@ class EXPCL_DTOOL_PRC EncryptStreamBuf : public std::streambuf { EncryptStreamBuf(); virtual ~EncryptStreamBuf(); - void open_read(std::istream *source, bool owns_source, const std::string &password); + void open_read(std::istream *source, bool owns_source, std::string_view password); void close_read(); - void open_write(std::ostream *dest, bool owns_dest, const std::string &password); + void open_write(std::ostream *dest, bool owns_dest, std::string_view password); void close_write(); - INLINE void set_algorithm(const std::string &algorithm); + INLINE void set_algorithm(std::string algorithm); INLINE const std::string &get_algorithm() const; INLINE void set_key_length(int key_length); diff --git a/dtool/src/prc/notify.cxx b/dtool/src/prc/notify.cxx index 34f36d93365..a936ddb5254 100644 --- a/dtool/src/prc/notify.cxx +++ b/dtool/src/prc/notify.cxx @@ -129,13 +129,9 @@ get_literal_flag() { static ios_fmtflags flag; if (!got_flag) { -#ifndef PHAVE_IOSTREAM - flag = std::ios::bitalloc(); -#else - // We lost bitalloc in the new iostream? Ok, this feature will just be - // disabled for now. No big deal. + // bitalloc was removed from the standard iostream library, so this + // feature is disabled. No big deal. flag = (ios_fmtflags)0; -#endif got_flag = true; } @@ -199,20 +195,23 @@ get_top_category() { * indicate this is a top-level Category. */ NotifyCategory *Notify:: -get_category(const string &basename, NotifyCategory *parent_category) { +get_category(std::string_view basename, NotifyCategory *parent_category) { // The string should not contain colons. nassertr(basename.find(':') == string::npos, nullptr); string fullname; if (parent_category != nullptr) { - fullname = parent_category->get_fullname() + ":" + basename; + fullname = parent_category->get_fullname(); + fullname += ':'; + fullname += basename; } else { // The parent_category is NULL. If basename is empty, that means we refer // to the very top-level category (with an empty fullname); otherwise, // it's a new category just below that top level. if (!basename.empty()) { parent_category = get_top_category(); - fullname = ":" + basename; + fullname = ":"; + fullname += basename; } } @@ -225,7 +224,7 @@ get_category(const string &basename, NotifyCategory *parent_category) { if (inserted) { // If we just inserted a new record, then we have to create a new Category // pointer. Otherwise, there was already one created from before. - category = new NotifyCategory(fullname, basename, parent_category); + category = new NotifyCategory(std::move(fullname), basename, parent_category); } return category; @@ -238,7 +237,7 @@ get_category(const string &basename, NotifyCategory *parent_category) { * parent. If the parent Category does not already exist, it will be created. */ NotifyCategory *Notify:: -get_category(const string &basename, const string &parent_fullname) { +get_category(std::string_view basename, std::string_view parent_fullname) { return get_category(basename, get_category(parent_fullname)); } @@ -250,7 +249,7 @@ get_category(const string &basename, const string &parent_fullname) { * handy. */ NotifyCategory *Notify:: -get_category(const string &fullname) { +get_category(std::string_view fullname) { Categories::const_iterator ci; ci = _categories.find(fullname); if (ci != _categories.end()) { @@ -260,7 +259,7 @@ get_category(const string &fullname) { // No such Category; create one. First identify the parent name, based on // the rightmost colon. NotifyCategory *parent_category = nullptr; - string basename = fullname; + std::string_view basename = fullname; size_t colon = fullname.rfind(':'); if (colon != string::npos) { @@ -315,7 +314,7 @@ null() { * implicit newline, to the Notify output stream. */ void Notify:: -write_string(const string &str) { +write_string(std::string_view str) { out() << str << "\n"; } @@ -600,10 +599,10 @@ write_backtrace(void **trace, int size) { * matches. */ NotifySeverity Notify:: -string_severity(const string &str) { +string_severity(std::string_view str) { // Convert the string to lowercase for a case-insensitive comparison. string lstring; - for (string::const_iterator si = str.begin(); + for (std::string_view::const_iterator si = str.begin(); si != str.end(); ++si) { lstring += (char)tolower(*si); diff --git a/dtool/src/prc/notifyCategory.cxx b/dtool/src/prc/notifyCategory.cxx index 3a0b161bf27..47224cdd382 100644 --- a/dtool/src/prc/notifyCategory.cxx +++ b/dtool/src/prc/notifyCategory.cxx @@ -30,9 +30,9 @@ long NotifyCategory::_server_delta = 0; * */ NotifyCategory:: -NotifyCategory(const std::string &fullname, const std::string &basename, +NotifyCategory(std::string fullname, std::string_view basename, NotifyCategory *parent) : - _fullname(fullname), + _fullname(std::move(fullname)), _basename(basename), _parent(parent), _severity(get_config_name(), NS_unspecified, diff --git a/dtool/src/prc/notifyCategory.h b/dtool/src/prc/notifyCategory.h index e9a11afed95..b2baed5dab1 100644 --- a/dtool/src/prc/notifyCategory.h +++ b/dtool/src/prc/notifyCategory.h @@ -31,7 +31,7 @@ */ class EXPCL_DTOOL_PRC NotifyCategory : public MemoryBase, public ConfigFlags { private: - NotifyCategory(const std::string &fullname, const std::string &basename, + NotifyCategory(std::string fullname, std::string_view basename, NotifyCategory *parent); PUBLISHED: diff --git a/dtool/src/prc/pnotify.h b/dtool/src/prc/pnotify.h index 2c949f1e1a5..78660284d60 100644 --- a/dtool/src/prc/pnotify.h +++ b/dtool/src/prc/pnotify.h @@ -61,16 +61,16 @@ class EXPCL_DTOOL_PRC Notify { INLINE void clear_assert_failed(); NotifyCategory *get_top_category(); - NotifyCategory *get_category(const std::string &basename, + NotifyCategory *get_category(std::string_view basename, NotifyCategory *parent_category); - NotifyCategory *get_category(const std::string &basename, - const std::string &parent_fullname); - NotifyCategory *get_category(const std::string &fullname); + NotifyCategory *get_category(std::string_view basename, + std::string_view parent_fullname); + NotifyCategory *get_category(std::string_view fullname); static std::ostream &out(NotifySeverity severity); static std::ostream &out(); static std::ostream &null(); - static void write_string(const std::string &str); + static void write_string(std::string_view str); static Notify *ptr(); public: @@ -83,7 +83,7 @@ class EXPCL_DTOOL_PRC Notify { static void write_backtrace(void **trace, int size); - static NotifySeverity string_severity(const std::string &string); + static NotifySeverity string_severity(std::string_view string); static void config_initialized(); @@ -98,7 +98,7 @@ class EXPCL_DTOOL_PRC Notify { // This shouldn't be a pmap, since it might be invoked before we initialize // the global malloc pointers. - typedef std::map Categories; + typedef std::map> Categories; Categories _categories; #if defined(ANDROID) diff --git a/dtool/src/prc/streamWriter.I b/dtool/src/prc/streamWriter.I index 0a5594357cb..f0b4db1fcf3 100644 --- a/dtool/src/prc/streamWriter.I +++ b/dtool/src/prc/streamWriter.I @@ -280,7 +280,7 @@ add_be_float64(PN_float64 value) { * followed by n bytes. */ INLINE void StreamWriter:: -add_string(const std::string &str) { +add_string(std::string_view str) { // The max sendable length for a string is 2^16. nassertv(str.length() <= (uint16_t)0xffff); @@ -295,7 +295,7 @@ add_string(const std::string &str) { * Adds a variable-length string to the stream, using a 32-bit length field. */ INLINE void StreamWriter:: -add_string32(const std::string &str) { +add_string32(std::string_view str) { // Strings always are preceded by their length add_uint32((uint32_t)str.length()); @@ -323,7 +323,7 @@ add_z_string(std::string str) { * greater than the requested size, this will silently truncate the string. */ INLINE void StreamWriter:: -add_fixed_string(const std::string &str, size_t size) { +add_fixed_string(std::string_view str, size_t size) { if (str.length() < size) { append_data(str); pad_bytes(size - str.length()); @@ -345,7 +345,7 @@ append_data(const void *data, size_t size) { * Appends some more raw data to the end of the streamWriter. */ INLINE void StreamWriter:: -append_data(const std::string &data) { +append_data(std::string_view data) { append_data(data.data(), data.length()); } @@ -362,6 +362,6 @@ flush() { * to sys.stderr and/or sys.stdout in Python. */ INLINE void StreamWriter:: -write(const std::string &data) { +write(std::string_view data) { append_data(data.data(), data.length()); } diff --git a/dtool/src/prc/streamWriter.h b/dtool/src/prc/streamWriter.h index 24d1b8298d3..b639cc910e1 100644 --- a/dtool/src/prc/streamWriter.h +++ b/dtool/src/prc/streamWriter.h @@ -64,21 +64,21 @@ class EXPCL_DTOOL_PRC StreamWriter { BLOCKING INLINE void add_be_float32(float value); BLOCKING INLINE void add_be_float64(PN_float64 value); - BLOCKING INLINE void add_string(const std::string &str); - BLOCKING INLINE void add_string32(const std::string &str); + BLOCKING INLINE void add_string(std::string_view str); + BLOCKING INLINE void add_string32(std::string_view str); BLOCKING INLINE void add_z_string(std::string str); - BLOCKING INLINE void add_fixed_string(const std::string &str, size_t size); + BLOCKING INLINE void add_fixed_string(std::string_view str, size_t size); BLOCKING void pad_bytes(size_t size); PY_EXTENSION(void append_data(PyObject *data)); BLOCKING INLINE void flush(); - BLOCKING INLINE void write(const std::string &str); + BLOCKING INLINE void write(std::string_view str); public: BLOCKING INLINE void append_data(const void *data, size_t size); - BLOCKING INLINE void append_data(const std::string &data); + BLOCKING INLINE void append_data(std::string_view data); private: std::ostream *_out; diff --git a/dtool/src/prckeys/makePrcKey.cxx b/dtool/src/prckeys/makePrcKey.cxx index f6598cab22c..29b7f65954e 100644 --- a/dtool/src/prckeys/makePrcKey.cxx +++ b/dtool/src/prckeys/makePrcKey.cxx @@ -72,7 +72,7 @@ output_ssl_errors() { * string. */ void -output_c_string(std::ostream &out, const string &string_name, +output_c_string(std::ostream &out, std::string_view string_name, size_t index, BIO *mbio) { char *data_ptr; size_t data_size = BIO_get_mem_data(mbio, &data_ptr); diff --git a/dtool/src/prckeys/signPrcFile_src.cxx b/dtool/src/prckeys/signPrcFile_src.cxx index f349626ec18..55cb3db5329 100644 --- a/dtool/src/prckeys/signPrcFile_src.cxx +++ b/dtool/src/prckeys/signPrcFile_src.cxx @@ -64,7 +64,7 @@ output_ssl_errors() { * Reads a single line of the prc file. */ void -read_prc_line(const string &line, string &data) { +read_prc_line(std::string_view line, string &data) { // Strip out lines with this prefix. These are from a previous signature. if (line.substr(0, 3) == "##!") { return; diff --git a/makepanda/makepackage.py b/makepanda/makepackage.py index 169f98b2660..049edd19fc8 100755 --- a/makepanda/makepackage.py +++ b/makepanda/makepackage.py @@ -664,7 +664,7 @@ def write_script(component, phase, contents): dist.write('\n') dist.write(' Panda3D SDK %s\n' % (version)) dist.write(' \n') - dist.write(' \n') + dist.write(' \n') dist.write(' \n') dist.write(' \n') dist.write(' %s\n' % ReadFile("doc/LICENSE")) diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 139e51eb0ed..d0e33329036 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -358,7 +358,7 @@ def parseopts(args): if tuple(OSX_ARCHS) == ('arm64',): os.environ["MACOSX_DEPLOYMENT_TARGET"] = "11.0" else: - os.environ["MACOSX_DEPLOYMENT_TARGET"] = "10.9" + os.environ["MACOSX_DEPLOYMENT_TARGET"] = "10.13" ######################################################################## ## @@ -421,10 +421,8 @@ def parseopts(args): if arch_tag == 'arm64': PLATFORM = 'macosx-11.0-' + arch_tag - elif sys.version_info >= (3, 13): - PLATFORM = 'macosx-10.13-' + arch_tag else: - PLATFORM = 'macosx-10.9-' + arch_tag + PLATFORM = 'macosx-10.13-' + arch_tag elif target == 'linux' and (os.path.isfile("/lib/libc-2.5.so") or os.path.isfile("/lib64/libc-2.5.so")) and os.path.isdir("/opt/python"): # This is manylinux1. A bit of a sloppy check, though. @@ -817,7 +815,7 @@ def parseopts(args): not os.path.isfile(SDK.get("MACOSX", "") + '/usr/lib/libstdc++.6.0.9.dylib'): # Also, we can't target FMOD Ex on 10.14 and above if not PkgSkip("FMODEX"): - Warn("thirdparty package fmodex requires one of MacOSX 10.9-10.13 SDK, excluding from build") + Warn("thirdparty package fmodex requires macOS 10.13 SDK, excluding from build") PkgDisable("FMODEX") #if not PkgSkip("PYTHON"): @@ -1196,7 +1194,7 @@ def CompileCxx(obj,src,opts): # Set the minimum version to Windows Vista. cmd += "/DWINVER=0x600 " - cmd += "/Fo" + obj + " /nologo /c" + cmd += "/Fo" + obj + " /nologo /c /std:c++17" if GetTargetArch() == 'x86': # x86 (32 bit) MSVC 2015+ defaults to /arch:SSE2 if not PkgSkip("SSE2") or 'SSE2' in opts: # x86 with SSE2 @@ -1322,7 +1320,7 @@ def CompileCxx(obj,src,opts): if (COMPILER=="GCC"): if (src.endswith(".c")): cmd = GetCC() +' -fPIC -c -o ' + obj - else: cmd = GetCXX()+' -std=gnu++14 -ftemplate-depth-70 -fPIC -c -o ' + obj + else: cmd = GetCXX()+' -std=gnu++17 -ftemplate-depth-70 -fPIC -c -o ' + obj for (opt, dir) in INCDIRECTORIES: if (opt=="ALWAYS") or (opt in opts): cmd += ' -I' + BracketNameWithQuotes(dir) for (opt, dir) in FRAMEWORKDIRECTORIES: @@ -1345,7 +1343,7 @@ def CompileCxx(obj,src,opts): if tuple(OSX_ARCHS) == ('arm64',): cmd += " -mmacosx-version-min=11.0" else: - cmd += " -mmacosx-version-min=10.9" + cmd += " -mmacosx-version-min=10.13" # Use libc++ to enable C++11 features. cmd += " -stdlib=libc++" @@ -1884,10 +1882,8 @@ def CompileLink(dll, obj, opts): if tuple(OSX_ARCHS) == ('arm64',): cmd += " -mmacosx-version-min=11.0" - elif sys.version_info >= (3, 13) and 'PYTHON' in opts: - cmd += " -mmacosx-version-min=10.13" else: - cmd += " -mmacosx-version-min=10.9" + cmd += " -mmacosx-version-min=10.13" # Use libc++ to enable C++11 features. cmd += " -stdlib=libc++" @@ -2396,7 +2392,6 @@ def CompileAnything(target, inputs, opts, progress = None): ("PHAVE_GETOPT_H", 'UNDEF', '1'), ("PHAVE_LINUX_INPUT_H", 'UNDEF', '1'), ("IOCTL_TERMINAL_WIDTH", 'UNDEF', '1'), - ("HAVE_IOS_TYPEDEFS", '1', '1'), ("HAVE_IOS_BINARY", '1', '1'), ("STATIC_INIT_GETENV", '1', 'UNDEF'), ("HAVE_PROC_SELF_EXE", 'UNDEF', '1'), @@ -2411,16 +2406,12 @@ def CompileAnything(target, inputs, opts, progress = None): ("GLOBAL_ARGV", '__argv', 'UNDEF'), ("GLOBAL_ARGC", '__argc', 'UNDEF'), ("PHAVE_IO_H", '1', 'UNDEF'), - ("PHAVE_IOSTREAM", '1', '1'), ("PHAVE_STRING_H", 'UNDEF', '1'), ("PHAVE_LIMITS_H", 'UNDEF', '1'), - ("PHAVE_STDLIB_H", 'UNDEF', '1'), ("PHAVE_MALLOC_H", '1', '1'), ("PHAVE_SYS_MALLOC_H", 'UNDEF', 'UNDEF'), ("PHAVE_ALLOCA_H", 'UNDEF', '1'), ("PHAVE_LOCALE_H", 'UNDEF', '1'), - ("PHAVE_SSTREAM", '1', '1'), - ("PHAVE_NEW", '1', '1'), ("PHAVE_SYS_TYPES_H", '1', '1'), ("PHAVE_SYS_TIME_H", 'UNDEF', '1'), ("PHAVE_UNISTD_H", 'UNDEF', '1'), @@ -2428,7 +2419,6 @@ def CompileAnything(target, inputs, opts, progress = None): ("PHAVE_GLOB_H", 'UNDEF', '1'), ("PHAVE_DIRENT_H", 'UNDEF', '1'), ("PHAVE_UCONTEXT_H", 'UNDEF', '1'), - ("PHAVE_STDINT_H", '1', '1'), ("PHAVE_EXECINFO_H", 'UNDEF', '1'), ("HAVE_RTTI", '1', '1'), ("HAVE_X11", 'UNDEF', '1'), diff --git a/makepanda/makepandacore.py b/makepanda/makepandacore.py index 20c646f5665..1f526427615 100644 --- a/makepanda/makepandacore.py +++ b/makepanda/makepandacore.py @@ -593,8 +593,8 @@ def GetInterrogateDir(): return INTERROGATE_DIR dir = os.path.join(GetOutputDir(), "tmp", "interrogate") - if not os.path.isdir(os.path.join(dir, "panda3d_interrogate-0.8.1.dist-info")): - oscmd("\"%s\" -m pip install --force-reinstall --upgrade -t \"%s\" panda3d-interrogate==0.8.1" % (sys.executable, dir)) + if not os.path.isdir(os.path.join(dir, "panda3d_interrogate-0.11.2.dist-info")): + oscmd("\"%s\" -m pip install --force-reinstall --upgrade -t \"%s\" panda3d-interrogate==0.11.2" % (sys.executable, dir)) INTERROGATE_DIR = dir @@ -2478,7 +2478,7 @@ def SdkLocateMacOSX(archs = []): sdk_versions = [] if 'arm64' not in archs: # Prefer pre-10.14 for now so that we can keep building FMOD. - sdk_versions += ["10.13", "10.12"] + sdk_versions += ["10.13"] sdk_versions += ["15.5", "15.4", "15.2", "15.1", "15.0", "14.5", "14.4", "14.2", "14.0", "13.3", "13.1", "13.0", "12.3", "11.3", "11.1", "11.0"] diff --git a/panda/src/android/pnmFileTypeAndroid.cxx b/panda/src/android/pnmFileTypeAndroid.cxx index 535cc305639..c00de55b305 100644 --- a/panda/src/android/pnmFileTypeAndroid.cxx +++ b/panda/src/android/pnmFileTypeAndroid.cxx @@ -84,7 +84,7 @@ has_magic_number() const { * returns NULL. */ PNMReader *PNMFileTypeAndroid:: -make_reader(std::istream *file, bool owns_file, const std::string &magic_number) { +make_reader(std::istream *file, bool owns_file, std::string_view magic_number) { return new Reader(this, file, owns_file, magic_number); } diff --git a/panda/src/android/pnmFileTypeAndroid.h b/panda/src/android/pnmFileTypeAndroid.h index 3501f312395..9501c10a5ef 100644 --- a/panda/src/android/pnmFileTypeAndroid.h +++ b/panda/src/android/pnmFileTypeAndroid.h @@ -46,13 +46,13 @@ class PNMFileTypeAndroid : public PNMFileType { virtual bool has_magic_number() const; virtual PNMReader *make_reader(std::istream *file, bool owns_file = true, - const std::string &magic_number = std::string()); + std::string_view magic_number = std::string_view()); virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true); public: class Reader : public PNMReader { public: - Reader(PNMFileType *type, std::istream *file, bool owns_file, std::string magic_number); + Reader(PNMFileType *type, std::istream *file, bool owns_file, std::string_view magic_number); virtual ~Reader(); virtual void prepare_read(); diff --git a/panda/src/android/pnmFileTypeAndroidReader.cxx b/panda/src/android/pnmFileTypeAndroidReader.cxx index 7feceffa1c3..a5502f7bf8d 100644 --- a/panda/src/android/pnmFileTypeAndroidReader.cxx +++ b/panda/src/android/pnmFileTypeAndroidReader.cxx @@ -60,14 +60,13 @@ static void conv_rgba4444(uint16_t in, xel &rgb, xelval &alpha) { * */ PNMFileTypeAndroid::Reader:: -Reader(PNMFileType *type, std::istream *file, bool owns_file, std::string magic_number) : +Reader(PNMFileType *type, std::istream *file, bool owns_file, std::string_view magic_number) : PNMReader(type, file, owns_file), _bitmap(nullptr) { // Hope we can putback() more than one character. - for (std::string::reverse_iterator mi = magic_number.rbegin(); - mi != magic_number.rend(); ++mi) { + for (auto mi = magic_number.rbegin(); mi != magic_number.rend(); ++mi) { _file->putback(*mi); - }; + } if (_file->fail()) { android_cat.error() << "Unable to put back magic number.\n"; diff --git a/panda/src/androiddisplay/androidGraphicsPipe.cxx b/panda/src/androiddisplay/androidGraphicsPipe.cxx index e78c53878f0..e0e7ca8c7ab 100644 --- a/panda/src/androiddisplay/androidGraphicsPipe.cxx +++ b/panda/src/androiddisplay/androidGraphicsPipe.cxx @@ -101,7 +101,7 @@ AndroidGraphicsPipe::get_preferred_window_thread() const { * Creates a new window on the pipe, if possible. */ PT(GraphicsOutput) AndroidGraphicsPipe:: -make_output(const std::string &name, +make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -135,7 +135,7 @@ make_output(const std::string &name, ((flags&BF_can_bind_every)!=0)) { return nullptr; } - return new AndroidGraphicsWindow(engine, this, name, fb_prop, win_prop, + return new AndroidGraphicsWindow(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } @@ -194,7 +194,7 @@ make_output(const std::string &name, } } - return new eglGraphicsBuffer(engine, this, name, fb_prop, win_prop, + return new eglGraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } diff --git a/panda/src/androiddisplay/androidGraphicsPipe.h b/panda/src/androiddisplay/androidGraphicsPipe.h index 8767f1ee233..afa49e5ae12 100644 --- a/panda/src/androiddisplay/androidGraphicsPipe.h +++ b/panda/src/androiddisplay/androidGraphicsPipe.h @@ -49,7 +49,7 @@ class AndroidGraphicsPipe : public GraphicsPipe { virtual PreferredWindowThread get_preferred_window_thread() const; protected: - virtual PT(GraphicsOutput) make_output(const std::string &name, + virtual PT(GraphicsOutput) make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/androiddisplay/androidGraphicsWindow.cxx b/panda/src/androiddisplay/androidGraphicsWindow.cxx index e88d6dae6ab..3d66886af7a 100644 --- a/panda/src/androiddisplay/androidGraphicsWindow.cxx +++ b/panda/src/androiddisplay/androidGraphicsWindow.cxx @@ -39,13 +39,13 @@ TypeHandle AndroidGraphicsWindow::_type_handle; */ AndroidGraphicsWindow:: AndroidGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host), + GraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host), _primary_pointer_down(false), _mouse_button_state(0) { diff --git a/panda/src/androiddisplay/androidGraphicsWindow.h b/panda/src/androiddisplay/androidGraphicsWindow.h index 1f622924fa7..0493434826e 100644 --- a/panda/src/androiddisplay/androidGraphicsWindow.h +++ b/panda/src/androiddisplay/androidGraphicsWindow.h @@ -33,7 +33,7 @@ struct android_app; class AndroidGraphicsWindow : public GraphicsWindow { public: AndroidGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/audio/audioSound.cxx b/panda/src/audio/audioSound.cxx index 6dc948d95b0..afe44b0fd0a 100644 --- a/panda/src/audio/audioSound.cxx +++ b/panda/src/audio/audioSound.cxx @@ -223,9 +223,10 @@ get_raw_comment() const { * i.e. "author". Case-sensitive. */ bool AudioSound:: -has_comment(const std::string &key) const { +has_comment(std::string_view key) const { for (const std::string &st : get_raw_comment()) { - if (st.rfind(key + "=", 0) == 0) { + if (st.size() > key.size() && st[key.size()] == '=' && + st.compare(0, key.size(), key) == 0) { return true; } } @@ -237,10 +238,11 @@ has_comment(const std::string &key) const { * returns an empty string. */ std::string AudioSound:: -get_comment(const std::string &key) const { +get_comment(std::string_view key) const { for (const std::string &st : get_raw_comment()) { - if (st.rfind(key + "=", 0) == 0) { - return st.substr(key.length() + 1); + if (st.size() > key.size() && st[key.size()] == '=' && + st.compare(0, key.size(), key) == 0) { + return st.substr(key.size() + 1); } } return ""; diff --git a/panda/src/audio/audioSound.h b/panda/src/audio/audioSound.h index e55d25ccc5f..13921d8d2fa 100644 --- a/panda/src/audio/audioSound.h +++ b/panda/src/audio/audioSound.h @@ -30,7 +30,7 @@ class EXPCL_PANDA_AUDIO AudioSound : public TypedReferenceCount { // Construct a near-identical copy of this object on the heap and // return a pointer to the new copy. Currently only implemented for OpenAL. - virtual AudioSound *make_copy() const; + [[nodiscard]] virtual AudioSound *make_copy() const; // For best compatibility, set the loop_count, volume, and balance, prior to // calling play(). You may set them while they're playing, but it's @@ -88,7 +88,7 @@ class EXPCL_PANDA_AUDIO AudioSound : public TypedReferenceCount { // Set (or clear) the event that will be thrown when the sound finishes // playing. To clear the event, pass an empty string. - virtual void set_finished_event(const std::string& event) = 0; + virtual void set_finished_event(std::string event) = 0; virtual const std::string& get_finished_event() const = 0; // There is no set_name(), this is intentional. @@ -146,8 +146,8 @@ class EXPCL_PANDA_AUDIO AudioSound : public TypedReferenceCount { enum SoundStatus { BAD, READY, PLAYING }; virtual SoundStatus status() const = 0; - bool has_comment(const std::string &key) const; - std::string get_comment(const std::string &key) const; + bool has_comment(std::string_view key) const; + std::string get_comment(std::string_view key) const; MAKE_MAP_PROPERTY(comments, has_comment, get_comment); virtual const vector_string& get_raw_comment() const; diff --git a/panda/src/audio/nullAudioSound.cxx b/panda/src/audio/nullAudioSound.cxx index 88b9bd8f571..4b5b220f505 100644 --- a/panda/src/audio/nullAudioSound.cxx +++ b/panda/src/audio/nullAudioSound.cxx @@ -110,7 +110,7 @@ bool NullAudioSound::get_active() const { return false; } -void NullAudioSound::set_finished_event(const string& event) { +void NullAudioSound::set_finished_event(string event) { // Intentionally blank. } diff --git a/panda/src/audio/nullAudioSound.h b/panda/src/audio/nullAudioSound.h index 234047977a7..e8c54046daf 100644 --- a/panda/src/audio/nullAudioSound.h +++ b/panda/src/audio/nullAudioSound.h @@ -57,7 +57,7 @@ class EXPCL_PANDA_AUDIO NullAudioSound : public AudioSound { void set_active(bool); bool get_active() const; - void set_finished_event(const std::string& event); + void set_finished_event(std::string event); const std::string& get_finished_event() const; const std::string& get_name() const; diff --git a/panda/src/audiotraits/fmodAudioSound.cxx b/panda/src/audiotraits/fmodAudioSound.cxx index 5c43c8a5945..0682106ad26 100644 --- a/panda/src/audiotraits/fmodAudioSound.cxx +++ b/panda/src/audiotraits/fmodAudioSound.cxx @@ -905,7 +905,7 @@ finished() { * */ void FmodAudioSound:: -set_finished_event(const string& event) { +set_finished_event(string event) { audio_error("set_finished_event: not implemented under FMOD-EX"); } diff --git a/panda/src/audiotraits/fmodAudioSound.h b/panda/src/audiotraits/fmodAudioSound.h index 7762b413d31..39c0c7c550a 100644 --- a/panda/src/audiotraits/fmodAudioSound.h +++ b/panda/src/audiotraits/fmodAudioSound.h @@ -137,7 +137,7 @@ class EXPCL_FMOD_AUDIO FmodAudioSound : public AudioSound { bool get_active() const; void finished(); - void set_finished_event(const std::string& event); + void set_finished_event(std::string event); const std::string& get_finished_event() const; private: diff --git a/panda/src/audiotraits/openalAudioSound.cxx b/panda/src/audiotraits/openalAudioSound.cxx index ca7b81908af..eda617137e2 100644 --- a/panda/src/audiotraits/openalAudioSound.cxx +++ b/panda/src/audiotraits/openalAudioSound.cxx @@ -1131,8 +1131,8 @@ get_active() const { * */ void OpenALAudioSound:: -set_finished_event(const std::string& event) { - _finished_event = event; +set_finished_event(std::string event) { + _finished_event = std::move(event); } /** diff --git a/panda/src/audiotraits/openalAudioSound.h b/panda/src/audiotraits/openalAudioSound.h index 53c65b53c00..49091c9535b 100644 --- a/panda/src/audiotraits/openalAudioSound.h +++ b/panda/src/audiotraits/openalAudioSound.h @@ -78,7 +78,7 @@ class EXPCL_OPENAL_AUDIO OpenALAudioSound final : public AudioSound { // This is the string that throw_event() will throw when the sound finishes // playing. It is not triggered when the sound is stopped with stop(). - void set_finished_event(const std::string& event); + void set_finished_event(std::string event); const std::string& get_finished_event() const; const std::string &get_name() const; diff --git a/panda/src/bullet/bulletWorld.cxx b/panda/src/bullet/bulletWorld.cxx index f422df2f861..33202b23234 100644 --- a/panda/src/bullet/bulletWorld.cxx +++ b/panda/src/bullet/bulletWorld.cxx @@ -24,8 +24,6 @@ #include "collideMask.h" #include "lightMutexHolder.h" -#define clamp(x, x_min, x_max) std::max(std::min(x, x_max), x_min) - using std::endl; using std::istream; using std::ostream; @@ -226,7 +224,7 @@ do_physics(PN_stdfloat dt, int max_substeps, PN_stdfloat stepsize) { _pstat_physics.start(); - int num_substeps = clamp(int(dt / stepsize), 1, max_substeps); + int num_substeps = std::max(std::min(int(dt / stepsize), max_substeps), 1); // Synchronize Panda to Bullet _pstat_p2b.start(); diff --git a/panda/src/chan/animBundle.I b/panda/src/chan/animBundle.I index c52608f852e..f07e04ba88b 100644 --- a/panda/src/chan/animBundle.I +++ b/panda/src/chan/animBundle.I @@ -15,7 +15,7 @@ * */ INLINE AnimBundle:: -AnimBundle(const std::string &name, PN_stdfloat fps, int num_frames) : AnimGroup(name) { +AnimBundle(std::string name, PN_stdfloat fps, int num_frames) : AnimGroup(std::move(name)) { _fps = fps; _num_frames = num_frames; _root = this; diff --git a/panda/src/chan/animBundle.h b/panda/src/chan/animBundle.h index 0605381bff4..b0f0b159919 100644 --- a/panda/src/chan/animBundle.h +++ b/panda/src/chan/animBundle.h @@ -31,7 +31,7 @@ class EXPCL_PANDA_CHAN AnimBundle : public AnimGroup { AnimBundle(AnimGroup *parent, const AnimBundle ©); PUBLISHED: - INLINE explicit AnimBundle(const std::string &name, PN_stdfloat fps, int num_frames); + INLINE explicit AnimBundle(std::string name, PN_stdfloat fps, int num_frames); PT(AnimBundle) copy_bundle() const; diff --git a/panda/src/chan/animBundleNode.I b/panda/src/chan/animBundleNode.I index ced5541dbeb..b191e529a0c 100644 --- a/panda/src/chan/animBundleNode.I +++ b/panda/src/chan/animBundleNode.I @@ -17,8 +17,8 @@ * the appropriate type, and pass it up to this constructor. */ INLINE AnimBundleNode:: -AnimBundleNode(const std::string &name, AnimBundle *bundle) : - PandaNode(name), +AnimBundleNode(std::string name, AnimBundle *bundle) : + PandaNode(std::move(name)), _bundle(bundle) { } diff --git a/panda/src/chan/animBundleNode.h b/panda/src/chan/animBundleNode.h index 2a334036ab6..781be7018f0 100644 --- a/panda/src/chan/animBundleNode.h +++ b/panda/src/chan/animBundleNode.h @@ -28,7 +28,7 @@ */ class EXPCL_PANDA_CHAN AnimBundleNode : public PandaNode { PUBLISHED: - INLINE explicit AnimBundleNode(const std::string &name, AnimBundle *bundle); + INLINE explicit AnimBundleNode(std::string name, AnimBundle *bundle); protected: INLINE AnimBundleNode(); diff --git a/panda/src/chan/animChannel.I b/panda/src/chan/animChannel.I index 921536f0b38..e776879a7ef 100644 --- a/panda/src/chan/animChannel.I +++ b/panda/src/chan/animChannel.I @@ -26,8 +26,8 @@ TypeHandle AnimChannel::_type_handle; */ template INLINE AnimChannel:: -AnimChannel(const std::string &name) - : AnimChannelBase(name) { +AnimChannel(std::string name) + : AnimChannelBase(std::move(name)) { } /** @@ -48,8 +48,8 @@ AnimChannel(AnimGroup *parent, const AnimChannel ©) : */ template INLINE AnimChannel:: -AnimChannel(AnimGroup *parent, const std::string &name) - : AnimChannelBase(parent, name) { +AnimChannel(AnimGroup *parent, std::string name) + : AnimChannelBase(parent, std::move(name)) { } /** diff --git a/panda/src/chan/animChannel.h b/panda/src/chan/animChannel.h index eb024ea31e4..aa44072d182 100644 --- a/panda/src/chan/animChannel.h +++ b/panda/src/chan/animChannel.h @@ -30,12 +30,12 @@ class AnimChannel : public AnimChannelBase { // The default constructor is protected: don't try to create an AnimChannel // without a parent. To create an AnimChannel hierarchy, you must first // create an AnimBundle, and use that to create any subsequent children. - INLINE AnimChannel(const std::string &name = ""); + INLINE AnimChannel(std::string name = ""); INLINE AnimChannel(AnimGroup *parent, const AnimChannel ©); public: typedef typename SwitchType::ValueType ValueType; - INLINE AnimChannel(AnimGroup *parent, const std::string &name); + INLINE AnimChannel(AnimGroup *parent, std::string name); INLINE ~AnimChannel(); PUBLISHED: diff --git a/panda/src/chan/animChannelBase.I b/panda/src/chan/animChannelBase.I index 0e86c51027f..8772ca45565 100644 --- a/panda/src/chan/animChannelBase.I +++ b/panda/src/chan/animChannelBase.I @@ -17,8 +17,8 @@ * created as part of a hierarchy. */ INLINE AnimChannelBase:: -AnimChannelBase(const std::string &name) - : AnimGroup(name) +AnimChannelBase(std::string name) + : AnimGroup(std::move(name)) { _last_frame = -1; } @@ -40,8 +40,8 @@ AnimChannelBase(AnimGroup *parent, const AnimChannelBase ©) : * in the previously-created hierarchy. */ INLINE AnimChannelBase:: -AnimChannelBase(AnimGroup *parent, const std::string &name) - : AnimGroup(parent, name) +AnimChannelBase(AnimGroup *parent, std::string name) + : AnimGroup(parent, std::move(name)) { _last_frame = -1; } diff --git a/panda/src/chan/animChannelBase.h b/panda/src/chan/animChannelBase.h index 71493de31d7..1c512fc64a4 100644 --- a/panda/src/chan/animChannelBase.h +++ b/panda/src/chan/animChannelBase.h @@ -32,11 +32,11 @@ class EXPCL_PANDA_CHAN AnimChannelBase : public AnimGroup { // The default constructor is protected: don't try to create an AnimChannel // without a parent. To create an AnimChannel hierarchy, you must first // create an AnimBundle, and use that to create any subsequent children. - INLINE AnimChannelBase(const std::string &name = ""); + INLINE AnimChannelBase(std::string name = ""); INLINE AnimChannelBase(AnimGroup *parent, const AnimChannelBase ©); public: - INLINE AnimChannelBase(AnimGroup *parent, const std::string &name); + INLINE AnimChannelBase(AnimGroup *parent, std::string name); virtual bool has_changed(int last_frame, double last_frac, int this_frame, double this_frac); diff --git a/panda/src/chan/animChannelFixed.I b/panda/src/chan/animChannelFixed.I index c430366945b..658e15b81ee 100644 --- a/panda/src/chan/animChannelFixed.I +++ b/panda/src/chan/animChannelFixed.I @@ -32,8 +32,8 @@ AnimChannelFixed(AnimGroup *parent, const AnimChannelFixed ©) : */ template INLINE AnimChannelFixed:: -AnimChannelFixed(const std::string &name, const ValueType &value) - : AnimChannel(name), +AnimChannelFixed(std::string name, const ValueType &value) + : AnimChannel(std::move(name)), _value(value) { } diff --git a/panda/src/chan/animChannelFixed.h b/panda/src/chan/animChannelFixed.h index a2317d257b4..ec1db08505b 100644 --- a/panda/src/chan/animChannelFixed.h +++ b/panda/src/chan/animChannelFixed.h @@ -34,7 +34,7 @@ class AnimChannelFixed : public AnimChannel { INLINE AnimChannelFixed(AnimGroup *parent, const AnimChannelFixed ©); public: - INLINE AnimChannelFixed(const std::string &name, const ValueType &value); + INLINE AnimChannelFixed(std::string name, const ValueType &value); virtual bool has_changed(int last_frame, double last_frac, int this_frame, double this_frac); diff --git a/panda/src/chan/animChannelMatrixDynamic.cxx b/panda/src/chan/animChannelMatrixDynamic.cxx index 731dcf8215a..4b7037cb31b 100644 --- a/panda/src/chan/animChannelMatrixDynamic.cxx +++ b/panda/src/chan/animChannelMatrixDynamic.cxx @@ -49,8 +49,8 @@ AnimChannelMatrixDynamic(AnimGroup *parent, const AnimChannelMatrixDynamic © * */ AnimChannelMatrixDynamic:: -AnimChannelMatrixDynamic(const std::string &name) - : AnimChannelMatrix(name) +AnimChannelMatrixDynamic(std::string name) + : AnimChannelMatrix(std::move(name)) { _value = TransformState::make_identity(); _last_value = nullptr; // This is impossible; thus, has_changed() will diff --git a/panda/src/chan/animChannelMatrixDynamic.h b/panda/src/chan/animChannelMatrixDynamic.h index 449819f367b..fd6af9804d6 100644 --- a/panda/src/chan/animChannelMatrixDynamic.h +++ b/panda/src/chan/animChannelMatrixDynamic.h @@ -36,7 +36,7 @@ class EXPCL_PANDA_CHAN AnimChannelMatrixDynamic : public AnimChannelMatrix { AnimChannelMatrixDynamic(AnimGroup *parent, const AnimChannelMatrixDynamic ©); public: - AnimChannelMatrixDynamic(const std::string &name); + AnimChannelMatrixDynamic(std::string name); virtual bool has_changed(int last_frame, double last_frac, int this_frame, double this_frac); diff --git a/panda/src/chan/animChannelMatrixFixed.cxx b/panda/src/chan/animChannelMatrixFixed.cxx index d5f0ef3d841..c7d5b8dc5f7 100644 --- a/panda/src/chan/animChannelMatrixFixed.cxx +++ b/panda/src/chan/animChannelMatrixFixed.cxx @@ -34,8 +34,8 @@ AnimChannelMatrixFixed(AnimGroup *parent, const AnimChannelMatrixFixed ©) : * */ AnimChannelMatrixFixed:: -AnimChannelMatrixFixed(const std::string &name, const LVecBase3 &pos, const LVecBase3 &hpr, const LVecBase3 &scale) : - AnimChannel(name), +AnimChannelMatrixFixed(std::string name, const LVecBase3 &pos, const LVecBase3 &hpr, const LVecBase3 &scale) : + AnimChannel(std::move(name)), _pos(pos), _hpr(hpr), _scale(scale) { } diff --git a/panda/src/chan/animChannelMatrixFixed.h b/panda/src/chan/animChannelMatrixFixed.h index 8b6e06c8aba..31b17c8d9ab 100644 --- a/panda/src/chan/animChannelMatrixFixed.h +++ b/panda/src/chan/animChannelMatrixFixed.h @@ -28,7 +28,7 @@ class EXPCL_PANDA_CHAN AnimChannelMatrixFixed : public AnimChannel Controls; Controls _controls; - typedef pmap ControlsByName; + typedef pmap> ControlsByName; ControlsByName _controls_by_name; AnimControl *_last_started_control; diff --git a/panda/src/chan/animGroup.cxx b/panda/src/chan/animGroup.cxx index 5c9200ff70a..cea5c1d376b 100644 --- a/panda/src/chan/animGroup.cxx +++ b/panda/src/chan/animGroup.cxx @@ -35,8 +35,8 @@ TypeHandle AnimGroup::_type_handle; * create an AnimBundle, and use that to create any subsequent children. */ AnimGroup:: -AnimGroup(const string &name) : - Namable(name), +AnimGroup(std::string name) : + Namable(std::move(name)), _children(get_class_type()), _root(nullptr) { @@ -65,8 +65,8 @@ AnimGroup(AnimGroup *parent, const AnimGroup ©) : * to delete it subsequently is to delete the entire hierarchy. */ AnimGroup:: -AnimGroup(AnimGroup *parent, const string &name) : - Namable(name), +AnimGroup(AnimGroup *parent, std::string name) : + Namable(std::move(name)), _children(get_class_type()) { nassertv(parent != nullptr); @@ -108,10 +108,8 @@ get_child(int n) const { * find_child(). */ AnimGroup *AnimGroup:: -get_child_named(const string &name) const { - Children::const_iterator ci; - for (ci = _children.begin(); ci != _children.end(); ++ci) { - AnimGroup *child = (*ci); +get_child_named(std::string_view name) const { + for (AnimGroup *child : _children) { if (child->get_name() == name) { return child; } @@ -126,10 +124,8 @@ get_child_named(const string &name) const { * this AnimGroup; see also get_child_named(). */ AnimGroup *AnimGroup:: -find_child(const string &name) const { - Children::const_iterator ci; - for (ci = _children.begin(); ci != _children.end(); ++ci) { - AnimGroup *child = (*ci); +find_child(std::string_view name) const { + for (AnimGroup *child : _children) { if (child->get_name() == name) { return child; } diff --git a/panda/src/chan/animGroup.h b/panda/src/chan/animGroup.h index f49bb88fcf9..a7c2bb0c907 100644 --- a/panda/src/chan/animGroup.h +++ b/panda/src/chan/animGroup.h @@ -32,20 +32,20 @@ class FactoryParams; */ class EXPCL_PANDA_CHAN AnimGroup : public TypedWritableReferenceCount, public Namable { protected: - AnimGroup(const std::string &name = ""); + AnimGroup(std::string name = ""); AnimGroup(AnimGroup *parent, const AnimGroup ©); PUBLISHED: // This is the normal AnimGroup constructor. - explicit AnimGroup(AnimGroup *parent, const std::string &name); + explicit AnimGroup(AnimGroup *parent, std::string name); virtual ~AnimGroup(); int get_num_children() const; AnimGroup *get_child(int n) const; MAKE_SEQ(get_children, get_num_children, get_child); - AnimGroup *get_child_named(const std::string &name) const; - AnimGroup *find_child(const std::string &name) const; + AnimGroup *get_child_named(std::string_view name) const; + AnimGroup *find_child(std::string_view name) const; void sort_descendants(); MAKE_SEQ_PROPERTY(children, get_num_children, get_child); @@ -60,7 +60,7 @@ class EXPCL_PANDA_CHAN AnimGroup : public TypedWritableReferenceCount, public Na protected: void write_descendants(std::ostream &out, int indent_level) const; - virtual AnimGroup *make_copy(AnimGroup *parent) const; + [[nodiscard]] virtual AnimGroup *make_copy(AnimGroup *parent) const; PT(AnimGroup) copy_subtree(AnimGroup *parent) const; protected: diff --git a/panda/src/chan/animPreloadTable.cxx b/panda/src/chan/animPreloadTable.cxx index 43958482b3f..519dca00851 100644 --- a/panda/src/chan/animPreloadTable.cxx +++ b/panda/src/chan/animPreloadTable.cxx @@ -60,7 +60,7 @@ get_num_anims() const { * Filename::get_basename_wo_extension(). */ int AnimPreloadTable:: -find_anim(const std::string &basename) const { +find_anim(std::string_view basename) const { consider_sort(); AnimRecord record; record._basename = basename; @@ -96,13 +96,13 @@ remove_anim(int n) { * See find_anim(). This will invalidate existing index numbers. */ void AnimPreloadTable:: -add_anim(const std::string &basename, PN_stdfloat base_frame_rate, int num_frames) { +add_anim(std::string basename, PN_stdfloat base_frame_rate, int num_frames) { AnimRecord record; - record._basename = basename; + record._basename = std::move(basename); record._base_frame_rate = base_frame_rate; record._num_frames = num_frames; - _anims.push_back(record); + _anims.push_back(std::move(record)); _needs_sort = true; } diff --git a/panda/src/chan/animPreloadTable.h b/panda/src/chan/animPreloadTable.h index e4fd64915bf..b27d7752a1d 100644 --- a/panda/src/chan/animPreloadTable.h +++ b/panda/src/chan/animPreloadTable.h @@ -52,7 +52,7 @@ class EXPCL_PANDA_CHAN AnimPreloadTable : public CopyOnWriteObject { virtual ~AnimPreloadTable(); int get_num_anims() const; - int find_anim(const std::string &basename) const; + int find_anim(std::string_view basename) const; INLINE std::string get_basename(int n) const; INLINE PN_stdfloat get_base_frame_rate(int n) const; @@ -60,7 +60,7 @@ class EXPCL_PANDA_CHAN AnimPreloadTable : public CopyOnWriteObject { void clear_anims(); void remove_anim(int n); - void add_anim(const std::string &basename, PN_stdfloat base_frame_rate, int num_frames); + void add_anim(std::string basename, PN_stdfloat base_frame_rate, int num_frames); void add_anims_from(const AnimPreloadTable *other); virtual void output(std::ostream &out) const; diff --git a/panda/src/chan/bindAnimRequest.cxx b/panda/src/chan/bindAnimRequest.cxx index 637f44831de..a69fccdf73f 100644 --- a/panda/src/chan/bindAnimRequest.cxx +++ b/panda/src/chan/bindAnimRequest.cxx @@ -22,7 +22,7 @@ TypeHandle BindAnimRequest::_type_handle; * */ BindAnimRequest:: -BindAnimRequest(const std::string &name, +BindAnimRequest(std::string name, const Filename &filename, const LoaderOptions &options, Loader *loader, AnimControl *control, int hierarchy_match_flags, diff --git a/panda/src/chan/bindAnimRequest.h b/panda/src/chan/bindAnimRequest.h index f3d0314b6a4..d5e1577e37f 100644 --- a/panda/src/chan/bindAnimRequest.h +++ b/panda/src/chan/bindAnimRequest.h @@ -30,7 +30,7 @@ class EXPCL_PANDA_CHAN BindAnimRequest : public ModelLoadRequest { ALLOC_DELETED_CHAIN(BindAnimRequest); PUBLISHED: - explicit BindAnimRequest(const std::string &name, + explicit BindAnimRequest(std::string name, const Filename &filename, const LoaderOptions &options, Loader *loader, diff --git a/panda/src/chan/movingPart.I b/panda/src/chan/movingPart.I index 9b0d35e9c8d..778355eafa5 100644 --- a/panda/src/chan/movingPart.I +++ b/panda/src/chan/movingPart.I @@ -43,9 +43,9 @@ MovingPart(const MovingPart ©) : */ template INLINE MovingPart:: -MovingPart(PartGroup *parent, const std::string &name, +MovingPart(PartGroup *parent, std::string name, const ValueType &default_value) : - MovingPartBase(parent, name), + MovingPartBase(parent, std::move(name)), _value(default_value), _default_value(default_value) { diff --git a/panda/src/chan/movingPart.h b/panda/src/chan/movingPart.h index 8673a271d67..c9944e7dade 100644 --- a/panda/src/chan/movingPart.h +++ b/panda/src/chan/movingPart.h @@ -33,7 +33,7 @@ class MovingPart : public MovingPartBase { INLINE MovingPart(const MovingPart ©); public: - INLINE MovingPart(PartGroup *parent, const std::string &name, + INLINE MovingPart(PartGroup *parent, std::string name, const ValueType &default_value); virtual TypeHandle get_value_type() const; diff --git a/panda/src/chan/movingPartBase.cxx b/panda/src/chan/movingPartBase.cxx index 563c8aa7945..7d286e5bfff 100644 --- a/panda/src/chan/movingPartBase.cxx +++ b/panda/src/chan/movingPartBase.cxx @@ -26,8 +26,8 @@ TypeHandle MovingPartBase::_type_handle; * */ MovingPartBase:: -MovingPartBase(PartGroup *parent, const std::string &name) : - PartGroup(parent, name), +MovingPartBase(PartGroup *parent, std::string name) : + PartGroup(parent, std::move(name)), _effective_control(nullptr) { } diff --git a/panda/src/chan/movingPartBase.h b/panda/src/chan/movingPartBase.h index bc23ccee969..20fe0d260a7 100644 --- a/panda/src/chan/movingPartBase.h +++ b/panda/src/chan/movingPartBase.h @@ -34,7 +34,7 @@ class EXPCL_PANDA_CHAN MovingPartBase : public PartGroup { INLINE MovingPartBase(const MovingPartBase ©); public: - MovingPartBase(PartGroup *parent, const std::string &name); + MovingPartBase(PartGroup *parent, std::string name); PUBLISHED: INLINE int get_max_bound() const; diff --git a/panda/src/chan/movingPartMatrix.I b/panda/src/chan/movingPartMatrix.I index f9432b312e2..c991a7c4ced 100644 --- a/panda/src/chan/movingPartMatrix.I +++ b/panda/src/chan/movingPartMatrix.I @@ -24,9 +24,9 @@ MovingPartMatrix(const MovingPartMatrix ©) : * */ INLINE MovingPartMatrix:: -MovingPartMatrix(PartGroup *parent, const std::string &name, +MovingPartMatrix(PartGroup *parent, std::string name, const LMatrix4 &default_value) - : MovingPart(parent, name, default_value) { + : MovingPart(parent, std::move(name), default_value) { } /** diff --git a/panda/src/chan/movingPartMatrix.h b/panda/src/chan/movingPartMatrix.h index 7e8aaa0e90a..d12ff8ce210 100644 --- a/panda/src/chan/movingPartMatrix.h +++ b/panda/src/chan/movingPartMatrix.h @@ -31,7 +31,7 @@ class EXPCL_PANDA_CHAN MovingPartMatrix : public MovingPart INLINE MovingPartMatrix(const MovingPartMatrix ©); public: - INLINE MovingPartMatrix(PartGroup *parent, const std::string &name, + INLINE MovingPartMatrix(PartGroup *parent, std::string name, const LMatrix4 &default_value); virtual ~MovingPartMatrix(); diff --git a/panda/src/chan/movingPartScalar.I b/panda/src/chan/movingPartScalar.I index e67dad05625..e185c2083a8 100644 --- a/panda/src/chan/movingPartScalar.I +++ b/panda/src/chan/movingPartScalar.I @@ -24,9 +24,9 @@ MovingPartScalar(const MovingPartScalar ©) : * */ INLINE MovingPartScalar:: -MovingPartScalar(PartGroup *parent, const std::string &name, +MovingPartScalar(PartGroup *parent, std::string name, PN_stdfloat default_value) - : MovingPart(parent, name, default_value) { + : MovingPart(parent, std::move(name), default_value) { } /** diff --git a/panda/src/chan/movingPartScalar.h b/panda/src/chan/movingPartScalar.h index 8d3666ed874..4f31a46b6c6 100644 --- a/panda/src/chan/movingPartScalar.h +++ b/panda/src/chan/movingPartScalar.h @@ -30,7 +30,7 @@ class EXPCL_PANDA_CHAN MovingPartScalar : public MovingPart INLINE MovingPartScalar(const MovingPartScalar ©); public: - INLINE MovingPartScalar(PartGroup *parent, const std::string &name, + INLINE MovingPartScalar(PartGroup *parent, std::string name, PN_stdfloat default_value = 0); virtual ~MovingPartScalar(); diff --git a/panda/src/chan/partBundle.cxx b/panda/src/chan/partBundle.cxx index 076482cdd97..de29c80b33d 100644 --- a/panda/src/chan/partBundle.cxx +++ b/panda/src/chan/partBundle.cxx @@ -69,8 +69,8 @@ PartBundle(const PartBundle ©) : * get created when a PartBundleNode is created. */ PartBundle:: -PartBundle(const string &name) : - PartGroup(name) +PartBundle(std::string name) : + PartGroup(std::move(name)) { _update_delay = 0.0; } @@ -368,7 +368,7 @@ wait_pending() { * child is not a joint (or slider) or does not exist. */ bool PartBundle:: -freeze_joint(const string &joint_name, const TransformState *transform) { +freeze_joint(std::string_view joint_name, const TransformState *transform) { PartGroup *child = find_child(joint_name); if (child == nullptr) { return false; @@ -389,7 +389,7 @@ freeze_joint(const string &joint_name, const TransformState *transform) { * child is not a joint (or slider) or does not exist. */ bool PartBundle:: -freeze_joint(const string &joint_name, const LVecBase3 &pos, const LVecBase3 &hpr, const LVecBase3 &scale) { +freeze_joint(std::string_view joint_name, const LVecBase3 &pos, const LVecBase3 &hpr, const LVecBase3 &scale) { PartGroup *child = find_child(joint_name); if (child == nullptr) { return false; @@ -410,7 +410,7 @@ freeze_joint(const string &joint_name, const LVecBase3 &pos, const LVecBase3 &hp * child is not a joint (or slider) or does not exist. */ bool PartBundle:: -freeze_joint(const string &joint_name, PN_stdfloat value) { +freeze_joint(std::string_view joint_name, PN_stdfloat value) { PartGroup *child = find_child(joint_name); if (child == nullptr) { return false; @@ -432,7 +432,7 @@ freeze_joint(const string &joint_name, PN_stdfloat value) { * child is not a joint (or slider) or does not exist. */ bool PartBundle:: -control_joint(const string &joint_name, PandaNode *node) { +control_joint(std::string_view joint_name, PandaNode *node) { PartGroup *child = find_child(joint_name); if (child == nullptr) { return false; @@ -453,7 +453,7 @@ control_joint(const string &joint_name, PandaNode *node) { * previously controlled or frozen, or it does not exist. */ bool PartBundle:: -release_joint(const string &joint_name) { +release_joint(std::string_view joint_name) { PartGroup *child = find_child(joint_name); if (child == nullptr) { return false; diff --git a/panda/src/chan/partBundle.h b/panda/src/chan/partBundle.h index 19f716ee7f4..eab66b5670b 100644 --- a/panda/src/chan/partBundle.h +++ b/panda/src/chan/partBundle.h @@ -55,7 +55,7 @@ class EXPCL_PANDA_CHAN PartBundle : public PartGroup { PartBundle(const PartBundle ©); PUBLISHED: - explicit PartBundle(const std::string &name = ""); + explicit PartBundle(std::string name = ""); virtual PartGroup *make_copy() const; INLINE CPT(AnimPreloadTable) get_anim_preload() const; @@ -136,11 +136,11 @@ class EXPCL_PANDA_CHAN PartBundle : public PartGroup { bool allow_async); void wait_pending(); - bool freeze_joint(const std::string &joint_name, const TransformState *transform); - bool freeze_joint(const std::string &joint_name, const LVecBase3 &pos, const LVecBase3 &hpr, const LVecBase3 &scale); - bool freeze_joint(const std::string &joint_name, PN_stdfloat value); - bool control_joint(const std::string &joint_name, PandaNode *node); - bool release_joint(const std::string &joint_name); + bool freeze_joint(std::string_view joint_name, const TransformState *transform); + bool freeze_joint(std::string_view joint_name, const LVecBase3 &pos, const LVecBase3 &hpr, const LVecBase3 &scale); + bool freeze_joint(std::string_view joint_name, PN_stdfloat value); + bool control_joint(std::string_view joint_name, PandaNode *node); + bool release_joint(std::string_view joint_name); bool update(); bool force_update(); diff --git a/panda/src/chan/partBundleNode.I b/panda/src/chan/partBundleNode.I index d1e2e5597fb..450465575e3 100644 --- a/panda/src/chan/partBundleNode.I +++ b/panda/src/chan/partBundleNode.I @@ -17,8 +17,8 @@ * the appropriate type, and pass it up to this constructor. */ INLINE PartBundleNode:: -PartBundleNode(const std::string &name, PartBundle *bundle) : - PandaNode(name) +PartBundleNode(std::string name, PartBundle *bundle) : + PandaNode(std::move(name)) { add_bundle(bundle); } diff --git a/panda/src/chan/partBundleNode.h b/panda/src/chan/partBundleNode.h index bdfad481734..ee0908514b8 100644 --- a/panda/src/chan/partBundleNode.h +++ b/panda/src/chan/partBundleNode.h @@ -34,7 +34,7 @@ */ class EXPCL_PANDA_CHAN PartBundleNode : public PandaNode { PUBLISHED: - INLINE explicit PartBundleNode(const std::string &name, PartBundle *bundle); + INLINE explicit PartBundleNode(std::string name, PartBundle *bundle); protected: INLINE PartBundleNode(); diff --git a/panda/src/chan/partGroup.I b/panda/src/chan/partGroup.I index 250cd195eb4..bfc76ef3b09 100644 --- a/panda/src/chan/partGroup.I +++ b/panda/src/chan/partGroup.I @@ -16,8 +16,8 @@ * You should normally use the non-default constructor, below. */ INLINE PartGroup:: -PartGroup(const std::string &name) : - Namable(name), +PartGroup(std::string name) : + Namable(std::move(name)), _children(get_class_type()) { } diff --git a/panda/src/chan/partGroup.cxx b/panda/src/chan/partGroup.cxx index 2be55b7d682..6f2add18af3 100644 --- a/panda/src/chan/partGroup.cxx +++ b/panda/src/chan/partGroup.cxx @@ -34,8 +34,8 @@ TypeHandle PartGroup::_type_handle; * to delete it subsequently is to delete the entire hierarchy. */ PartGroup:: -PartGroup(PartGroup *parent, const std::string &name) : - Namable(name), +PartGroup(PartGroup *parent, std::string name) : + Namable(std::move(name)), _children(get_class_type()) { nassertv(parent != nullptr); @@ -115,10 +115,8 @@ get_child(int n) const { * find_child(). */ PartGroup *PartGroup:: -get_child_named(const std::string &name) const { - Children::const_iterator ci; - for (ci = _children.begin(); ci != _children.end(); ++ci) { - PartGroup *child = (*ci); +get_child_named(std::string_view name) const { + for (PartGroup *child : _children) { if (child->get_name() == name) { return child; } @@ -133,10 +131,8 @@ get_child_named(const std::string &name) const { * this PartGroup; see also get_child_named(). */ PartGroup *PartGroup:: -find_child(const std::string &name) const { - Children::const_iterator ci; - for (ci = _children.begin(); ci != _children.end(); ++ci) { - PartGroup *child = (*ci); +find_child(std::string_view name) const { + for (PartGroup *child : _children) { if (child->get_name() == name) { return child; } diff --git a/panda/src/chan/partGroup.h b/panda/src/chan/partGroup.h index 56bae67ac97..bf0b990c678 100644 --- a/panda/src/chan/partGroup.h +++ b/panda/src/chan/partGroup.h @@ -54,24 +54,24 @@ class EXPCL_PANDA_CHAN PartGroup : public TypedWritableReferenceCount, public Na // The default constructor is protected: don't try to create a PartGroup // without a parent. To create a PartGroup hierarchy, you must first create // a PartBundle, and use that as the parent of any subsequent children. - INLINE PartGroup(const std::string &name = ""); + INLINE PartGroup(std::string name = ""); INLINE PartGroup(const PartGroup ©); PUBLISHED: // This is the normal PartGroup constructor. - explicit PartGroup(PartGroup *parent, const std::string &name); + explicit PartGroup(PartGroup *parent, std::string name); virtual ~PartGroup(); virtual bool is_character_joint() const; - virtual PartGroup *make_copy() const; + [[nodiscard]] virtual PartGroup *make_copy() const; PartGroup *copy_subgraph() const; int get_num_children() const; PartGroup *get_child(int n) const; MAKE_SEQ(get_children, get_num_children, get_child); - PartGroup *get_child_named(const std::string &name) const; - PartGroup *find_child(const std::string &name) const; + PartGroup *get_child_named(std::string_view name) const; + PartGroup *find_child(std::string_view name) const; void sort_descendants(); MAKE_SEQ_PROPERTY(children, get_num_children, get_child); diff --git a/panda/src/chan/partSubset.cxx b/panda/src/chan/partSubset.cxx index 5e2a6c5831d..a3a0da24912 100644 --- a/panda/src/chan/partSubset.cxx +++ b/panda/src/chan/partSubset.cxx @@ -120,7 +120,7 @@ is_include_empty() const { * false otherwise. */ bool PartSubset:: -matches_include(const std::string &joint_name) const { +matches_include(std::string_view joint_name) const { Joints::const_iterator ji; for (ji = _include_joints.begin(); ji != _include_joints.end(); ++ji) { if ((*ji).matches(joint_name)) { @@ -137,7 +137,7 @@ matches_include(const std::string &joint_name) const { * false otherwise. */ bool PartSubset:: -matches_exclude(const std::string &joint_name) const { +matches_exclude(std::string_view joint_name) const { Joints::const_iterator ji; for (ji = _exclude_joints.begin(); ji != _exclude_joints.end(); ++ji) { if ((*ji).matches(joint_name)) { diff --git a/panda/src/chan/partSubset.h b/panda/src/chan/partSubset.h index 853849c5ea0..ff822175bc8 100644 --- a/panda/src/chan/partSubset.h +++ b/panda/src/chan/partSubset.h @@ -36,8 +36,8 @@ class EXPCL_PANDA_CHAN PartSubset { void output(std::ostream &out) const; bool is_include_empty() const; - bool matches_include(const std::string &joint_name) const; - bool matches_exclude(const std::string &joint_name) const; + bool matches_include(std::string_view joint_name) const; + bool matches_exclude(std::string_view joint_name) const; private: typedef pvector Joints; diff --git a/panda/src/char/character.cxx b/panda/src/char/character.cxx index eef46d4713e..dd674a0ea95 100644 --- a/panda/src/char/character.cxx +++ b/panda/src/char/character.cxx @@ -73,8 +73,8 @@ Character(const Character ©, bool copy_bundles) : * */ Character:: -Character(const std::string &name) : - PartBundleNode(name, new CharacterJointBundle(name)), +Character(std::string_view name) : + PartBundleNode(std::string(name), new CharacterJointBundle(std::string(name))), _last_auto_update(-1.0), _view_frame(-1), _view_distance2(0.0f), @@ -326,7 +326,7 @@ clear_lod_animation() { * to a slider. */ CharacterJoint *Character:: -find_joint(const std::string &name) const { +find_joint(std::string_view name) const { LightMutexHolder holder(_lock); for (PartBundleHandle *handle : _bundles) { PartGroup *part = handle->get_bundle()->find_child(name); @@ -344,7 +344,7 @@ find_joint(const std::string &name) const { * to a joint. */ CharacterSlider *Character:: -find_slider(const std::string &name) const { +find_slider(std::string_view name) const { LightMutexHolder holder(_lock); for (PartBundleHandle *handle : _bundles) { PartGroup *part = handle->get_bundle()->find_child(name); diff --git a/panda/src/char/character.h b/panda/src/char/character.h index 83aa754ee83..c36a0ab432f 100644 --- a/panda/src/char/character.h +++ b/panda/src/char/character.h @@ -40,7 +40,7 @@ class EXPCL_PANDA_CHAR Character : public PartBundleNode { Character(const Character ©, bool copy_bundles); PUBLISHED: - explicit Character(const std::string &name); + explicit Character(std::string_view name); virtual ~Character(); public: @@ -67,8 +67,8 @@ class EXPCL_PANDA_CHAR Character : public PartBundleNode { PN_stdfloat delay_factor); void clear_lod_animation(); - CharacterJoint *find_joint(const std::string &name) const; - CharacterSlider *find_slider(const std::string &name) const; + CharacterJoint *find_joint(std::string_view name) const; + CharacterSlider *find_slider(std::string_view name) const; void write_parts(std::ostream &out) const; void write_part_values(std::ostream &out) const; diff --git a/panda/src/char/characterJoint.cxx b/panda/src/char/characterJoint.cxx index c2dd79b3f94..9d608542792 100644 --- a/panda/src/char/characterJoint.cxx +++ b/panda/src/char/characterJoint.cxx @@ -50,9 +50,9 @@ CharacterJoint(const CharacterJoint ©) : */ CharacterJoint:: CharacterJoint(Character *character, - PartBundle *root, PartGroup *parent, const std::string &name, + PartBundle *root, PartGroup *parent, std::string name, const LMatrix4 &default_value) : - MovingPartMatrix(parent, name, default_value), + MovingPartMatrix(parent, std::move(name), default_value), _character(character) { Thread *current_thread = Thread::get_current_thread(); diff --git a/panda/src/char/characterJoint.h b/panda/src/char/characterJoint.h index 7d261578a3d..eec59c201db 100644 --- a/panda/src/char/characterJoint.h +++ b/panda/src/char/characterJoint.h @@ -37,7 +37,7 @@ class EXPCL_PANDA_CHAR CharacterJoint : public MovingPartMatrix { PUBLISHED: explicit CharacterJoint(Character *character, PartBundle *root, - PartGroup *parent, const std::string &name, + PartGroup *parent, std::string name, const LMatrix4 &default_value); virtual ~CharacterJoint(); diff --git a/panda/src/char/characterJointBundle.cxx b/panda/src/char/characterJointBundle.cxx index dda107a9a5d..be753cf24ca 100644 --- a/panda/src/char/characterJointBundle.cxx +++ b/panda/src/char/characterJointBundle.cxx @@ -24,7 +24,7 @@ TypeHandle CharacterJointBundle::_type_handle; * Character node will automatically create one for itself. */ CharacterJointBundle:: -CharacterJointBundle(const std::string &name) : PartBundle(name) { +CharacterJointBundle(std::string name) : PartBundle(std::move(name)) { } /** diff --git a/panda/src/char/characterJointBundle.h b/panda/src/char/characterJointBundle.h index 7d799b44dc2..9d9058deff0 100644 --- a/panda/src/char/characterJointBundle.h +++ b/panda/src/char/characterJointBundle.h @@ -30,7 +30,7 @@ class EXPCL_PANDA_CHAR CharacterJointBundle : public PartBundle { INLINE CharacterJointBundle(const CharacterJointBundle ©); PUBLISHED: - explicit CharacterJointBundle(const std::string &name = ""); + explicit CharacterJointBundle(std::string name = ""); virtual ~CharacterJointBundle(); PUBLISHED: diff --git a/panda/src/char/characterSlider.cxx b/panda/src/char/characterSlider.cxx index 0671bbdf793..c76b01630f3 100644 --- a/panda/src/char/characterSlider.cxx +++ b/panda/src/char/characterSlider.cxx @@ -40,9 +40,9 @@ CharacterSlider(const CharacterSlider ©) : * */ CharacterSlider:: -CharacterSlider(PartGroup *parent, const std::string &name, +CharacterSlider(PartGroup *parent, std::string name, PN_stdfloat default_value) - : MovingPartScalar(parent, name, default_value) { + : MovingPartScalar(parent, std::move(name), default_value) { } /** diff --git a/panda/src/char/characterSlider.h b/panda/src/char/characterSlider.h index 3184b2546ae..aac5089a0bc 100644 --- a/panda/src/char/characterSlider.h +++ b/panda/src/char/characterSlider.h @@ -31,7 +31,7 @@ class EXPCL_PANDA_CHAR CharacterSlider : public MovingPartScalar { CharacterSlider(const CharacterSlider ©); PUBLISHED: - explicit CharacterSlider(PartGroup *parent, const std::string &name, + explicit CharacterSlider(PartGroup *parent, std::string name, PN_stdfloat default_value = 0); virtual ~CharacterSlider(); diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.h b/panda/src/cocoadisplay/cocoaGraphicsWindow.h index e555489d24e..3e74b11463d 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.h +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.h @@ -42,7 +42,7 @@ typedef unsigned long NSUInteger; class EXPCL_PANDA_COCOADISPLAY CocoaGraphicsWindow : public GraphicsWindow { public: CocoaGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm index 1c25c04f668..8a1af2827f4 100644 --- a/panda/src/cocoadisplay/cocoaGraphicsWindow.mm +++ b/panda/src/cocoadisplay/cocoaGraphicsWindow.mm @@ -57,13 +57,13 @@ */ CocoaGraphicsWindow:: CocoaGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + GraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { _window = nil; _view = nil; @@ -1846,8 +1846,8 @@ && !in_window) { CGPoint point; - nx = std::max(0., std::min((double) get_x_size() - 1, nx)); - ny = std::max(0., std::min((double) get_y_size() - 1, ny)); + nx = std::clamp(nx, 0., (double) get_x_size() - 1); + ny = std::clamp(ny, 0., (double) get_y_size() - 1); // Convert back mouse position to screen space using point units if (_properties.get_fullscreen()) { diff --git a/panda/src/cocoagldisplay/cocoaGLGraphicsBuffer.h b/panda/src/cocoagldisplay/cocoaGLGraphicsBuffer.h index ea3a63eb3a7..0abf9984239 100644 --- a/panda/src/cocoagldisplay/cocoaGLGraphicsBuffer.h +++ b/panda/src/cocoagldisplay/cocoaGLGraphicsBuffer.h @@ -24,7 +24,7 @@ class EXPCL_PANDA_COCOAGLDISPLAY CocoaGLGraphicsBuffer : public GLGraphicsBuffer { public: CocoaGLGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/cocoagldisplay/cocoaGLGraphicsBuffer.mm b/panda/src/cocoagldisplay/cocoaGLGraphicsBuffer.mm index 8311e5ba289..390151be842 100644 --- a/panda/src/cocoagldisplay/cocoaGLGraphicsBuffer.mm +++ b/panda/src/cocoagldisplay/cocoaGLGraphicsBuffer.mm @@ -25,13 +25,13 @@ */ CocoaGLGraphicsBuffer:: CocoaGLGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, - const FrameBufferProperties &fb_prop, - const WindowProperties &win_prop, - int flags, - GraphicsStateGuardian *gsg, - GraphicsOutput *host) : // Ignore the host. - GLGraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, nullptr) + std::string name, + const FrameBufferProperties &fb_prop, + const WindowProperties &win_prop, + int flags, + GraphicsStateGuardian *gsg, + GraphicsOutput *host) : // Ignore the host. + GLGraphicsBuffer(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, nullptr) { } diff --git a/panda/src/cocoagldisplay/cocoaGLGraphicsPipe.h b/panda/src/cocoagldisplay/cocoaGLGraphicsPipe.h index 945e43b72a3..675eacb1c05 100644 --- a/panda/src/cocoagldisplay/cocoaGLGraphicsPipe.h +++ b/panda/src/cocoagldisplay/cocoaGLGraphicsPipe.h @@ -31,7 +31,7 @@ class EXPCL_PANDA_COCOAGLDISPLAY CocoaGLGraphicsPipe : public CocoaGraphicsPipe static PT(GraphicsPipe) pipe_constructor(); protected: - virtual PT(GraphicsOutput) make_output(const std::string &name, + virtual PT(GraphicsOutput) make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/cocoagldisplay/cocoaGLGraphicsPipe.mm b/panda/src/cocoagldisplay/cocoaGLGraphicsPipe.mm index ce73ce0732e..d9b3b3a1102 100644 --- a/panda/src/cocoagldisplay/cocoaGLGraphicsPipe.mm +++ b/panda/src/cocoagldisplay/cocoaGLGraphicsPipe.mm @@ -60,7 +60,7 @@ * Creates a new window on the pipe, if possible. */ PT(GraphicsOutput) CocoaGLGraphicsPipe:: -make_output(const std::string &name, +make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -92,7 +92,7 @@ (flags & BF_can_bind_layered) != 0) { return nullptr; } - return new CocoaGLGraphicsWindow(engine, this, name, fb_prop, win_prop, + return new CocoaGLGraphicsWindow(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } @@ -126,10 +126,10 @@ } } if (host != nullptr && host->get_engine() == engine) { - return new GLGraphicsBuffer(engine, this, name, fb_prop, win_prop, + return new GLGraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } else { - return new CocoaGLGraphicsBuffer(engine, this, name, fb_prop, win_prop, + return new CocoaGLGraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, nullptr); } } diff --git a/panda/src/cocoagldisplay/cocoaGLGraphicsWindow.h b/panda/src/cocoagldisplay/cocoaGLGraphicsWindow.h index 7bd612678d1..a3d9eb75eea 100644 --- a/panda/src/cocoagldisplay/cocoaGLGraphicsWindow.h +++ b/panda/src/cocoagldisplay/cocoaGLGraphicsWindow.h @@ -22,7 +22,7 @@ class EXPCL_PANDA_COCOADISPLAY CocoaGLGraphicsWindow : public CocoaGraphicsWindow { public: CocoaGLGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/cocoagldisplay/cocoaGLGraphicsWindow.mm b/panda/src/cocoagldisplay/cocoaGLGraphicsWindow.mm index 95df31cd364..3db8631036e 100644 --- a/panda/src/cocoagldisplay/cocoaGLGraphicsWindow.mm +++ b/panda/src/cocoagldisplay/cocoaGLGraphicsWindow.mm @@ -24,13 +24,13 @@ */ CocoaGLGraphicsWindow:: CocoaGLGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - CocoaGraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + CocoaGraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { } diff --git a/panda/src/collide/collisionBox.cxx b/panda/src/collide/collisionBox.cxx index d3445af0044..e5978c84633 100644 --- a/panda/src/collide/collisionBox.cxx +++ b/panda/src/collide/collisionBox.cxx @@ -541,7 +541,7 @@ test_intersection_from_segment(const CollisionEntry &entry) const { } // Our interior point is the closest point to t2 that is inside the segment. - new_entry->set_interior_point(from_origin + std::min(std::max(t2, 0.0), 1.0) * from_direction); + new_entry->set_interior_point(from_origin + std::clamp(t2, 0.0, 1.0) * from_direction); LPoint3 point = from_origin + t1 * from_direction; new_entry->set_surface_point(point); @@ -597,7 +597,7 @@ test_intersection_from_capsule(const CollisionEntry &entry) const { return nullptr; } - t1 = std::min(1.0, std::max(0.0, (t1 + t2) * 0.5)); + t1 = std::clamp((t1 + t2) * 0.5, 0.0, 1.0); LPoint3 point = from_a + from_direction * t1; // We now have a point of intersection between the line segment and the @@ -885,9 +885,9 @@ test_intersection_from_box(const CollisionEntry &entry) const { // This isn't always the correct surface point. However, it seems to be // enough to let the pusher do the right thing. LPoint3 surface( - min(max(diff[0], -into_extents[0]), into_extents[0]), - min(max(diff[1], -into_extents[1]), into_extents[1]), - min(max(diff[2], -into_extents[2]), into_extents[2])); + std::clamp(diff[0], -into_extents[0], into_extents[0]), + std::clamp(diff[1], -into_extents[1], into_extents[1]), + std::clamp(diff[2], -into_extents[2], into_extents[2])); // Create the normal along the axis of least penetration. LVector3 normal(0); diff --git a/panda/src/collide/collisionCapsule.cxx b/panda/src/collide/collisionCapsule.cxx index 0c67a492ab8..4805751d570 100644 --- a/panda/src/collide/collisionCapsule.cxx +++ b/panda/src/collide/collisionCapsule.cxx @@ -264,8 +264,7 @@ test_intersection_from_sphere(const CollisionEntry &entry) const { return nullptr; } - // doubles, not floats, to satisfy min and max templates. - actual_t = std::min(1.0, std::max(0.0, t1)); + actual_t = std::clamp(t1, 0.0, 1.0); contact_point = from_a + actual_t * (from_b - from_a); if (collide_cat.is_debug()) { diff --git a/panda/src/collide/collisionHandlerEvent.I b/panda/src/collide/collisionHandlerEvent.I index 217978e1173..94f7b52cd0a 100644 --- a/panda/src/collide/collisionHandlerEvent.I +++ b/panda/src/collide/collisionHandlerEvent.I @@ -64,8 +64,8 @@ clear_in_patterns() { * longer detected, the out_pattern event is thrown. */ INLINE void CollisionHandlerEvent:: -add_in_pattern(const std::string &in_pattern) { - _in_patterns.push_back(in_pattern); +add_in_pattern(std::string in_pattern) { + _in_patterns.push_back(std::move(in_pattern)); } /** @@ -75,9 +75,9 @@ add_in_pattern(const std::string &in_pattern) { * @deprecated Use add_in_pattern() instead. */ INLINE void CollisionHandlerEvent:: -set_in_pattern(const std::string &in_pattern) { +set_in_pattern(std::string in_pattern) { clear_in_patterns(); - add_in_pattern(in_pattern); + add_in_pattern(std::move(in_pattern)); } /** @@ -119,8 +119,8 @@ clear_again_patterns() { * longer detected, the out_pattern event is thrown. */ INLINE void CollisionHandlerEvent:: -add_again_pattern(const std::string &again_pattern) { - _again_patterns.push_back(again_pattern); +add_again_pattern(std::string again_pattern) { + _again_patterns.push_back(std::move(again_pattern)); } /** @@ -130,9 +130,9 @@ add_again_pattern(const std::string &again_pattern) { * @deprecated Use add_again_pattern() instead. */ INLINE void CollisionHandlerEvent:: -set_again_pattern(const std::string &again_pattern) { +set_again_pattern(std::string again_pattern) { clear_again_patterns(); - add_again_pattern(again_pattern); + add_again_pattern(std::move(again_pattern)); } /** @@ -172,8 +172,8 @@ clear_out_patterns() { * longer detected, the out_pattern event is thrown. */ INLINE void CollisionHandlerEvent:: -add_out_pattern(const std::string &out_pattern) { - _out_patterns.push_back(out_pattern); +add_out_pattern(std::string out_pattern) { + _out_patterns.push_back(std::move(out_pattern)); } /** @@ -183,9 +183,9 @@ add_out_pattern(const std::string &out_pattern) { * @deprecated Use add_out_pattern() instead. */ INLINE void CollisionHandlerEvent:: -set_out_pattern(const std::string &out_pattern) { +set_out_pattern(std::string out_pattern) { clear_out_patterns(); - add_out_pattern(out_pattern); + add_out_pattern(std::move(out_pattern)); } /** diff --git a/panda/src/collide/collisionHandlerEvent.cxx b/panda/src/collide/collisionHandlerEvent.cxx index 668868f0787..776b3ea74d9 100644 --- a/panda/src/collide/collisionHandlerEvent.cxx +++ b/panda/src/collide/collisionHandlerEvent.cxx @@ -214,7 +214,7 @@ throw_event_for(const vector_string &patterns, CollisionEntry *entry) { * Throws an event matching the indicated pattern. */ void CollisionHandlerEvent:: -throw_event_pattern(const string &pattern, CollisionEntry *entry) { +throw_event_pattern(std::string_view pattern, CollisionEntry *entry) { if (pattern.empty()) { return; } @@ -226,7 +226,7 @@ throw_event_pattern(const string &pattern, CollisionEntry *entry) { if (p + 1 < pattern.size() && pattern[p + 1] == '(') { // Extract out the key--the name up until the closing paren. size_t close = pattern.find(')', p + 2); - if (close != string::npos) { + if (close != std::string_view::npos) { key = pattern.substr(p + 2, close - (p + 2)); p = close; } @@ -234,7 +234,7 @@ throw_event_pattern(const string &pattern, CollisionEntry *entry) { // Get out the command--the two characters following the percent sign // (or the key). - string cmd = pattern.substr(p + 1, 2); + std::string_view cmd = pattern.substr(p + 1, 2); p += 2; if (cmd == "fn") { event += entry->get_from_node()->get_name(); diff --git a/panda/src/collide/collisionHandlerEvent.h b/panda/src/collide/collisionHandlerEvent.h index 829533b7d4a..b4968ac8a8f 100644 --- a/panda/src/collide/collisionHandlerEvent.h +++ b/panda/src/collide/collisionHandlerEvent.h @@ -41,22 +41,22 @@ class EXPCL_PANDA_COLLIDE CollisionHandlerEvent : public CollisionHandler { PUBLISHED: INLINE void clear_in_patterns(); - INLINE void add_in_pattern(const std::string &in_pattern); - INLINE void set_in_pattern(const std::string &in_pattern); + INLINE void add_in_pattern(std::string in_pattern); + INLINE void set_in_pattern(std::string in_pattern); INLINE int get_num_in_patterns() const; INLINE std::string get_in_pattern(int n) const; MAKE_SEQ(get_in_patterns, get_num_in_patterns, get_in_pattern); INLINE void clear_again_patterns(); - INLINE void add_again_pattern(const std::string &again_pattern); - INLINE void set_again_pattern(const std::string &again_pattern); + INLINE void add_again_pattern(std::string again_pattern); + INLINE void set_again_pattern(std::string again_pattern); INLINE int get_num_again_patterns() const; INLINE std::string get_again_pattern(int n) const; MAKE_SEQ(get_again_patterns, get_num_again_patterns, get_again_pattern); INLINE void clear_out_patterns(); - INLINE void add_out_pattern(const std::string &out_pattern); - INLINE void set_out_pattern(const std::string &out_pattern); + INLINE void add_out_pattern(std::string out_pattern); + INLINE void set_out_pattern(std::string out_pattern); INLINE int get_num_out_patterns() const; INLINE std::string get_out_pattern(int n) const; MAKE_SEQ(get_out_patterns, get_num_out_patterns, get_out_pattern); @@ -77,7 +77,7 @@ class EXPCL_PANDA_COLLIDE CollisionHandlerEvent : public CollisionHandler { protected: void throw_event_for(const vector_string &patterns, CollisionEntry *entry); - void throw_event_pattern(const std::string &pattern, CollisionEntry *entry); + void throw_event_pattern(std::string_view pattern, CollisionEntry *entry); vector_string _in_patterns; vector_string _again_patterns; diff --git a/panda/src/collide/collisionNode.cxx b/panda/src/collide/collisionNode.cxx index 60d28960ddb..b2d6b47589c 100644 --- a/panda/src/collide/collisionNode.cxx +++ b/panda/src/collide/collisionNode.cxx @@ -37,8 +37,8 @@ TypeHandle CollisionNode::_type_handle; * */ CollisionNode:: -CollisionNode(const std::string &name) : - PandaNode(name), +CollisionNode(std::string name) : + PandaNode(std::move(name)), _from_collide_mask(get_default_collide_mask()), _collider_sort(0), _owner(nullptr), diff --git a/panda/src/collide/collisionNode.h b/panda/src/collide/collisionNode.h index 14941a53369..b5b40228c0f 100644 --- a/panda/src/collide/collisionNode.h +++ b/panda/src/collide/collisionNode.h @@ -29,7 +29,7 @@ */ class EXPCL_PANDA_COLLIDE CollisionNode : public PandaNode { PUBLISHED: - explicit CollisionNode(const std::string &name); + explicit CollisionNode(std::string name); protected: CollisionNode(const CollisionNode ©); diff --git a/panda/src/collide/collisionPolygon.cxx b/panda/src/collide/collisionPolygon.cxx index 0d3214f2110..a96b0b4bc0a 100644 --- a/panda/src/collide/collisionPolygon.cxx +++ b/panda/src/collide/collisionPolygon.cxx @@ -439,7 +439,7 @@ test_intersection_from_sphere(const CollisionEntry &entry) const { // also compute the actual contact point and time of contact for // handlers that need it actual_t = ((dist_to_p - from_radius) / -dot); - actual_t = min((PN_stdfloat)1.0, max((PN_stdfloat)0.0, actual_t)); + actual_t = std::clamp(actual_t, (PN_stdfloat)0.0, (PN_stdfloat)1.0); contact_point = a + (actual_t * delta); if (t >= 1.0f) { @@ -899,7 +899,7 @@ test_intersection_from_capsule(const CollisionEntry &entry) const { LVector2 pv = p2 - p1; if (is_right(v, pv)) { PN_stdfloat t = v.dot(pv) / pv.length_squared(); - t = max(min(t, (PN_stdfloat)1), (PN_stdfloat)0); + t = std::clamp(t, (PN_stdfloat)0, (PN_stdfloat)1); LPoint2 p = p1 + pv * t; PN_stdfloat d = (p - intersect_2d).length_squared(); @@ -916,7 +916,7 @@ test_intersection_from_capsule(const CollisionEntry &entry) const { LVector3 from_v = from_b - from_a; PN_stdfloat t = (closest_p_3d - from_a).dot(from_v) / from_v.length_squared(); - LPoint3 ref_point_3d = from_a + from_v * max(min(t, (PN_stdfloat)1), (PN_stdfloat)0); + LPoint3 ref_point_3d = from_a + from_v * std::clamp(t, (PN_stdfloat)0, (PN_stdfloat)1); // Okay, now we have a point to apply the sphere test on. @@ -947,7 +947,7 @@ test_intersection_from_capsule(const CollisionEntry &entry) const { LVector2 pv = p2 - p1; if (is_right(v, pv)) { PN_stdfloat t = v.dot(pv) / pv.length_squared(); - t = max(min(t, (PN_stdfloat)1), (PN_stdfloat)0); + t = std::clamp(t, (PN_stdfloat)0, (PN_stdfloat)1); LPoint2 p = p1 + pv * t; PN_stdfloat d = (p - ref_point_2d).length_squared(); @@ -1010,7 +1010,7 @@ test_intersection_from_capsule(const CollisionEntry &entry) const { LVector2 pv = p2 - p1; if (is_right(v, pv)) { PN_stdfloat t = v.dot(pv) / pv.length_squared(); - t = max(min(t, (PN_stdfloat)1), (PN_stdfloat)0); + t = std::clamp(t, (PN_stdfloat)0, (PN_stdfloat)1); LPoint2 p = p1 + pv * t; PN_stdfloat d = (p - deepest_2d).length_squared(); diff --git a/panda/src/collide/collisionSolid.h b/panda/src/collide/collisionSolid.h index 4b1d17ce15f..fe4289326ad 100644 --- a/panda/src/collide/collisionSolid.h +++ b/panda/src/collide/collisionSolid.h @@ -48,7 +48,7 @@ class EXPCL_PANDA_COLLIDE CollisionSolid : public CopyOnWriteObject { CollisionSolid(const CollisionSolid ©); virtual ~CollisionSolid(); - virtual CollisionSolid *make_copy()=0; + [[nodiscard]] virtual CollisionSolid *make_copy()=0; protected: virtual PT(CopyOnWriteObject) make_cow_copy(); diff --git a/panda/src/collide/collisionSphere.cxx b/panda/src/collide/collisionSphere.cxx index 847de2e84fa..03e2c80d16f 100644 --- a/panda/src/collide/collisionSphere.cxx +++ b/panda/src/collide/collisionSphere.cxx @@ -174,8 +174,7 @@ test_intersection_from_sphere(const CollisionEntry &entry) const { return nullptr; } - // doubles, not floats, to satisfy min and max templates. - actual_t = min(1.0, max(0.0, t1)); + actual_t = std::clamp(t1, 0.0, 1.0); contact_point = from_a + actual_t * (from_b - from_a); if (t1 < 0.0) { diff --git a/panda/src/collide/collisionTraverser.cxx b/panda/src/collide/collisionTraverser.cxx index 87dad21203c..08caff5bf46 100644 --- a/panda/src/collide/collisionTraverser.cxx +++ b/panda/src/collide/collisionTraverser.cxx @@ -70,9 +70,9 @@ class SortByColliderSort { * */ CollisionTraverser:: -CollisionTraverser(const std::string &name) : - Namable(name), - _this_pcollector(_collisions_pcollector, name) +CollisionTraverser(std::string name) : + Namable(std::move(name)), + _this_pcollector(_collisions_pcollector, get_name()) { _respect_prev_transform = respect_prev_transform; #ifdef DO_COLLISION_RECORDING diff --git a/panda/src/collide/collisionTraverser.h b/panda/src/collide/collisionTraverser.h index a22a30aabe6..0d6201f5919 100644 --- a/panda/src/collide/collisionTraverser.h +++ b/panda/src/collide/collisionTraverser.h @@ -45,7 +45,7 @@ class CollisionEntry; */ class EXPCL_PANDA_COLLIDE CollisionTraverser : public Namable { PUBLISHED: - explicit CollisionTraverser(const std::string &name = "ctrav"); + explicit CollisionTraverser(std::string name = "ctrav"); ~CollisionTraverser(); INLINE void set_respect_prev_transform(bool flag); diff --git a/panda/src/collide/collisionVisualizer.cxx b/panda/src/collide/collisionVisualizer.cxx index 29d713badb0..3b97e5c879c 100644 --- a/panda/src/collide/collisionVisualizer.cxx +++ b/panda/src/collide/collisionVisualizer.cxx @@ -41,7 +41,7 @@ TypeHandle CollisionVisualizer::_type_handle; * */ CollisionVisualizer:: -CollisionVisualizer(const std::string &name) : PandaNode(name), _lock("CollisionVisualizer") { +CollisionVisualizer(std::string name) : PandaNode(std::move(name)), _lock("CollisionVisualizer") { set_cull_callback(); set_renderable(); diff --git a/panda/src/collide/collisionVisualizer.h b/panda/src/collide/collisionVisualizer.h index d289b74c0cc..87b3c7288ab 100644 --- a/panda/src/collide/collisionVisualizer.h +++ b/panda/src/collide/collisionVisualizer.h @@ -34,7 +34,7 @@ */ class EXPCL_PANDA_COLLIDE CollisionVisualizer : public PandaNode, public CollisionRecorder { public: - explicit CollisionVisualizer(const std::string &name); + explicit CollisionVisualizer(std::string name); CollisionVisualizer(const CollisionVisualizer ©); virtual ~CollisionVisualizer(); diff --git a/panda/src/cull/cullBinBackToFront.I b/panda/src/cull/cullBinBackToFront.I index fd66f8437ba..37d744cb947 100644 --- a/panda/src/cull/cullBinBackToFront.I +++ b/panda/src/cull/cullBinBackToFront.I @@ -15,9 +15,9 @@ * */ INLINE CullBinBackToFront:: -CullBinBackToFront(const std::string &name, GraphicsStateGuardianBase *gsg, +CullBinBackToFront(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector) : - CullBin(name, BT_back_to_front, gsg, draw_region_pcollector) + CullBin(std::move(name), BT_back_to_front, gsg, draw_region_pcollector) { } diff --git a/panda/src/cull/cullBinBackToFront.cxx b/panda/src/cull/cullBinBackToFront.cxx index 0254c4dfdd0..ea412822da8 100644 --- a/panda/src/cull/cullBinBackToFront.cxx +++ b/panda/src/cull/cullBinBackToFront.cxx @@ -27,9 +27,9 @@ TypeHandle CullBinBackToFront::_type_handle; * Factory constructor for passing to the CullBinManager. */ CullBin *CullBinBackToFront:: -make_bin(const std::string &name, GraphicsStateGuardianBase *gsg, +make_bin(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector) { - return new CullBinBackToFront(name, gsg, draw_region_pcollector); + return new CullBinBackToFront(std::move(name), gsg, draw_region_pcollector); } /** diff --git a/panda/src/cull/cullBinBackToFront.h b/panda/src/cull/cullBinBackToFront.h index b950bddc282..9d7fcbf173a 100644 --- a/panda/src/cull/cullBinBackToFront.h +++ b/panda/src/cull/cullBinBackToFront.h @@ -30,11 +30,11 @@ */ class EXPCL_PANDA_CULL CullBinBackToFront : public CullBin { public: - INLINE CullBinBackToFront(const std::string &name, + INLINE CullBinBackToFront(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector); - static CullBin *make_bin(const std::string &name, + static CullBin *make_bin(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector); diff --git a/panda/src/cull/cullBinFixed.I b/panda/src/cull/cullBinFixed.I index 4d35e242a39..08616ad5e1d 100644 --- a/panda/src/cull/cullBinFixed.I +++ b/panda/src/cull/cullBinFixed.I @@ -15,9 +15,9 @@ * */ INLINE CullBinFixed:: -CullBinFixed(const std::string &name, GraphicsStateGuardianBase *gsg, +CullBinFixed(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector) : - CullBin(name, BT_fixed, gsg, draw_region_pcollector) + CullBin(std::move(name), BT_fixed, gsg, draw_region_pcollector) { } diff --git a/panda/src/cull/cullBinFixed.cxx b/panda/src/cull/cullBinFixed.cxx index 9d8ff46dcb0..155c1ff03d5 100644 --- a/panda/src/cull/cullBinFixed.cxx +++ b/panda/src/cull/cullBinFixed.cxx @@ -27,9 +27,9 @@ TypeHandle CullBinFixed::_type_handle; * Factory constructor for passing to the CullBinManager. */ CullBin *CullBinFixed:: -make_bin(const std::string &name, GraphicsStateGuardianBase *gsg, +make_bin(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector) { - return new CullBinFixed(name, gsg, draw_region_pcollector); + return new CullBinFixed(std::move(name), gsg, draw_region_pcollector); } /** diff --git a/panda/src/cull/cullBinFixed.h b/panda/src/cull/cullBinFixed.h index fdaece45914..02051237637 100644 --- a/panda/src/cull/cullBinFixed.h +++ b/panda/src/cull/cullBinFixed.h @@ -32,11 +32,11 @@ */ class EXPCL_PANDA_CULL CullBinFixed : public CullBin { public: - INLINE CullBinFixed(const std::string &name, + INLINE CullBinFixed(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector); - static CullBin *make_bin(const std::string &name, + static CullBin *make_bin(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector); diff --git a/panda/src/cull/cullBinFrontToBack.I b/panda/src/cull/cullBinFrontToBack.I index 83c0ab46510..58d7cfcda24 100644 --- a/panda/src/cull/cullBinFrontToBack.I +++ b/panda/src/cull/cullBinFrontToBack.I @@ -15,9 +15,9 @@ * */ INLINE CullBinFrontToBack:: -CullBinFrontToBack(const std::string &name, GraphicsStateGuardianBase *gsg, +CullBinFrontToBack(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector) : - CullBin(name, BT_front_to_back, gsg, draw_region_pcollector) + CullBin(std::move(name), BT_front_to_back, gsg, draw_region_pcollector) { } diff --git a/panda/src/cull/cullBinFrontToBack.cxx b/panda/src/cull/cullBinFrontToBack.cxx index dfc85dd5403..ae162b61927 100644 --- a/panda/src/cull/cullBinFrontToBack.cxx +++ b/panda/src/cull/cullBinFrontToBack.cxx @@ -27,9 +27,9 @@ TypeHandle CullBinFrontToBack::_type_handle; * Factory constructor for passing to the CullBinManager. */ CullBin *CullBinFrontToBack:: -make_bin(const std::string &name, GraphicsStateGuardianBase *gsg, +make_bin(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector) { - return new CullBinFrontToBack(name, gsg, draw_region_pcollector); + return new CullBinFrontToBack(std::move(name), gsg, draw_region_pcollector); } /** diff --git a/panda/src/cull/cullBinFrontToBack.h b/panda/src/cull/cullBinFrontToBack.h index 15c1f80ccf4..b5d892aafa2 100644 --- a/panda/src/cull/cullBinFrontToBack.h +++ b/panda/src/cull/cullBinFrontToBack.h @@ -31,11 +31,11 @@ */ class EXPCL_PANDA_CULL CullBinFrontToBack : public CullBin { public: - INLINE CullBinFrontToBack(const std::string &name, + INLINE CullBinFrontToBack(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector); - static CullBin *make_bin(const std::string &name, + static CullBin *make_bin(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector); diff --git a/panda/src/cull/cullBinStateSorted.I b/panda/src/cull/cullBinStateSorted.I index 1a1637bdf41..83c6e98d396 100644 --- a/panda/src/cull/cullBinStateSorted.I +++ b/panda/src/cull/cullBinStateSorted.I @@ -15,9 +15,9 @@ * */ INLINE CullBinStateSorted:: -CullBinStateSorted(const std::string &name, GraphicsStateGuardianBase *gsg, +CullBinStateSorted(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector) : - CullBin(name, BT_state_sorted, gsg, draw_region_pcollector), + CullBin(std::move(name), BT_state_sorted, gsg, draw_region_pcollector), _objects(get_class_type()) { } diff --git a/panda/src/cull/cullBinStateSorted.cxx b/panda/src/cull/cullBinStateSorted.cxx index 3d08802a48f..504d7046576 100644 --- a/panda/src/cull/cullBinStateSorted.cxx +++ b/panda/src/cull/cullBinStateSorted.cxx @@ -26,9 +26,9 @@ TypeHandle CullBinStateSorted::_type_handle; * Factory constructor for passing to the CullBinManager. */ CullBin *CullBinStateSorted:: -make_bin(const std::string &name, GraphicsStateGuardianBase *gsg, +make_bin(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector) { - return new CullBinStateSorted(name, gsg, draw_region_pcollector); + return new CullBinStateSorted(std::move(name), gsg, draw_region_pcollector); } /** diff --git a/panda/src/cull/cullBinStateSorted.h b/panda/src/cull/cullBinStateSorted.h index 2e6486e3485..5e0cfb0298b 100644 --- a/panda/src/cull/cullBinStateSorted.h +++ b/panda/src/cull/cullBinStateSorted.h @@ -34,11 +34,11 @@ */ class EXPCL_PANDA_CULL CullBinStateSorted : public CullBin { public: - INLINE CullBinStateSorted(const std::string &name, + INLINE CullBinStateSorted(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector); - static CullBin *make_bin(const std::string &name, + static CullBin *make_bin(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector); diff --git a/panda/src/cull/cullBinUnsorted.I b/panda/src/cull/cullBinUnsorted.I index 2e000b72f0b..c091c939bc3 100644 --- a/panda/src/cull/cullBinUnsorted.I +++ b/panda/src/cull/cullBinUnsorted.I @@ -15,8 +15,8 @@ * */ INLINE CullBinUnsorted:: -CullBinUnsorted(const std::string &name, GraphicsStateGuardianBase *gsg, +CullBinUnsorted(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector) : - CullBin(name, BT_unsorted, gsg, draw_region_pcollector) + CullBin(std::move(name), BT_unsorted, gsg, draw_region_pcollector) { } diff --git a/panda/src/cull/cullBinUnsorted.cxx b/panda/src/cull/cullBinUnsorted.cxx index 768ce35abfd..5686e977a9b 100644 --- a/panda/src/cull/cullBinUnsorted.cxx +++ b/panda/src/cull/cullBinUnsorted.cxx @@ -23,9 +23,9 @@ TypeHandle CullBinUnsorted::_type_handle; * Factory constructor for passing to the CullBinManager. */ CullBin *CullBinUnsorted:: -make_bin(const std::string &name, GraphicsStateGuardianBase *gsg, +make_bin(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector) { - return new CullBinUnsorted(name, gsg, draw_region_pcollector); + return new CullBinUnsorted(std::move(name), gsg, draw_region_pcollector); } /** diff --git a/panda/src/cull/cullBinUnsorted.h b/panda/src/cull/cullBinUnsorted.h index bd31ea0a387..2736677d0dc 100644 --- a/panda/src/cull/cullBinUnsorted.h +++ b/panda/src/cull/cullBinUnsorted.h @@ -26,11 +26,11 @@ */ class EXPCL_PANDA_CULL CullBinUnsorted : public CullBin { public: - INLINE CullBinUnsorted(const std::string &name, + INLINE CullBinUnsorted(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector); - static CullBin *make_bin(const std::string &name, + static CullBin *make_bin(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector); diff --git a/panda/src/device/analogNode.cxx b/panda/src/device/analogNode.cxx index 6f9b42811c1..c024d5657e7 100644 --- a/panda/src/device/analogNode.cxx +++ b/panda/src/device/analogNode.cxx @@ -23,8 +23,8 @@ TypeHandle AnalogNode::_type_handle; * */ AnalogNode:: -AnalogNode(ClientBase *client, const std::string &device_name) : - DataNode(device_name) +AnalogNode(ClientBase *client, std::string_view device_name) : + DataNode(std::string(device_name)) { _xy_output = define_output("xy", EventStoreVec2::get_class_type()); _xy = new EventStoreVec2(LPoint2(0)); diff --git a/panda/src/device/analogNode.h b/panda/src/device/analogNode.h index 2b522423d26..9e323e92e30 100644 --- a/panda/src/device/analogNode.h +++ b/panda/src/device/analogNode.h @@ -38,7 +38,7 @@ */ class EXPCL_PANDA_DEVICE AnalogNode : public DataNode { PUBLISHED: - explicit AnalogNode(ClientBase *client, const std::string &device_name); + explicit AnalogNode(ClientBase *client, std::string_view device_name); explicit AnalogNode(InputDevice *device); virtual ~AnalogNode(); diff --git a/panda/src/device/buttonNode.cxx b/panda/src/device/buttonNode.cxx index c5f8242c01a..7034e36478f 100644 --- a/panda/src/device/buttonNode.cxx +++ b/panda/src/device/buttonNode.cxx @@ -23,8 +23,8 @@ TypeHandle ButtonNode::_type_handle; * */ ButtonNode:: -ButtonNode(ClientBase *client, const std::string &device_name) : - DataNode(device_name) +ButtonNode(ClientBase *client, std::string_view device_name) : + DataNode(std::string(device_name)) { _button_events_output = define_output("button_events", ButtonEventList::get_class_type()); diff --git a/panda/src/device/buttonNode.h b/panda/src/device/buttonNode.h index 2739c440a74..4739f82e6be 100644 --- a/panda/src/device/buttonNode.h +++ b/panda/src/device/buttonNode.h @@ -32,7 +32,7 @@ */ class EXPCL_PANDA_DEVICE ButtonNode : public DataNode { PUBLISHED: - explicit ButtonNode(ClientBase *client, const std::string &device_name); + explicit ButtonNode(ClientBase *client, std::string_view device_name); explicit ButtonNode(InputDevice *device); virtual ~ButtonNode(); diff --git a/panda/src/device/clientAnalogDevice.I b/panda/src/device/clientAnalogDevice.I index 490eedb0793..80e7c38752d 100644 --- a/panda/src/device/clientAnalogDevice.I +++ b/panda/src/device/clientAnalogDevice.I @@ -15,7 +15,7 @@ * */ INLINE ClientAnalogDevice:: -ClientAnalogDevice(ClientBase *client, const std::string &device_name): - ClientDevice(client, get_class_type(), device_name) +ClientAnalogDevice(ClientBase *client, std::string device_name): + ClientDevice(client, get_class_type(), std::move(device_name)) { } diff --git a/panda/src/device/clientAnalogDevice.h b/panda/src/device/clientAnalogDevice.h index 0db13d573fa..375e999786e 100644 --- a/panda/src/device/clientAnalogDevice.h +++ b/panda/src/device/clientAnalogDevice.h @@ -28,7 +28,7 @@ */ class EXPCL_PANDA_DEVICE ClientAnalogDevice : public ClientDevice { protected: - INLINE ClientAnalogDevice(ClientBase *client, const std::string &device_name); + INLINE ClientAnalogDevice(ClientBase *client, std::string device_name); public: virtual void write(std::ostream &out, int indent_level = 0) const; diff --git a/panda/src/device/clientBase.cxx b/panda/src/device/clientBase.cxx index a6f8bb3051e..63d52b7acb3 100644 --- a/panda/src/device/clientBase.cxx +++ b/panda/src/device/clientBase.cxx @@ -113,7 +113,7 @@ fork_asynchronous_thread(double poll_time) { * NULL is returned. */ PT(ClientDevice) ClientBase:: -get_device(TypeHandle device_type, const std::string &device_name) { +get_device(TypeHandle device_type, std::string_view device_name) { DevicesByName &dbn = _devices[device_type]; DevicesByName::iterator dbni; @@ -127,7 +127,7 @@ get_device(TypeHandle device_type, const std::string &device_name) { PT(ClientDevice) device = make_device(device_type, device_name); if (device != nullptr) { - dbn.insert(DevicesByName::value_type(device_name, device)); + dbn.insert(DevicesByName::value_type(std::string(device_name), device)); } return device; @@ -142,7 +142,7 @@ get_device(TypeHandle device_type, const std::string &device_name) { * unknown (e.g. it was disconnected previously). */ bool ClientBase:: -disconnect_device(TypeHandle device_type, const std::string &device_name, +disconnect_device(TypeHandle device_type, std::string_view device_name, ClientDevice *device) { DevicesByName &dbn = _devices[device_type]; diff --git a/panda/src/device/clientBase.h b/panda/src/device/clientBase.h index 6a3106a3852..d11718062ef 100644 --- a/panda/src/device/clientBase.h +++ b/panda/src/device/clientBase.h @@ -57,20 +57,20 @@ class EXPCL_PANDA_DEVICE ClientBase : public TypedReferenceCount { public: PT(ClientDevice) get_device(TypeHandle device_type, - const std::string &device_name); + std::string_view device_name); protected: virtual PT(ClientDevice) make_device(TypeHandle device_type, - const std::string &device_name)=0; + std::string_view device_name)=0; virtual bool disconnect_device(TypeHandle device_type, - const std::string &device_name, + std::string_view device_name, ClientDevice *device); virtual void do_poll(); private: - typedef pmap DevicesByName; + typedef pmap> DevicesByName; typedef pmap Devices; Devices _devices; diff --git a/panda/src/device/clientButtonDevice.cxx b/panda/src/device/clientButtonDevice.cxx index 9ae2b4844cf..7608c2d8035 100644 --- a/panda/src/device/clientButtonDevice.cxx +++ b/panda/src/device/clientButtonDevice.cxx @@ -23,8 +23,8 @@ TypeHandle ClientButtonDevice::_type_handle; * */ ClientButtonDevice:: -ClientButtonDevice(ClientBase *client, const std::string &device_name): - ClientDevice(client, get_class_type(), device_name) +ClientButtonDevice(ClientBase *client, std::string device_name): + ClientDevice(client, get_class_type(), std::move(device_name)) { } diff --git a/panda/src/device/clientButtonDevice.h b/panda/src/device/clientButtonDevice.h index 3e5b9c57df2..4c41f404a52 100644 --- a/panda/src/device/clientButtonDevice.h +++ b/panda/src/device/clientButtonDevice.h @@ -31,7 +31,7 @@ */ class EXPCL_PANDA_DEVICE ClientButtonDevice : public ClientDevice { protected: - ClientButtonDevice(ClientBase *client, const std::string &device_name); + ClientButtonDevice(ClientBase *client, std::string device_name); public: virtual void output(std::ostream &out) const; diff --git a/panda/src/device/clientDevice.cxx b/panda/src/device/clientDevice.cxx index 198270f5639..f251ca5b644 100644 --- a/panda/src/device/clientDevice.cxx +++ b/panda/src/device/clientDevice.cxx @@ -23,8 +23,8 @@ TypeHandle ClientDevice::_type_handle; */ ClientDevice:: ClientDevice(ClientBase *client, TypeHandle device_type, - const std::string &device_name) : - InputDevice(device_name, DeviceClass::UNKNOWN), + std::string device_name) : + InputDevice(std::move(device_name), DeviceClass::UNKNOWN), _client(client), _device_type(device_type) { diff --git a/panda/src/device/clientDevice.h b/panda/src/device/clientDevice.h index b77d7074847..27981e456d4 100644 --- a/panda/src/device/clientDevice.h +++ b/panda/src/device/clientDevice.h @@ -27,7 +27,7 @@ class ClientBase; class EXPCL_PANDA_DEVICE ClientDevice : public InputDevice { protected: ClientDevice(ClientBase *client, TypeHandle device_type, - const std::string &device_name); + std::string device_name); public: virtual ~ClientDevice(); diff --git a/panda/src/device/clientDialDevice.I b/panda/src/device/clientDialDevice.I index b0360ec63bb..e6e22cd08dd 100644 --- a/panda/src/device/clientDialDevice.I +++ b/panda/src/device/clientDialDevice.I @@ -25,8 +25,8 @@ DialState() : * */ INLINE ClientDialDevice:: -ClientDialDevice(ClientBase *client, const std::string &device_name): - ClientDevice(client, get_class_type(), device_name) +ClientDialDevice(ClientBase *client, std::string device_name): + ClientDevice(client, get_class_type(), std::move(device_name)) { } diff --git a/panda/src/device/clientDialDevice.h b/panda/src/device/clientDialDevice.h index ec1c929abfa..196712b9836 100644 --- a/panda/src/device/clientDialDevice.h +++ b/panda/src/device/clientDialDevice.h @@ -29,7 +29,7 @@ */ class EXPCL_PANDA_DEVICE ClientDialDevice : public ClientDevice { protected: - INLINE ClientDialDevice(ClientBase *client, const std::string &device_name); + INLINE ClientDialDevice(ClientBase *client, std::string device_name); public: INLINE int get_num_dials() const; diff --git a/panda/src/device/clientTrackerDevice.I b/panda/src/device/clientTrackerDevice.I index 7012b53faa6..9bc4d79c770 100644 --- a/panda/src/device/clientTrackerDevice.I +++ b/panda/src/device/clientTrackerDevice.I @@ -15,8 +15,8 @@ * */ INLINE ClientTrackerDevice:: -ClientTrackerDevice(ClientBase *client, const std::string &device_name): - ClientDevice(client, get_class_type(), device_name) +ClientTrackerDevice(ClientBase *client, std::string device_name): + ClientDevice(client, get_class_type(), std::move(device_name)) { enable_feature(Feature::TRACKER); } diff --git a/panda/src/device/clientTrackerDevice.h b/panda/src/device/clientTrackerDevice.h index 22ff983fa09..4200e5798da 100644 --- a/panda/src/device/clientTrackerDevice.h +++ b/panda/src/device/clientTrackerDevice.h @@ -25,7 +25,7 @@ */ class EXPCL_PANDA_DEVICE ClientTrackerDevice : public ClientDevice { protected: - INLINE ClientTrackerDevice(ClientBase *client, const std::string &device_name); + INLINE ClientTrackerDevice(ClientBase *client, std::string device_name); public: static TypeHandle get_class_type() { diff --git a/panda/src/device/dialNode.cxx b/panda/src/device/dialNode.cxx index 04f46a78054..b7ebec81c2d 100644 --- a/panda/src/device/dialNode.cxx +++ b/panda/src/device/dialNode.cxx @@ -22,8 +22,8 @@ TypeHandle DialNode::_type_handle; * */ DialNode:: -DialNode(ClientBase *client, const std::string &device_name) : - DataNode(device_name) +DialNode(ClientBase *client, std::string_view device_name) : + DataNode(std::string(device_name)) { nassertv(client != nullptr); PT(ClientDevice) device = diff --git a/panda/src/device/dialNode.h b/panda/src/device/dialNode.h index 6fb65e77639..8be9b1f9487 100644 --- a/panda/src/device/dialNode.h +++ b/panda/src/device/dialNode.h @@ -33,7 +33,7 @@ */ class EXPCL_PANDA_DEVICE DialNode : public DataNode { PUBLISHED: - explicit DialNode(ClientBase *client, const std::string &device_name); + explicit DialNode(ClientBase *client, std::string_view device_name); virtual ~DialNode(); INLINE bool is_valid() const; diff --git a/panda/src/device/inputDevice.cxx b/panda/src/device/inputDevice.cxx index 7997680847a..cd444723daa 100644 --- a/panda/src/device/inputDevice.cxx +++ b/panda/src/device/inputDevice.cxx @@ -23,8 +23,8 @@ TypeHandle InputDevice::_type_handle; * Defines a new InputDevice. */ InputDevice:: -InputDevice(const std::string &name, DeviceClass dev_class) : - _name(name), +InputDevice(std::string name, DeviceClass dev_class) : + _name(std::move(name)), _device_class(dev_class), _is_connected(true) { diff --git a/panda/src/device/inputDevice.h b/panda/src/device/inputDevice.h index 445e0d07f11..a03e82648c2 100644 --- a/panda/src/device/inputDevice.h +++ b/panda/src/device/inputDevice.h @@ -229,7 +229,7 @@ class EXPCL_PANDA_DEVICE InputDevice : public TypedReferenceCount { }; protected: - InputDevice(const std::string &name, DeviceClass dev_class); + InputDevice(std::string name, DeviceClass dev_class); public: InputDevice(); diff --git a/panda/src/device/inputDeviceNode.cxx b/panda/src/device/inputDeviceNode.cxx index 286dd93c087..a973cc148ec 100644 --- a/panda/src/device/inputDeviceNode.cxx +++ b/panda/src/device/inputDeviceNode.cxx @@ -19,8 +19,8 @@ TypeHandle InputDeviceNode::_type_handle; InputDeviceNode:: -InputDeviceNode(InputDevice *device, const std::string &name) : - DataNode(name), +InputDeviceNode(InputDevice *device, std::string name) : + DataNode(std::move(name)), _device(device) { _button_events_output = define_output("button_events", ButtonEventList::get_class_type()); diff --git a/panda/src/device/inputDeviceNode.h b/panda/src/device/inputDeviceNode.h index f2d5659781b..177b8238fbe 100644 --- a/panda/src/device/inputDeviceNode.h +++ b/panda/src/device/inputDeviceNode.h @@ -28,7 +28,7 @@ */ class EXPCL_PANDA_DEVICE InputDeviceNode : public DataNode { PUBLISHED: - explicit InputDeviceNode(InputDevice *device, const std::string &name); + explicit InputDeviceNode(InputDevice *device, std::string name); public: void set_device(InputDevice *device); diff --git a/panda/src/device/trackerNode.cxx b/panda/src/device/trackerNode.cxx index f97849e754a..a6061ca51a8 100644 --- a/panda/src/device/trackerNode.cxx +++ b/panda/src/device/trackerNode.cxx @@ -23,8 +23,8 @@ TypeHandle TrackerNode::_type_handle; * */ TrackerNode:: -TrackerNode(ClientBase *client, const std::string &device_name) : - DataNode(device_name) +TrackerNode(ClientBase *client, std::string_view device_name) : + DataNode(std::string(device_name)) { _transform_output = define_output("transform", TransformState::get_class_type()); diff --git a/panda/src/device/trackerNode.h b/panda/src/device/trackerNode.h index d4be61c1dd6..2083f94e836 100644 --- a/panda/src/device/trackerNode.h +++ b/panda/src/device/trackerNode.h @@ -32,7 +32,7 @@ */ class EXPCL_PANDA_DEVICE TrackerNode : public DataNode { PUBLISHED: - explicit TrackerNode(ClientBase *client, const std::string &device_name); + explicit TrackerNode(ClientBase *client, std::string_view device_name); explicit TrackerNode(InputDevice *device); virtual ~TrackerNode(); diff --git a/panda/src/device/virtualMouse.cxx b/panda/src/device/virtualMouse.cxx index cdbf5aa678b..82e8f0110e7 100644 --- a/panda/src/device/virtualMouse.cxx +++ b/panda/src/device/virtualMouse.cxx @@ -20,8 +20,8 @@ TypeHandle VirtualMouse::_type_handle; * */ VirtualMouse:: -VirtualMouse(const std::string &name) : - DataNode(name) +VirtualMouse(std::string name) : + DataNode(std::move(name)) { _pixel_xy_output = define_output("pixel_xy", EventStoreVec2::get_class_type()); _pixel_size_output = define_output("pixel_size", EventStoreVec2::get_class_type()); diff --git a/panda/src/device/virtualMouse.h b/panda/src/device/virtualMouse.h index 2afa1b8d726..7eecddaaa7d 100644 --- a/panda/src/device/virtualMouse.h +++ b/panda/src/device/virtualMouse.h @@ -31,7 +31,7 @@ */ class EXPCL_PANDA_DEVICE VirtualMouse : public DataNode { PUBLISHED: - explicit VirtualMouse(const std::string &name); + explicit VirtualMouse(std::string name); void set_mouse_pos(int x, int y); void set_window_size(int width, int height); diff --git a/panda/src/device/xInputDevice.cxx b/panda/src/device/xInputDevice.cxx index 4405cc72258..393ba7fee44 100644 --- a/panda/src/device/xInputDevice.cxx +++ b/panda/src/device/xInputDevice.cxx @@ -148,7 +148,7 @@ XInputDevice:: */ bool XInputDevice:: check_arrival(const RID_DEVICE_INFO &info, DEVINST inst, - const std::string &name, const std::string &manufacturer) { + std::string name, std::string manufacturer) { LightMutexHolder holder(_lock); if (_is_connected) { return false; @@ -177,12 +177,12 @@ check_arrival(const RID_DEVICE_INFO &info, DEVINST inst, // Yes, take the name and manufacturer. if (!name.empty()) { - _name = name; + _name = std::move(name); } else { _name = "XInput Device #"; _name += format_string(_index + 1); } - _manufacturer = manufacturer; + _manufacturer = std::move(manufacturer); if (inst && caps.ProductID == 0 && caps.RevisionID != 0) { // XInput does not report a product ID for the Xbox 360 wireless adapter. diff --git a/panda/src/device/xInputDevice.h b/panda/src/device/xInputDevice.h index c4a1f58d272..68f61bd2edc 100644 --- a/panda/src/device/xInputDevice.h +++ b/panda/src/device/xInputDevice.h @@ -40,7 +40,7 @@ class EXPCL_PANDA_DEVICE XInputDevice final : public InputDevice { ~XInputDevice(); bool check_arrival(const RID_DEVICE_INFO &info, DEVINST inst, - const std::string &name, const std::string &manufacturer); + std::string name, std::string manufacturer); void detect(InputDeviceManager *mgr); static bool init_xinput(); diff --git a/panda/src/dgraph/dataNode.I b/panda/src/dgraph/dataNode.I index a466de9d244..0f3211ca0fa 100644 --- a/panda/src/dgraph/dataNode.I +++ b/panda/src/dgraph/dataNode.I @@ -15,8 +15,8 @@ * */ INLINE DataNode:: -DataNode(const std::string &name) : - PandaNode(name) +DataNode(std::string name) : + PandaNode(std::move(name)) { } diff --git a/panda/src/dgraph/dataNode.cxx b/panda/src/dgraph/dataNode.cxx index a67c0b0c0db..3f88d615b02 100644 --- a/panda/src/dgraph/dataNode.cxx +++ b/panda/src/dgraph/dataNode.cxx @@ -166,7 +166,7 @@ write_connections(std::ostream &out) const { * do_transmit_data() that can be used to access the input data. */ int DataNode:: -define_input(const string &name, TypeHandle data_type) { +define_input(std::string name, TypeHandle data_type) { // We shouldn't already be connected. nassertr(_data_connections.empty(), 0); @@ -180,7 +180,7 @@ define_input(const string &name, TypeHandle data_type) { } // This wire did not already exist; add it. - WireDef &def = _input_wires[name]; + WireDef &def = _input_wires[std::move(name)]; def._data_type = data_type; def._index = _input_wires.size() - 1; return def._index; @@ -199,7 +199,7 @@ define_input(const string &name, TypeHandle data_type) { * do_transmit_data() where the output data should be stored. */ int DataNode:: -define_output(const string &name, TypeHandle data_type) { +define_output(std::string name, TypeHandle data_type) { // We shouldn't already be connected. nassertr(_data_connections.empty(), 0); @@ -213,7 +213,7 @@ define_output(const string &name, TypeHandle data_type) { } // This wire did not already exist; add it. - WireDef &def = _output_wires[name]; + WireDef &def = _output_wires[std::move(name)]; def._data_type = data_type; def._index = _output_wires.size() - 1; return def._index; diff --git a/panda/src/dgraph/dataNode.h b/panda/src/dgraph/dataNode.h index 7386b52b9ad..0eb8011d358 100644 --- a/panda/src/dgraph/dataNode.h +++ b/panda/src/dgraph/dataNode.h @@ -51,7 +51,7 @@ class DataNodeTransmit; */ class EXPCL_PANDA_DGRAPH DataNode : public PandaNode { PUBLISHED: - INLINE explicit DataNode(const std::string &name); + INLINE explicit DataNode(std::string name); protected: INLINE DataNode(const DataNode ©); @@ -71,8 +71,8 @@ class EXPCL_PANDA_DGRAPH DataNode : public PandaNode { void write_connections(std::ostream &out) const; protected: - int define_input(const std::string &name, TypeHandle data_type); - int define_output(const std::string &name, TypeHandle data_type); + int define_input(std::string name, TypeHandle data_type); + int define_output(std::string name, TypeHandle data_type); protected: // Inherited from PandaNode diff --git a/panda/src/display/callbackGraphicsWindow.cxx b/panda/src/display/callbackGraphicsWindow.cxx index 7372f81f640..71ade51c9ce 100644 --- a/panda/src/display/callbackGraphicsWindow.cxx +++ b/panda/src/display/callbackGraphicsWindow.cxx @@ -24,12 +24,12 @@ TypeHandle CallbackGraphicsWindow::RenderCallbackData::_type_handle; */ CallbackGraphicsWindow:: CallbackGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg) : - GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, nullptr) + GraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, nullptr) { #ifdef DO_MEMORY_USAGE MemoryUsage::update_type(this, this); @@ -52,8 +52,8 @@ CallbackGraphicsWindow:: * Returns the index of the new device. */ int CallbackGraphicsWindow:: -create_input_device(const std::string &name) { - return add_input_device(GraphicsWindowInputDevice::pointer_and_keyboard(this, name)); +create_input_device(std::string name) { + return add_input_device(GraphicsWindowInputDevice::pointer_and_keyboard(this, std::move(name))); } /** diff --git a/panda/src/display/callbackGraphicsWindow.h b/panda/src/display/callbackGraphicsWindow.h index dee8558a53e..37236fad335 100644 --- a/panda/src/display/callbackGraphicsWindow.h +++ b/panda/src/display/callbackGraphicsWindow.h @@ -27,7 +27,7 @@ class EXPCL_PANDA_DISPLAY CallbackGraphicsWindow : public GraphicsWindow { protected: CallbackGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -178,7 +178,7 @@ class EXPCL_PANDA_DISPLAY CallbackGraphicsWindow : public GraphicsWindow { INLINE void clear_render_callback(); INLINE CallbackObject *get_render_callback() const; - int create_input_device(const std::string &name); + int create_input_device(std::string name); public: virtual bool begin_frame(FrameMode mode, Thread *current_thread); diff --git a/panda/src/display/displayRegion.cxx b/panda/src/display/displayRegion.cxx index 0b13e9089bc..c8ed760122c 100644 --- a/panda/src/display/displayRegion.cxx +++ b/panda/src/display/displayRegion.cxx @@ -358,7 +358,7 @@ output(std::ostream &out) const { * screenshot-extension All other % strings in strftime(). */ Filename DisplayRegion:: -make_screenshot_filename(const string &prefix) { +make_screenshot_filename(std::string_view prefix) { time_t now = time(nullptr); struct tm *ttm = localtime(&now); int frame_count = ClockObject::get_global_clock()->get_frame_count(); @@ -425,7 +425,7 @@ make_screenshot_filename(const string &prefix) { * generated by make_screenshot_filename(). */ Filename DisplayRegion:: -save_screenshot_default(const string &prefix) { +save_screenshot_default(std::string_view prefix) { Filename filename = make_screenshot_filename(prefix); if (save_screenshot(filename)) { return filename; @@ -438,13 +438,13 @@ save_screenshot_default(const string &prefix) { * on success, false on failure. */ bool DisplayRegion:: -save_screenshot(const Filename &filename, const string &image_comment) { +save_screenshot(const Filename &filename, std::string image_comment) { PNMImage image; if (!get_screenshot(image)) { return false; } - image.set_comment(image_comment); + image.set_comment(std::move(image_comment)); if (!image.write(filename)) { return false; } diff --git a/panda/src/display/displayRegion.h b/panda/src/display/displayRegion.h index 571f5f4ef3b..779213d747c 100644 --- a/panda/src/display/displayRegion.h +++ b/panda/src/display/displayRegion.h @@ -156,10 +156,10 @@ class EXPCL_PANDA_DISPLAY DisplayRegion : public TypedReferenceCount, public Dra virtual void output(std::ostream &out) const; static Filename make_screenshot_filename( - const std::string &prefix = "screenshot"); - Filename save_screenshot_default(const std::string &prefix = "screenshot"); + std::string_view prefix = "screenshot"); + Filename save_screenshot_default(std::string_view prefix = "screenshot"); bool save_screenshot( - const Filename &filename, const std::string &image_comment = ""); + const Filename &filename, std::string image_comment = ""); bool get_screenshot(PNMImage &image); PT(Texture) get_screenshot(); diff --git a/panda/src/display/frameBufferProperties.cxx b/panda/src/display/frameBufferProperties.cxx index 4f27007cbc8..2898d3aa441 100644 --- a/panda/src/display/frameBufferProperties.cxx +++ b/panda/src/display/frameBufferProperties.cxx @@ -631,7 +631,7 @@ get_quality(const FrameBufferProperties &reqs) const { * false. */ bool FrameBufferProperties:: -verify_hardware_software(const FrameBufferProperties &props, const std::string &renderer) const { +verify_hardware_software(const FrameBufferProperties &props, std::string_view renderer) const { if (get_force_hardware() < props.get_force_hardware()) { display_cat.error() diff --git a/panda/src/display/frameBufferProperties.h b/panda/src/display/frameBufferProperties.h index 573c866c76b..249ef814b63 100644 --- a/panda/src/display/frameBufferProperties.h +++ b/panda/src/display/frameBufferProperties.h @@ -169,7 +169,7 @@ class EXPCL_PANDA_DISPLAY FrameBufferProperties { bool is_basic() const; int get_aux_mask() const; int get_buffer_mask() const; - bool verify_hardware_software(const FrameBufferProperties &props, const std::string &renderer) const; + bool verify_hardware_software(const FrameBufferProperties &props, std::string_view renderer) const; bool setup_color_texture(Texture *tex) const; bool setup_depth_texture(Texture *tex) const; diff --git a/panda/src/display/graphicsBuffer.cxx b/panda/src/display/graphicsBuffer.cxx index 6955305a96c..eeee5cd0497 100644 --- a/panda/src/display/graphicsBuffer.cxx +++ b/panda/src/display/graphicsBuffer.cxx @@ -21,12 +21,12 @@ TypeHandle GraphicsBuffer::_type_handle; */ GraphicsBuffer:: GraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsOutput(engine, pipe, name, fb_prop, win_prop, flags, gsg, host, false) + GraphicsOutput(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host, false) { #ifdef DO_MEMORY_USAGE MemoryUsage::update_type(this, this); diff --git a/panda/src/display/graphicsBuffer.h b/panda/src/display/graphicsBuffer.h index 5c7e833f57c..98e2b30f754 100644 --- a/panda/src/display/graphicsBuffer.h +++ b/panda/src/display/graphicsBuffer.h @@ -28,7 +28,7 @@ class EXPCL_PANDA_DISPLAY GraphicsBuffer : public GraphicsOutput { protected: GraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/display/graphicsEngine.I b/panda/src/display/graphicsEngine.I index ca9142a8a81..674f158181b 100644 --- a/panda/src/display/graphicsEngine.I +++ b/panda/src/display/graphicsEngine.I @@ -104,7 +104,7 @@ close_gsg(GraphicsPipe *pipe, GraphicsStateGuardian *gsg) { * sharing of resources. */ INLINE GraphicsOutput *GraphicsEngine:: -make_buffer(GraphicsOutput *host, const std::string &name, +make_buffer(GraphicsOutput *host, std::string_view name, int sort, int x_size, int y_size) { GraphicsOutput *result = make_output(host->get_pipe(), name, sort, FrameBufferProperties(), @@ -130,7 +130,7 @@ make_buffer(GraphicsOutput *host, const std::string &name, * the first parameter. */ INLINE GraphicsOutput *GraphicsEngine:: -make_buffer(GraphicsStateGuardian *gsg, const std::string &name, +make_buffer(GraphicsStateGuardian *gsg, std::string_view name, int sort, int x_size, int y_size) { FrameBufferProperties fb_props = FrameBufferProperties::get_default(); fb_props.set_back_buffers(0); @@ -152,7 +152,7 @@ make_buffer(GraphicsStateGuardian *gsg, const std::string &name, * Syntactic shorthand for make_buffer. */ INLINE GraphicsOutput *GraphicsEngine:: -make_parasite(GraphicsOutput *host, const std::string &name, +make_parasite(GraphicsOutput *host, std::string_view name, int sort, int x_size, int y_size) { GraphicsOutput *result = make_output(host->get_pipe(), name, sort, FrameBufferProperties(), @@ -195,29 +195,20 @@ run_on_draw_thread(Callable &&callable) -> decltype(callable()) { */ template INLINE auto GraphicsEngine::RenderThread:: -run_on_thread(Callable &&callable) -> - typename std::enable_if::value, decltype(callable())>::type { - +run_on_thread(Callable &&callable) -> decltype(callable()) { using ReturnType = decltype(callable()); - alignas(ReturnType) unsigned char storage[sizeof(ReturnType)]; - - run_on_thread([] (RenderThread *data) { - new (data->_return_data) ReturnType(std::move(*(Callable *)data->_callback_data)()); - }, &callable, storage); + if constexpr (std::is_void::value) { + run_on_thread([] (RenderThread *data) { + std::move(*(Callable *)data->_callback_data)(); + }, &callable, nullptr); + } else { + alignas(ReturnType) unsigned char storage[sizeof(ReturnType)]; - return *(ReturnType *)storage; -} + run_on_thread([] (RenderThread *data) { + new (data->_return_data) ReturnType(std::move(*(Callable *)data->_callback_data)()); + }, &callable, storage); -/** - * Waits for this thread to become idle, then runs the given function on it. - */ -template -INLINE auto GraphicsEngine::RenderThread:: -run_on_thread(Callable &&callable) -> - typename std::enable_if::value, decltype(callable())>::type { - - run_on_thread([] (RenderThread *data) { - std::move(*(Callable *)data->_callback_data)(); - }, &callable, nullptr); + return *std::launder(reinterpret_cast(storage)); + } } #endif // CPPPARSER diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index 12f77d82357..26959c55eec 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -264,7 +264,7 @@ get_threading_model() const { GraphicsOutput *GraphicsEngine:: make_output(GraphicsPipe *pipe, - const string &name, int sort, + std::string_view name, int sort, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -356,7 +356,7 @@ make_output(GraphicsPipe *pipe, this_gsg = pipe->make_callback_gsg(this); } if (this_gsg != nullptr) { - CallbackGraphicsWindow *window = new CallbackGraphicsWindow(this, pipe, name, fb_prop, win_prop, flags, this_gsg); + CallbackGraphicsWindow *window = new CallbackGraphicsWindow(this, pipe, std::string(name), fb_prop, win_prop, flags, this_gsg); window->_sort = sort; do_add_window(window); do_add_gsg(window->get_gsg(), pipe); @@ -396,7 +396,7 @@ make_output(GraphicsPipe *pipe, (x_size <= host->get_x_size())&& (y_size <= host->get_y_size())&& (host->get_fb_properties().subsumes(fb_prop))) { - ParasiteBuffer *buffer = new ParasiteBuffer(host, name, x_size, y_size, flags); + ParasiteBuffer *buffer = new ParasiteBuffer(host, std::string(name), x_size, y_size, flags); buffer->_sort = sort; do_add_window(buffer); do_add_gsg(host->get_gsg(), pipe); @@ -408,7 +408,7 @@ make_output(GraphicsPipe *pipe, // less than ideal. You might set this if you really don't trust your // graphics driver's support for offscreen buffers. if (force_parasite_buffer && can_use_parasite) { - ParasiteBuffer *buffer = new ParasiteBuffer(host, name, x_size, y_size, flags); + ParasiteBuffer *buffer = new ParasiteBuffer(host, std::string(name), x_size, y_size, flags); buffer->_sort = sort; do_add_window(buffer); do_add_gsg(host->get_gsg(), pipe); @@ -469,7 +469,7 @@ make_output(GraphicsPipe *pipe, // window to the user's specs. Try a parasite as a last hope. if (can_use_parasite) { - ParasiteBuffer *buffer = new ParasiteBuffer(host, name, x_size, y_size, flags); + ParasiteBuffer *buffer = new ParasiteBuffer(host, std::string(name), x_size, y_size, flags); buffer->_sort = sort; do_add_window(buffer); do_add_gsg(host->get_gsg(), pipe); @@ -2548,7 +2548,7 @@ get_invert_polygon_state() { * You must already be holding the lock before calling this method. */ GraphicsEngine::WindowRenderer *GraphicsEngine:: -get_window_renderer(const string &name, int pipeline_stage) { +get_window_renderer(std::string_view name, int pipeline_stage) { nassertr(_lock.debug_is_locked(), nullptr); if (name.empty()) { @@ -2566,7 +2566,7 @@ get_window_renderer(const string &name, int pipeline_stage) { bool started = thread->start(TP_normal, true); nassertr(started, thread.p()); - _threads[name] = thread; + _threads[std::string(name)] = thread; nassertr(thread->get_pipeline_stage() < _pipeline->get_num_stages(), thread.p()); @@ -2577,8 +2577,8 @@ get_window_renderer(const string &name, int pipeline_stage) { * */ GraphicsEngine::WindowRenderer:: -WindowRenderer(const string &name) : - _wl_lock(string("GraphicsEngine::WindowRenderer::_wl_lock ") + name) +WindowRenderer(std::string_view name) : + _wl_lock(std::string("GraphicsEngine::WindowRenderer::_wl_lock ").append(name)) { } @@ -2846,11 +2846,11 @@ any_done_gsgs() const { * */ GraphicsEngine::RenderThread:: -RenderThread(const string &name, GraphicsEngine *engine) : - Thread(name, "Main"), +RenderThread(std::string_view name, GraphicsEngine *engine) : + Thread(std::string(name), "Main"), WindowRenderer(name), _engine(engine), - _cv_mutex(string("GraphicsEngine::RenderThread ") + name), + _cv_mutex(std::string("GraphicsEngine::RenderThread ").append(name)), _cv_start(_cv_mutex), _cv_done(_cv_mutex) { diff --git a/panda/src/display/graphicsEngine.h b/panda/src/display/graphicsEngine.h index 65cf8a7710d..a81bd874613 100644 --- a/panda/src/display/graphicsEngine.h +++ b/panda/src/display/graphicsEngine.h @@ -80,7 +80,7 @@ class EXPCL_PANDA_DISPLAY GraphicsEngine : public ReferenceCount { MAKE_PROPERTY(default_loader, get_default_loader, set_default_loader); GraphicsOutput *make_output(GraphicsPipe *pipe, - const std::string &name, int sort, + std::string_view name, int sort, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg = nullptr, @@ -88,13 +88,13 @@ class EXPCL_PANDA_DISPLAY GraphicsEngine : public ReferenceCount { // Syntactic shorthand versions of make_output INLINE GraphicsOutput *make_buffer(GraphicsOutput *host, - const std::string &name, int sort, + std::string_view name, int sort, int x_size, int y_size); INLINE GraphicsOutput *make_buffer(GraphicsStateGuardian *gsg, - const std::string &name, int sort, + std::string_view name, int sort, int x_size, int y_size); INLINE GraphicsOutput *make_parasite(GraphicsOutput *host, - const std::string &name, int sort, + std::string_view name, int sort, int x_size, int y_size); bool add_window(GraphicsOutput *window, int sort); @@ -280,7 +280,7 @@ class EXPCL_PANDA_DISPLAY GraphicsEngine : public ReferenceCount { class WindowRenderer { public: - WindowRenderer(const std::string &name); + WindowRenderer(std::string_view name); void add_gsg(GraphicsStateGuardian *gsg); void add_window(Windows &wlist, GraphicsOutput *window); @@ -311,7 +311,7 @@ class EXPCL_PANDA_DISPLAY GraphicsEngine : public ReferenceCount { class RenderThread : public Thread, public WindowRenderer { public: - RenderThread(const std::string &name, GraphicsEngine *engine); + RenderThread(std::string_view name, GraphicsEngine *engine); virtual void thread_main(); typedef void Callback(RenderThread *thread); @@ -321,12 +321,7 @@ class EXPCL_PANDA_DISPLAY GraphicsEngine : public ReferenceCount { #ifndef CPPPARSER template - INLINE auto run_on_thread(Callable &&callable) -> - typename std::enable_if::value, decltype(callable())>::type; - - template - INLINE auto run_on_thread(Callable &&callable) -> - typename std::enable_if::value, decltype(callable())>::type; + INLINE auto run_on_thread(Callable &&callable) -> decltype(callable()); #endif GraphicsEngine *_engine; @@ -341,7 +336,7 @@ class EXPCL_PANDA_DISPLAY GraphicsEngine : public ReferenceCount { void *_return_data; }; - WindowRenderer *get_window_renderer(const std::string &name, int pipeline_stage); + WindowRenderer *get_window_renderer(std::string_view name, int pipeline_stage); Pipeline *_pipeline; ClockObject *const _clock; @@ -355,7 +350,7 @@ class EXPCL_PANDA_DISPLAY GraphicsEngine : public ReferenceCount { NewWindows _new_windows; WindowRenderer _app; - typedef pmap Threads; + typedef pmap > Threads; Threads _threads; GraphicsThreadingModel _threading_model; bool _threading_model_changed; diff --git a/panda/src/display/graphicsOutput.I b/panda/src/display/graphicsOutput.I index 1f4e2d87a40..7f3402e8077 100644 --- a/panda/src/display/graphicsOutput.I +++ b/panda/src/display/graphicsOutput.I @@ -602,7 +602,7 @@ get_overlay_display_region() const { * screenshot-extension All other % strings in strftime(). */ INLINE Filename GraphicsOutput:: -make_screenshot_filename(const std::string &prefix) { +make_screenshot_filename(std::string_view prefix) { return DisplayRegion::make_screenshot_filename(prefix); } @@ -612,7 +612,7 @@ make_screenshot_filename(const std::string &prefix) { * generated by make_screenshot_filename(). */ INLINE Filename GraphicsOutput:: -save_screenshot_default(const std::string &prefix) { +save_screenshot_default(std::string_view prefix) { return _overlay_display_region->save_screenshot_default(prefix); } @@ -623,8 +623,8 @@ save_screenshot_default(const std::string &prefix) { * jpg allows comments). Returns true on success, false on failure. */ INLINE bool GraphicsOutput:: -save_screenshot(const Filename &filename, const std::string &image_comment) { - return _overlay_display_region->save_screenshot(filename, image_comment); +save_screenshot(const Filename &filename, std::string image_comment) { + return _overlay_display_region->save_screenshot(filename, std::move(image_comment)); } /** diff --git a/panda/src/display/graphicsOutput.cxx b/panda/src/display/graphicsOutput.cxx index 39b5de51407..d44ae9ad3de 100644 --- a/panda/src/display/graphicsOutput.cxx +++ b/panda/src/display/graphicsOutput.cxx @@ -67,7 +67,7 @@ static CubeFaceDef cube_faces[6] = { */ GraphicsOutput:: GraphicsOutput(GraphicsEngine *engine, GraphicsPipe *pipe, - const string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -88,7 +88,7 @@ GraphicsOutput(GraphicsEngine *engine, GraphicsPipe *pipe, _gsg = gsg; _host = host; _fb_properties = fb_prop; - _name = name; + _name = std::move(name); _creation_flags = flags; _has_size = win_prop.has_size(); _is_nonzero_size = false; @@ -857,7 +857,7 @@ get_active_display_region(int n) const { * GraphicsEngine::remove_window(). */ GraphicsOutput *GraphicsOutput:: -make_texture_buffer(const string &name, int x_size, int y_size, +make_texture_buffer(std::string_view name, int x_size, int y_size, Texture *tex, bool to_ram, FrameBufferProperties *fbp) { FrameBufferProperties props; @@ -917,7 +917,7 @@ make_texture_buffer(const string &name, int x_size, int y_size, * to apply a reflection of everything seen by the camera rig. */ GraphicsOutput *GraphicsOutput:: -make_cube_map(const string &name, int size, NodePath &camera_rig, +make_cube_map(std::string_view name, int size, NodePath &camera_rig, DrawMask camera_mask, bool to_ram, FrameBufferProperties *fbp) { if (!to_ram) { // Check the limits imposed by the GSG. (However, if we're rendering the @@ -942,7 +942,7 @@ make_cube_map(const string &name, int size, NodePath &camera_rig, // behavior, he can take this effect off again. camera_rig.node()->set_effect(CompassEffect::make(NodePath())); - PT(Texture) tex = new Texture(name); + PT(Texture) tex = new Texture(std::string(name)); tex->setup_cube_map(); tex->set_wrap_u(SamplerState::WM_clamp); tex->set_wrap_v(SamplerState::WM_clamp); @@ -986,9 +986,9 @@ make_cube_map(const string &name, int size, NodePath &camera_rig, * several frames extra to complete. */ PT(ScreenshotRequest) GraphicsOutput:: -save_async_screenshot(const Filename &filename, const std::string &image_comment) { +save_async_screenshot(const Filename &filename, std::string image_comment) { PT(ScreenshotRequest) request = get_async_screenshot(); - request->add_output_file(filename, image_comment); + request->add_output_file(filename, std::move(image_comment)); return request; } @@ -1675,7 +1675,7 @@ do_determine_display_regions(GraphicsOutput::CData *cdata) { * These bitmask values are taken from ColorWriteAttrib. */ unsigned int GraphicsOutput:: -parse_color_mask(const string &word) { +parse_color_mask(std::string_view word) { unsigned int result = 0; vector_string components; tokenize(word, components, "|"); diff --git a/panda/src/display/graphicsOutput.h b/panda/src/display/graphicsOutput.h index 87d094e9aa5..683ca184ada 100644 --- a/panda/src/display/graphicsOutput.h +++ b/panda/src/display/graphicsOutput.h @@ -65,7 +65,7 @@ class EXPCL_PANDA_DISPLAY GraphicsOutput : public GraphicsOutputBase, public Dra protected: GraphicsOutput(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, @@ -225,23 +225,23 @@ class EXPCL_PANDA_DISPLAY GraphicsOutput : public GraphicsOutputBase, public Dra MAKE_SEQ_PROPERTY(active_display_regions, get_num_active_display_regions, get_active_display_region); GraphicsOutput *make_texture_buffer( - const std::string &name, int x_size, int y_size, + std::string_view name, int x_size, int y_size, Texture *tex = nullptr, bool to_ram = false, FrameBufferProperties *fbp = nullptr); - GraphicsOutput *make_cube_map(const std::string &name, int size, + GraphicsOutput *make_cube_map(std::string_view name, int size, NodePath &camera_rig, DrawMask camera_mask = PandaNode::get_all_camera_mask(), bool to_ram = false, FrameBufferProperties *fbp = nullptr); INLINE static Filename make_screenshot_filename( - const std::string &prefix = "screenshot"); + std::string_view prefix = "screenshot"); INLINE Filename save_screenshot_default( - const std::string &prefix = "screenshot"); + std::string_view prefix = "screenshot"); INLINE bool save_screenshot( - const Filename &filename, const std::string &image_comment = ""); + const Filename &filename, std::string image_comment = ""); INLINE bool get_screenshot(PNMImage &image); INLINE PT(Texture) get_screenshot(); PT(ScreenshotRequest) save_async_screenshot(const Filename &filename, - const std::string &image_comment = ""); + std::string image_comment = ""); PT(ScreenshotRequest) get_async_screenshot(); NodePath get_texture_card(); @@ -322,7 +322,7 @@ class EXPCL_PANDA_DISPLAY GraphicsOutput : public GraphicsOutputBase, public Dra INLINE void determine_display_regions() const; void do_determine_display_regions(CData *cdata); - static unsigned int parse_color_mask(const std::string &word); + static unsigned int parse_color_mask(std::string_view word); protected: PT(GraphicsStateGuardian) _gsg; diff --git a/panda/src/display/graphicsPipe.cxx b/panda/src/display/graphicsPipe.cxx index c548ff16ab7..e1c50f563a0 100644 --- a/panda/src/display/graphicsPipe.cxx +++ b/panda/src/display/graphicsPipe.cxx @@ -262,7 +262,7 @@ close_gsg(GraphicsStateGuardian *gsg) { * Creates a new window on the pipe, if possible. */ PT(GraphicsOutput) GraphicsPipe:: -make_output(const std::string &name, +make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/display/graphicsPipe.h b/panda/src/display/graphicsPipe.h index 34ec0e112b9..cc9b79628da 100644 --- a/panda/src/display/graphicsPipe.h +++ b/panda/src/display/graphicsPipe.h @@ -122,7 +122,7 @@ class EXPCL_PANDA_DISPLAY GraphicsPipe : public TypedReferenceCount { virtual void close_gsg(GraphicsStateGuardian *gsg); - virtual PT(GraphicsOutput) make_output(const std::string &name, + virtual PT(GraphicsOutput) make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/display/graphicsPipeSelection.cxx b/panda/src/display/graphicsPipeSelection.cxx index 24fd0b5ffc9..c0ee44379d0 100644 --- a/panda/src/display/graphicsPipeSelection.cxx +++ b/panda/src/display/graphicsPipeSelection.cxx @@ -148,7 +148,7 @@ print_pipe_types() const { * module, or if module_name is empty, it will call load_aux_modules(). */ PT(GraphicsPipe) GraphicsPipeSelection:: -make_pipe(const string &type_name, const string &module_name) { +make_pipe(std::string_view type_name, std::string_view module_name) { TypeRegistry *type_reg = TypeRegistry::ptr(); // First, see if the type is already available. @@ -234,7 +234,7 @@ make_pipe(TypeHandle type) { * GraphicsPipe. */ PT(GraphicsPipe) GraphicsPipeSelection:: -make_module_pipe(const string &module_name) { +make_module_pipe(std::string_view module_name) { if (display_cat.is_debug()) { display_cat.debug() << "make_module_pipe(" << module_name << ")\n"; @@ -399,7 +399,7 @@ do_load_default_module() { * TypeHandle::none() on failure. */ TypeHandle GraphicsPipeSelection:: -load_named_module(const string &name) { +load_named_module(std::string_view name) { LightMutexHolder holder(_loaded_modules_lock); LoadedModules::iterator mi = _loaded_modules.find(name); @@ -409,7 +409,7 @@ load_named_module(const string &name) { } // We have not yet loaded this module. Load it now. - Filename dlname = Filename::dso_filename("lib" + name + ".so"); + Filename dlname = Filename::dso_filename(std::string("lib").append(name).append(".so")); display_cat.info() << "loading display module: " << dlname.to_os_specific() << std::endl; void *handle = load_dso(get_plugin_path().get_value(), dlname); @@ -422,7 +422,7 @@ load_named_module(const string &name) { // Now get the module's recommended pipe type. This requires calling a // specially-named function that should have been exported from the module. - string symbol_name = "get_pipe_type_" + name; + string symbol_name = std::string("get_pipe_type_").append(name); void *dso_symbol = get_dso_symbol(handle, symbol_name); if (display_cat.is_debug()) { display_cat.debug() @@ -468,7 +468,7 @@ load_named_module(const string &name) { << "\n"; } - LoadedModule &module = _loaded_modules[name]; + LoadedModule &module = _loaded_modules[std::string(name)]; module._module_name = name; module._module_handle = handle; module._default_pipe_type = pipe_type; diff --git a/panda/src/display/graphicsPipeSelection.h b/panda/src/display/graphicsPipeSelection.h index 42445336d7c..3584ac5ff2e 100644 --- a/panda/src/display/graphicsPipeSelection.h +++ b/panda/src/display/graphicsPipeSelection.h @@ -41,10 +41,10 @@ class EXPCL_PANDA_DISPLAY GraphicsPipeSelection { MAKE_SEQ_PROPERTY(pipe_types, get_num_pipe_types, get_pipe_type); void print_pipe_types() const; - PT(GraphicsPipe) make_pipe(const std::string &type_name, - const std::string &module_name = std::string()); + PT(GraphicsPipe) make_pipe(std::string_view type_name, + std::string_view module_name = std::string_view()); PT(GraphicsPipe) make_pipe(TypeHandle type); - PT(GraphicsPipe) make_module_pipe(const std::string &module_name); + PT(GraphicsPipe) make_module_pipe(std::string_view module_name); PT(GraphicsPipe) make_default_pipe(); INLINE int get_num_aux_modules() const; @@ -61,7 +61,7 @@ class EXPCL_PANDA_DISPLAY GraphicsPipeSelection { private: INLINE void load_default_module() const; void do_load_default_module(); - TypeHandle load_named_module(const std::string &name); + TypeHandle load_named_module(std::string_view name); class LoadedModule { public: @@ -69,7 +69,7 @@ class EXPCL_PANDA_DISPLAY GraphicsPipeSelection { void *_module_handle; TypeHandle _default_pipe_type; }; - typedef pmap LoadedModules; + typedef pmap> LoadedModules; LoadedModules _loaded_modules; LightMutex _loaded_modules_lock; diff --git a/panda/src/display/graphicsStateGuardian.cxx b/panda/src/display/graphicsStateGuardian.cxx index 528f6830eca..9a318a2335b 100644 --- a/panda/src/display/graphicsStateGuardian.cxx +++ b/panda/src/display/graphicsStateGuardian.cxx @@ -4027,7 +4027,7 @@ ensure_generated_shader(const RenderState *state) { * string. This currently is only implemented by the OpenGL back-end. */ bool GraphicsStateGuardian:: -has_extension(const string &extension) const { +has_extension(std::string_view extension) const { return false; } diff --git a/panda/src/display/graphicsStateGuardian.h b/panda/src/display/graphicsStateGuardian.h index eea337ead8e..df700f80054 100644 --- a/panda/src/display/graphicsStateGuardian.h +++ b/panda/src/display/graphicsStateGuardian.h @@ -276,7 +276,7 @@ class EXPCL_PANDA_DISPLAY GraphicsStateGuardian : public GraphicsStateGuardianBa #endif // !NDEBUG || !CPPPARSER PUBLISHED: - virtual bool has_extension(const std::string &extension) const; + virtual bool has_extension(std::string_view extension) const; virtual std::string get_driver_vendor(); virtual std::string get_driver_renderer(); diff --git a/panda/src/display/graphicsThreadingModel.I b/panda/src/display/graphicsThreadingModel.I index 98707b16cb2..e8651c36719 100644 --- a/panda/src/display/graphicsThreadingModel.I +++ b/panda/src/display/graphicsThreadingModel.I @@ -50,8 +50,8 @@ get_cull_name() const { * this only has an effect on newly-opened windows. */ INLINE void GraphicsThreadingModel:: -set_cull_name(const std::string &cull_name) { - _cull_name = cull_name; +set_cull_name(std::string cull_name) { + _cull_name = std::move(cull_name); update_stages(); } @@ -80,8 +80,8 @@ get_draw_name() const { * this only has an effect on newly-opened windows. */ INLINE void GraphicsThreadingModel:: -set_draw_name(const std::string &draw_name) { - _draw_name = draw_name; +set_draw_name(std::string draw_name) { + _draw_name = std::move(draw_name); update_stages(); } diff --git a/panda/src/display/graphicsThreadingModel.cxx b/panda/src/display/graphicsThreadingModel.cxx index 22357206daf..f2cf73b122d 100644 --- a/panda/src/display/graphicsThreadingModel.cxx +++ b/panda/src/display/graphicsThreadingModel.cxx @@ -38,7 +38,7 @@ using std::string; * in scene graph order; state sorting and alpha sorting is lost. */ GraphicsThreadingModel:: -GraphicsThreadingModel(const string &model) { +GraphicsThreadingModel(std::string_view model) { _cull_sorting = true; size_t start = 0; if (!model.empty() && model[0] == '-') { @@ -47,7 +47,7 @@ GraphicsThreadingModel(const string &model) { } size_t slash = model.find('/', start); - if (slash == string::npos) { + if (slash == std::string_view::npos) { _cull_name = model.substr(start); } else { _cull_name = model.substr(start, slash - start); diff --git a/panda/src/display/graphicsThreadingModel.h b/panda/src/display/graphicsThreadingModel.h index 7f0cf519af8..6330fe5f1cc 100644 --- a/panda/src/display/graphicsThreadingModel.h +++ b/panda/src/display/graphicsThreadingModel.h @@ -22,17 +22,17 @@ */ class EXPCL_PANDA_DISPLAY GraphicsThreadingModel { PUBLISHED: - GraphicsThreadingModel(const std::string &model = std::string()); + GraphicsThreadingModel(std::string_view model = std::string_view()); INLINE GraphicsThreadingModel(const GraphicsThreadingModel ©); INLINE void operator = (const GraphicsThreadingModel ©); std::string get_model() const; INLINE const std::string &get_cull_name() const; - INLINE void set_cull_name(const std::string &cull_name); + INLINE void set_cull_name(std::string cull_name); INLINE int get_cull_stage() const; INLINE const std::string &get_draw_name() const; - INLINE void set_draw_name(const std::string &cull_name); + INLINE void set_draw_name(std::string cull_name); INLINE int get_draw_stage() const; INLINE bool get_cull_sorting() const; diff --git a/panda/src/display/graphicsWindow.cxx b/panda/src/display/graphicsWindow.cxx index 377da09f04c..85f04cbe883 100644 --- a/panda/src/display/graphicsWindow.cxx +++ b/panda/src/display/graphicsWindow.cxx @@ -31,7 +31,7 @@ TypeHandle GraphicsWindow::_type_handle; */ GraphicsWindow:: GraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -179,9 +179,9 @@ is_active() const { * parameter: the window itself. */ void GraphicsWindow:: -set_window_event(const string &window_event) { +set_window_event(std::string window_event) { LightReMutexHolder holder(_properties_lock); - _window_event = window_event; + _window_event = std::move(window_event); } /** @@ -215,9 +215,9 @@ get_window_event() const { * app, or reboot the machine). */ void GraphicsWindow:: -set_close_request_event(const string &close_request_event) { +set_close_request_event(std::string close_request_event) { LightReMutexHolder holder(_properties_lock); - _close_request_event = close_request_event; + _close_request_event = std::move(close_request_event); } /** diff --git a/panda/src/display/graphicsWindow.h b/panda/src/display/graphicsWindow.h index 33fb4174d76..cfeea3e869e 100644 --- a/panda/src/display/graphicsWindow.h +++ b/panda/src/display/graphicsWindow.h @@ -41,7 +41,7 @@ class EXPCL_PANDA_DISPLAY GraphicsWindow : public GraphicsOutput { protected: GraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -67,11 +67,11 @@ class EXPCL_PANDA_DISPLAY GraphicsWindow : public GraphicsOutput { MAKE_PROPERTY(rejected_properties, get_rejected_properties); MAKE_PROPERTY(closed, is_closed); - void set_window_event(const std::string &window_event); + void set_window_event(std::string window_event); std::string get_window_event() const; MAKE_PROPERTY(window_event, get_window_event, set_window_event); - void set_close_request_event(const std::string &close_request_event); + void set_close_request_event(std::string close_request_event); std::string get_close_request_event() const; MAKE_PROPERTY(close_request_event, get_close_request_event, set_close_request_event); diff --git a/panda/src/display/graphicsWindowInputDevice.cxx b/panda/src/display/graphicsWindowInputDevice.cxx index 6eb1c61d44d..1eafe455844 100644 --- a/panda/src/display/graphicsWindowInputDevice.cxx +++ b/panda/src/display/graphicsWindowInputDevice.cxx @@ -29,8 +29,8 @@ using std::string; * below. */ GraphicsWindowInputDevice:: -GraphicsWindowInputDevice(GraphicsWindow *host, const string &name, bool pointer, bool keyboard) : - InputDevice(name, DeviceClass::VIRTUAL) +GraphicsWindowInputDevice(GraphicsWindow *host, std::string name, bool pointer, bool keyboard) : + InputDevice(std::move(name), DeviceClass::VIRTUAL) { if (pointer) { enable_feature(Feature::POINTER); @@ -46,8 +46,8 @@ GraphicsWindowInputDevice(GraphicsWindow *host, const string &name, bool pointer * device, no keyboard. */ PT(GraphicsWindowInputDevice) GraphicsWindowInputDevice:: -pointer_only(GraphicsWindow *host, const string &name) { - return new GraphicsWindowInputDevice(host, name, true, false); +pointer_only(GraphicsWindow *host, std::string name) { + return new GraphicsWindowInputDevice(host, std::move(name), true, false); } /** @@ -55,8 +55,8 @@ pointer_only(GraphicsWindow *host, const string &name) { * pointing device. */ PT(GraphicsWindowInputDevice) GraphicsWindowInputDevice:: -keyboard_only(GraphicsWindow *host, const string &name) { - return new GraphicsWindowInputDevice(host, name, false, true); +keyboard_only(GraphicsWindow *host, std::string name) { + return new GraphicsWindowInputDevice(host, std::move(name), false, true); } /** @@ -64,8 +64,8 @@ keyboard_only(GraphicsWindow *host, const string &name) { * pointer. */ PT(GraphicsWindowInputDevice) GraphicsWindowInputDevice:: -pointer_and_keyboard(GraphicsWindow *host, const string &name) { - return new GraphicsWindowInputDevice(host, name, true, true); +pointer_and_keyboard(GraphicsWindow *host, std::string name) { + return new GraphicsWindowInputDevice(host, std::move(name), true, true); } /** @@ -115,12 +115,12 @@ keystroke(int keycode, double time) { * especially Chinese/Japanese/Korean. */ void GraphicsWindowInputDevice:: -candidate(const std::wstring &candidate_string, size_t highlight_start, +candidate(std::wstring candidate_string, size_t highlight_start, size_t highlight_end, size_t cursor_pos) { LightMutexHolder holder(_lock); - _button_events->add_event(ButtonEvent(candidate_string, - highlight_start, highlight_end, - cursor_pos)); + _button_events->add_event(ButtonEvent(std::move(candidate_string), + highlight_start, highlight_end, + cursor_pos)); } /** diff --git a/panda/src/display/graphicsWindowInputDevice.h b/panda/src/display/graphicsWindowInputDevice.h index 22317a1ab0e..7a02942d591 100644 --- a/panda/src/display/graphicsWindowInputDevice.h +++ b/panda/src/display/graphicsWindowInputDevice.h @@ -27,13 +27,13 @@ class GraphicsWindow; */ class EXPCL_PANDA_DISPLAY GraphicsWindowInputDevice : public InputDevice { private: - GraphicsWindowInputDevice(GraphicsWindow *host, const std::string &name, + GraphicsWindowInputDevice(GraphicsWindow *host, std::string name, bool pointer, bool keyboard); public: - static PT(GraphicsWindowInputDevice) pointer_only(GraphicsWindow *host, const std::string &name); - static PT(GraphicsWindowInputDevice) keyboard_only(GraphicsWindow *host, const std::string &name); - static PT(GraphicsWindowInputDevice) pointer_and_keyboard(GraphicsWindow *host, const std::string &name); + static PT(GraphicsWindowInputDevice) pointer_only(GraphicsWindow *host, std::string name); + static PT(GraphicsWindowInputDevice) keyboard_only(GraphicsWindow *host, std::string name); + static PT(GraphicsWindowInputDevice) pointer_and_keyboard(GraphicsWindow *host, std::string name); GraphicsWindowInputDevice() = default; @@ -45,7 +45,7 @@ class EXPCL_PANDA_DISPLAY GraphicsWindowInputDevice : public InputDevice { void button_up(ButtonHandle button, double time = ClockObject::get_global_clock()->get_frame_time()); void keystroke(int keycode, double time = ClockObject::get_global_clock()->get_frame_time()); - void candidate(const std::wstring &candidate_string, size_t highlight_start, + void candidate(std::wstring candidate_string, size_t highlight_start, size_t highlight_end, size_t cursor_pos); void focus_lost(double time = ClockObject::get_global_clock()->get_frame_time()); diff --git a/panda/src/display/mouseAndKeyboard.cxx b/panda/src/display/mouseAndKeyboard.cxx index 6d014ddbdb8..7f78aa1ad3a 100644 --- a/panda/src/display/mouseAndKeyboard.cxx +++ b/panda/src/display/mouseAndKeyboard.cxx @@ -24,8 +24,8 @@ TypeHandle MouseAndKeyboard::_type_handle; * */ MouseAndKeyboard:: -MouseAndKeyboard(GraphicsWindow *window, int device, const std::string &name) : - DataNode(name), +MouseAndKeyboard(GraphicsWindow *window, int device, std::string name) : + DataNode(std::move(name)), _window(window), _device(window->get_input_device(device)) { diff --git a/panda/src/display/mouseAndKeyboard.h b/panda/src/display/mouseAndKeyboard.h index 035822a6ff0..b1f02d4205a 100644 --- a/panda/src/display/mouseAndKeyboard.h +++ b/panda/src/display/mouseAndKeyboard.h @@ -40,7 +40,7 @@ */ class EXPCL_PANDA_DISPLAY MouseAndKeyboard : public DataNode { PUBLISHED: - explicit MouseAndKeyboard(GraphicsWindow *window, int device, const std::string &name); + explicit MouseAndKeyboard(GraphicsWindow *window, int device, std::string name); void set_source(GraphicsWindow *window, int device); protected: diff --git a/panda/src/display/parasiteBuffer.cxx b/panda/src/display/parasiteBuffer.cxx index 1b23fdb653c..8850fc5a1a7 100644 --- a/panda/src/display/parasiteBuffer.cxx +++ b/panda/src/display/parasiteBuffer.cxx @@ -21,10 +21,10 @@ TypeHandle ParasiteBuffer::_type_handle; * created instead via the GraphicsEngine::make_parasite() function. */ ParasiteBuffer:: -ParasiteBuffer(GraphicsOutput *host, const std::string &name, +ParasiteBuffer(GraphicsOutput *host, std::string name, int x_size, int y_size, int flags) : GraphicsOutput(host->get_engine(), host->get_pipe(), - name, host->get_fb_properties(), + std::move(name), host->get_fb_properties(), WindowProperties::size(x_size, y_size), flags, host->get_gsg(), host, false) { diff --git a/panda/src/display/parasiteBuffer.h b/panda/src/display/parasiteBuffer.h index 3c197c068e2..95abdd74a40 100644 --- a/panda/src/display/parasiteBuffer.h +++ b/panda/src/display/parasiteBuffer.h @@ -42,7 +42,7 @@ */ class EXPCL_PANDA_DISPLAY ParasiteBuffer : public GraphicsOutput { public: - ParasiteBuffer(GraphicsOutput *host, const std::string &name, + ParasiteBuffer(GraphicsOutput *host, std::string name, int x_size, int y_size, int flags); PUBLISHED: diff --git a/panda/src/display/screenshotRequest.cxx b/panda/src/display/screenshotRequest.cxx index 8e9c8d33f17..51da0278b3d 100644 --- a/panda/src/display/screenshotRequest.cxx +++ b/panda/src/display/screenshotRequest.cxx @@ -89,11 +89,11 @@ finish() { * request is already done, performs the write synchronously. */ void ScreenshotRequest:: -add_output_file(const Filename &filename, const std::string &image_comment) { +add_output_file(const Filename &filename, std::string image_comment) { if (!done()) { LightMutexHolder holder(_lock); if (!done()) { - _output_files[filename] = image_comment; + _output_files[filename] = std::move(image_comment); return; } } @@ -101,6 +101,6 @@ add_output_file(const Filename &filename, const std::string &image_comment) { Texture *tex = get_result(); PNMImage image; tex->store(image); - image.set_comment(image_comment); + image.set_comment(std::move(image_comment)); image.write(filename); } diff --git a/panda/src/display/screenshotRequest.h b/panda/src/display/screenshotRequest.h index 8434d8c0dba..0b1e9434fe7 100644 --- a/panda/src/display/screenshotRequest.h +++ b/panda/src/display/screenshotRequest.h @@ -38,7 +38,7 @@ class EXPCL_PANDA_DISPLAY ScreenshotRequest : public AsyncFuture { PUBLISHED: void add_output_file(const Filename &filename, - const std::string &image_comment = ""); + std::string image_comment = ""); private: // It's possible to call save_screenshot multiple times in the same frame, so diff --git a/panda/src/display/subprocessWindow.cxx b/panda/src/display/subprocessWindow.cxx index 020dbde898c..0e8b36a439a 100644 --- a/panda/src/display/subprocessWindow.cxx +++ b/panda/src/display/subprocessWindow.cxx @@ -31,7 +31,7 @@ TypeHandle SubprocessWindow::_type_handle; */ SubprocessWindow:: SubprocessWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -48,7 +48,7 @@ SubprocessWindow(GraphicsEngine *engine, GraphicsPipe *pipe, // Create a texture to receive the contents of the framebuffer from the // offscreen buffer. - _texture = new Texture(name); + _texture = new Texture(std::move(name)); _fd = -1; _mmap_size = 0; diff --git a/panda/src/display/subprocessWindow.h b/panda/src/display/subprocessWindow.h index 0a887d9e8e0..01c4971585c 100644 --- a/panda/src/display/subprocessWindow.h +++ b/panda/src/display/subprocessWindow.h @@ -45,7 +45,7 @@ class SubprocessWindow : public GraphicsWindow { public: SubprocessWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/display/windowProperties.I b/panda/src/display/windowProperties.I index 51f398c6668..17066ebb353 100644 --- a/panda/src/display/windowProperties.I +++ b/panda/src/display/windowProperties.I @@ -182,8 +182,8 @@ clear_size() { * Specifies the title that should be assigned to the window. */ INLINE void WindowProperties:: -set_title(const std::string &title) { - _title = title; +set_title(std::string title) { + _title = std::move(title); _specified |= S_title; } diff --git a/panda/src/display/windowProperties.h b/panda/src/display/windowProperties.h index 215439eaa95..18701fa4f89 100644 --- a/panda/src/display/windowProperties.h +++ b/panda/src/display/windowProperties.h @@ -99,7 +99,7 @@ class EXPCL_PANDA_DISPLAY WindowProperties { MAKE_PROPERTY2(mouse_mode, has_mouse_mode, get_mouse_mode, set_mouse_mode, clear_mouse_mode); - INLINE void set_title(const std::string &title); + INLINE void set_title(std::string title); #ifdef CPPPARSER INLINE std::string get_title() const; #else // CPPPARSER diff --git a/panda/src/distort/nonlinearImager.cxx b/panda/src/distort/nonlinearImager.cxx index 7ffc2906215..2a1113a4321 100644 --- a/panda/src/distort/nonlinearImager.cxx +++ b/panda/src/distort/nonlinearImager.cxx @@ -73,7 +73,7 @@ add_screen(ProjectionScreen *screen) { * The return value is the index number of the new screen. */ int NonlinearImager:: -add_screen(const NodePath &screen, const std::string &name) { +add_screen(const NodePath &screen, std::string name) { nassertr(!screen.is_empty() && screen.node()->is_of_type(ProjectionScreen::get_class_type()), -1); @@ -83,7 +83,7 @@ add_screen(const NodePath &screen, const std::string &name) { Screen &new_screen = _screens.back(); new_screen._screen = screen; new_screen._screen_node = screen_node; - new_screen._name = name; + new_screen._name = std::move(name); new_screen._buffer = nullptr; new_screen._tex_width = 256; new_screen._tex_height = 256; diff --git a/panda/src/distort/nonlinearImager.h b/panda/src/distort/nonlinearImager.h index aa07854df75..1dcaa3dbef5 100644 --- a/panda/src/distort/nonlinearImager.h +++ b/panda/src/distort/nonlinearImager.h @@ -84,7 +84,7 @@ class EXPCL_PANDAFX NonlinearImager { ~NonlinearImager(); int add_screen(ProjectionScreen *screen); - int add_screen(const NodePath &screen, const std::string &name); + int add_screen(const NodePath &screen, std::string name); int find_screen(const NodePath &screen) const; void remove_screen(int index); void remove_all_screens(); diff --git a/panda/src/distort/projectionScreen.I b/panda/src/distort/projectionScreen.I index 2ff54cfeb5e..bb686e897a5 100644 --- a/panda/src/distort/projectionScreen.I +++ b/panda/src/distort/projectionScreen.I @@ -67,7 +67,7 @@ get_undist_lut() const { * stages of the multitexture pipeline. */ INLINE void ProjectionScreen:: -set_texcoord_name(const std::string &texcoord_name) { +set_texcoord_name(std::string_view texcoord_name) { _texcoord_name = InternalName::get_texcoord_name(texcoord_name); _stale = true; } diff --git a/panda/src/distort/projectionScreen.cxx b/panda/src/distort/projectionScreen.cxx index ff77e4448c7..3f29ef14f04 100644 --- a/panda/src/distort/projectionScreen.cxx +++ b/panda/src/distort/projectionScreen.cxx @@ -30,7 +30,7 @@ TypeHandle ProjectionScreen::_type_handle; * */ ProjectionScreen:: -ProjectionScreen(const std::string &name) : PandaNode(name) +ProjectionScreen(std::string name) : PandaNode(std::move(name)) { set_cull_callback(); @@ -151,7 +151,7 @@ set_projector(const NodePath &projector) { * fraction, and make the screen smaller by the inverse fraction. */ PT(GeomNode) ProjectionScreen:: -generate_screen(const NodePath &projector, const std::string &screen_name, +generate_screen(const NodePath &projector, std::string screen_name, int num_x_verts, int num_y_verts, PN_stdfloat distance, PN_stdfloat fill_ratio) { nassertr(!projector.is_empty() && @@ -166,7 +166,7 @@ generate_screen(const NodePath &projector, const std::string &screen_name, rel_mat = projector.get_transform(this_np)->get_mat(); // Create a GeomNode to hold this mesh. - PT(GeomNode) geom_node = new GeomNode(screen_name); + PT(GeomNode) geom_node = new GeomNode(std::move(screen_name)); // Now compute all the vertices for the screen. These are arranged in order // from left to right and bottom to top. @@ -237,7 +237,7 @@ generate_screen(const NodePath &projector, const std::string &screen_name, * generated child returned by generate_screen(). */ void ProjectionScreen:: -regenerate_screen(const NodePath &projector, const std::string &screen_name, +regenerate_screen(const NodePath &projector, std::string screen_name, int num_x_verts, int num_y_verts, PN_stdfloat distance, PN_stdfloat fill_ratio) { // First, remove all existing children. @@ -245,7 +245,7 @@ regenerate_screen(const NodePath &projector, const std::string &screen_name, // And attach a new child. PT(GeomNode) geom_node = - generate_screen(projector, screen_name, num_x_verts, num_y_verts, + generate_screen(projector, std::move(screen_name), num_x_verts, num_y_verts, distance, fill_ratio); add_child(geom_node); } diff --git a/panda/src/distort/projectionScreen.h b/panda/src/distort/projectionScreen.h index ef90ebb070d..8878d5b30c8 100644 --- a/panda/src/distort/projectionScreen.h +++ b/panda/src/distort/projectionScreen.h @@ -47,7 +47,7 @@ class WorkingNodePath; */ class EXPCL_PANDAFX ProjectionScreen : public PandaNode { PUBLISHED: - explicit ProjectionScreen(const std::string &name = ""); + explicit ProjectionScreen(std::string name = ""); virtual ~ProjectionScreen(); protected: @@ -67,15 +67,15 @@ class EXPCL_PANDAFX ProjectionScreen : public PandaNode { INLINE const PfmFile &get_undist_lut() const; PT(GeomNode) generate_screen(const NodePath &projector, - const std::string &screen_name, + std::string screen_name, int num_x_verts, int num_y_verts, PN_stdfloat distance, PN_stdfloat fill_ratio); - void regenerate_screen(const NodePath &projector, const std::string &screen_name, + void regenerate_screen(const NodePath &projector, std::string screen_name, int num_x_verts, int num_y_verts, PN_stdfloat distance, PN_stdfloat fill_ratio); PT(PandaNode) make_flat_mesh(const NodePath &this_np, const NodePath &camera); - INLINE void set_texcoord_name(const std::string &texcoord_name); + INLINE void set_texcoord_name(std::string_view texcoord_name); INLINE std::string get_texcoord_name() const; INLINE void set_invert_uvs(bool invert_uvs); diff --git a/panda/src/downloader/bioStreamBuf.cxx b/panda/src/downloader/bioStreamBuf.cxx index ffa6a2994ec..bde4ba2e0d8 100644 --- a/panda/src/downloader/bioStreamBuf.cxx +++ b/panda/src/downloader/bioStreamBuf.cxx @@ -32,23 +32,11 @@ BioStreamBuf() { _read_open = false; _write_open = false; -#ifdef PHAVE_IOSTREAM _buffer = (char *)PANDA_MALLOC_ARRAY(8192); char *ebuf = _buffer + 8192; char *mbuf = _buffer + 4096; setg(_buffer, mbuf, mbuf); setp(mbuf, ebuf); - -#else - allocate(); - // Chop the buffer in half. The bottom half goes to the get buffer; the top - // half goes to the put buffer. - char *b = base(); - char *t = ebuf(); - char *m = b + (t - b) / 2; - setg(b, m, m); - setp(b, m); -#endif } /** @@ -57,9 +45,7 @@ BioStreamBuf() { BioStreamBuf:: ~BioStreamBuf() { close(); -#ifdef PHAVE_IOSTREAM PANDA_FREE_ARRAY(_buffer); -#endif } /** diff --git a/panda/src/downloader/chunkedStreamBuf.cxx b/panda/src/downloader/chunkedStreamBuf.cxx index f9580b8e91f..756c8dfac3a 100644 --- a/panda/src/downloader/chunkedStreamBuf.cxx +++ b/panda/src/downloader/chunkedStreamBuf.cxx @@ -28,17 +28,10 @@ ChunkedStreamBuf() { _wanted_nonblocking = false; _read_state = ISocketStream::RS_initial; -#ifdef PHAVE_IOSTREAM _buffer = (char *)PANDA_MALLOC_ARRAY(4096); char *ebuf = _buffer + 4096; setg(_buffer, ebuf, ebuf); setp(_buffer, ebuf); - -#else - allocate(); - setg(base(), ebuf(), ebuf()); - setp(base(), ebuf()); -#endif } /** @@ -47,9 +40,7 @@ ChunkedStreamBuf() { ChunkedStreamBuf:: ~ChunkedStreamBuf() { close_read(); -#ifdef PHAVE_IOSTREAM PANDA_FREE_ARRAY(_buffer); -#endif } /** diff --git a/panda/src/downloader/documentSpec.I b/panda/src/downloader/documentSpec.I index 3077ac28485..9ff924fd49f 100644 --- a/panda/src/downloader/documentSpec.I +++ b/panda/src/downloader/documentSpec.I @@ -33,6 +33,18 @@ DocumentSpec(const std::string &url) : _flags = 0; } +/** + * + */ +INLINE DocumentSpec:: +DocumentSpec(std::string_view url) : + _url(url) +{ + _request_mode = RM_any; + _cache_control = CC_allow_cache; + _flags = 0; +} + /** * */ diff --git a/panda/src/downloader/documentSpec.h b/panda/src/downloader/documentSpec.h index e78b2eca62b..46c2f9f19e5 100644 --- a/panda/src/downloader/documentSpec.h +++ b/panda/src/downloader/documentSpec.h @@ -31,6 +31,7 @@ class EXPCL_PANDA_DOWNLOADER DocumentSpec { PUBLISHED: INLINE DocumentSpec(); INLINE DocumentSpec(const std::string &url); + INLINE DocumentSpec(std::string_view url); INLINE DocumentSpec(const URLSpec &url); INLINE DocumentSpec(const DocumentSpec ©); INLINE void operator = (const DocumentSpec ©); diff --git a/panda/src/downloader/httpAuthorization.cxx b/panda/src/downloader/httpAuthorization.cxx index d0c7d284766..45c81ec0cc5 100644 --- a/panda/src/downloader/httpAuthorization.cxx +++ b/panda/src/downloader/httpAuthorization.cxx @@ -110,7 +110,7 @@ is_valid() { */ void HTTPAuthorization:: parse_authentication_schemes(HTTPAuthorization::AuthenticationSchemes &schemes, - const string &field_value) { + std::string_view field_value) { // This string will consist of one or more records of the form: scheme // token=value[,token=value[,...]] If there are multiple records, they will // be comma-delimited, which makes parsing just a bit tricky. @@ -182,7 +182,7 @@ get_canonical_url(const URLSpec &url) { * maintaining a 76-char line length. */ string HTTPAuthorization:: -base64_encode(const string &s) { +base64_encode(std::string_view s) { // Collect the string 3 bytes at a time into 24-bit words, then output each // word using 4 bytes. size_t num_words = (s.size() + 2) / 3; @@ -227,7 +227,7 @@ base64_encode(const string &s) { * Returns the string decoded from base64. */ string HTTPAuthorization:: -base64_decode(const string &s) { +base64_decode(std::string_view s) { // Build up the invert table if this is the first time. if (!got_base64_invert) { int i; @@ -279,7 +279,7 @@ base64_decode(const string &s) { * its closing quote mark). */ size_t HTTPAuthorization:: -scan_quoted_or_unquoted_string(string &result, const string &source, +scan_quoted_or_unquoted_string(string &result, std::string_view source, size_t start) { result = string(); diff --git a/panda/src/downloader/httpAuthorization.h b/panda/src/downloader/httpAuthorization.h index cf694040b5e..655dd2f6897 100644 --- a/panda/src/downloader/httpAuthorization.h +++ b/panda/src/downloader/httpAuthorization.h @@ -50,18 +50,18 @@ class EXPCL_PANDA_DOWNLOADER HTTPAuthorization : public ReferenceCount { INLINE const std::string &get_realm() const; INLINE const vector_string &get_domain() const; - virtual std::string generate(HTTPEnum::Method method, const std::string &request_path, - const std::string &username, const std::string &body)=0; + virtual std::string generate(HTTPEnum::Method method, std::string_view request_path, + std::string_view username, std::string_view body)=0; static void parse_authentication_schemes(AuthenticationSchemes &schemes, - const std::string &field_value); + std::string_view field_value); static URLSpec get_canonical_url(const URLSpec &url); - static std::string base64_encode(const std::string &s); - static std::string base64_decode(const std::string &s); + static std::string base64_encode(std::string_view s); + static std::string base64_decode(std::string_view s); protected: static size_t scan_quoted_or_unquoted_string(std::string &result, - const std::string &source, + std::string_view source, size_t start); protected: diff --git a/panda/src/downloader/httpBasicAuthorization.cxx b/panda/src/downloader/httpBasicAuthorization.cxx index 2f8a46bec44..d6abcb7cfbe 100644 --- a/panda/src/downloader/httpBasicAuthorization.cxx +++ b/panda/src/downloader/httpBasicAuthorization.cxx @@ -51,8 +51,8 @@ get_mechanism() const { * the given username:password. */ string HTTPBasicAuthorization:: -generate(HTTPEnum::Method, const string &, - const string &username, const string &) { +generate(HTTPEnum::Method, std::string_view, + std::string_view username, std::string_view) { return "Basic " + base64_encode(username); } diff --git a/panda/src/downloader/httpBasicAuthorization.h b/panda/src/downloader/httpBasicAuthorization.h index 100bcd57d0e..81a6f2fcbeb 100644 --- a/panda/src/downloader/httpBasicAuthorization.h +++ b/panda/src/downloader/httpBasicAuthorization.h @@ -37,8 +37,8 @@ class HTTPBasicAuthorization : public HTTPAuthorization { virtual ~HTTPBasicAuthorization(); virtual const std::string &get_mechanism() const; - virtual std::string generate(HTTPEnum::Method method, const std::string &request_path, - const std::string &username, const std::string &body); + virtual std::string generate(HTTPEnum::Method method, std::string_view request_path, + std::string_view username, std::string_view body); private: static const std::string _mechanism; diff --git a/panda/src/downloader/httpChannel.I b/panda/src/downloader/httpChannel.I index 1fdd7e32f2c..ee9b4bbbd8e 100644 --- a/panda/src/downloader/httpChannel.I +++ b/panda/src/downloader/httpChannel.I @@ -620,8 +620,8 @@ get_header(const DocumentSpec &url) { * Posts form data to a particular URL and retrieves the response. */ INLINE bool HTTPChannel:: -post_form(const DocumentSpec &url, const std::string &body) { - begin_request(HTTPEnum::M_post, url, body, false, 0, 0); +post_form(const DocumentSpec &url, std::string body) { + begin_request(HTTPEnum::M_post, url, std::move(body), false, 0, 0); while (run()) { } return is_valid(); @@ -632,8 +632,8 @@ post_form(const DocumentSpec &url, const std::string &body) { * the server allows this. */ INLINE bool HTTPChannel:: -put_document(const DocumentSpec &url, const std::string &body) { - begin_request(HTTPEnum::M_put, url, body, false, 0, 0); +put_document(const DocumentSpec &url, std::string body) { + begin_request(HTTPEnum::M_put, url, std::move(body), false, 0, 0); while (run()) { } return is_valid(); @@ -735,8 +735,8 @@ begin_get_header(const DocumentSpec &url) { * interim, or your form data may not get posted. */ INLINE void HTTPChannel:: -begin_post_form(const DocumentSpec &url, const std::string &body) { - begin_request(HTTPEnum::M_post, url, body, true, 0, 0); +begin_post_form(const DocumentSpec &url, std::string body) { + begin_request(HTTPEnum::M_post, url, std::move(body), true, 0, 0); } /** diff --git a/panda/src/downloader/httpChannel.cxx b/panda/src/downloader/httpChannel.cxx index bd0e1c31100..8fc2aba8728 100644 --- a/panda/src/downloader/httpChannel.cxx +++ b/panda/src/downloader/httpChannel.cxx @@ -2434,7 +2434,7 @@ run_download_to_stream() { */ void HTTPChannel:: begin_request(HTTPEnum::Method method, const DocumentSpec &url, - const string &body, bool nonblocking, + std::string body, bool nonblocking, size_t first_byte, size_t last_byte) { downloader_cat.info() @@ -2501,7 +2501,7 @@ begin_request(HTTPEnum::Method method, const DocumentSpec &url, _request = url; _document_spec = DocumentSpec(); _method = method; - _body = body; + _body = std::move(body); // An https-style request means we'll need to establish an SSL connection. _want_ssl = _request.get_url().is_ssl(); diff --git a/panda/src/downloader/httpChannel.h b/panda/src/downloader/httpChannel.h index e085079d1af..da876f664e0 100644 --- a/panda/src/downloader/httpChannel.h +++ b/panda/src/downloader/httpChannel.h @@ -167,8 +167,8 @@ class EXPCL_PANDA_DOWNLOADER HTTPChannel : public TypedReferenceCount { BLOCKING INLINE bool get_subdocument(const DocumentSpec &url, size_t first_byte, size_t last_byte); BLOCKING INLINE bool get_header(const DocumentSpec &url); - BLOCKING INLINE bool post_form(const DocumentSpec &url, const std::string &body); - BLOCKING INLINE bool put_document(const DocumentSpec &url, const std::string &body); + BLOCKING INLINE bool post_form(const DocumentSpec &url, std::string body); + BLOCKING INLINE bool put_document(const DocumentSpec &url, std::string body); BLOCKING INLINE bool delete_document(const DocumentSpec &url); BLOCKING INLINE bool get_trace(const DocumentSpec &url); BLOCKING INLINE bool connect_to(const DocumentSpec &url); @@ -178,7 +178,7 @@ class EXPCL_PANDA_DOWNLOADER HTTPChannel : public TypedReferenceCount { INLINE void begin_get_subdocument(const DocumentSpec &url, size_t first_byte, size_t last_byte); INLINE void begin_get_header(const DocumentSpec &url); - INLINE void begin_post_form(const DocumentSpec &url, const std::string &body); + INLINE void begin_post_form(const DocumentSpec &url, std::string body); bool run(); INLINE void begin_connect_to(const DocumentSpec &url); @@ -226,7 +226,7 @@ class EXPCL_PANDA_DOWNLOADER HTTPChannel : public TypedReferenceCount { bool run_download_to_stream(); void begin_request(HTTPEnum::Method method, const DocumentSpec &url, - const std::string &body, bool nonblocking, + std::string body, bool nonblocking, size_t first_byte, size_t last_byte); void reconsider_proxy(); void reset_for_new_request(); diff --git a/panda/src/downloader/httpChannel_emscripten.I b/panda/src/downloader/httpChannel_emscripten.I index ada7def14de..6931e9f289d 100644 --- a/panda/src/downloader/httpChannel_emscripten.I +++ b/panda/src/downloader/httpChannel_emscripten.I @@ -283,8 +283,8 @@ get_header(const DocumentSpec &url) { * Posts form data to a particular URL and retrieves the response. */ INLINE bool HTTPChannel:: -post_form(const DocumentSpec &url, const std::string &body) { - if (!begin_request(HTTPEnum::M_post, url, body, false, 0, 0)) { +post_form(const DocumentSpec &url, std::string body) { + if (!begin_request(HTTPEnum::M_post, url, std::move(body), false, 0, 0)) { return false; } while (run()) { @@ -297,8 +297,8 @@ post_form(const DocumentSpec &url, const std::string &body) { * the server allows this. */ INLINE bool HTTPChannel:: -put_document(const DocumentSpec &url, const std::string &body) { - if (!begin_request(HTTPEnum::M_put, url, body, false, 0, 0)) { +put_document(const DocumentSpec &url, std::string body) { + if (!begin_request(HTTPEnum::M_put, url, std::move(body), false, 0, 0)) { return false; } while (run()) { @@ -379,8 +379,8 @@ begin_get_header(const DocumentSpec &url) { * interim, or your form data may not get posted. */ INLINE void HTTPChannel:: -begin_post_form(const DocumentSpec &url, const std::string &body) { - begin_request(HTTPEnum::M_post, url, body, true, 0, 0); +begin_post_form(const DocumentSpec &url, std::string body) { + begin_request(HTTPEnum::M_post, url, std::move(body), true, 0, 0); } /** diff --git a/panda/src/downloader/httpChannel_emscripten.cxx b/panda/src/downloader/httpChannel_emscripten.cxx index 3054d065f7d..8d984c0b5af 100644 --- a/panda/src/downloader/httpChannel_emscripten.cxx +++ b/panda/src/downloader/httpChannel_emscripten.cxx @@ -430,7 +430,7 @@ run_headers_received() { */ bool HTTPChannel:: begin_request(HTTPEnum::Method method, const DocumentSpec &url, - const std::string &body, bool nonblocking, + std::string body, bool nonblocking, size_t first_byte, size_t last_byte) { downloader_cat.info() @@ -445,7 +445,7 @@ begin_request(HTTPEnum::Method method, const DocumentSpec &url, _request = url; _document_spec = DocumentSpec(); _method = method; - _body = body; + _body = std::move(body); _first_byte_requested = first_byte; _last_byte_requested = last_byte; diff --git a/panda/src/downloader/httpChannel_emscripten.h b/panda/src/downloader/httpChannel_emscripten.h index f75d9599517..08ef37191c5 100644 --- a/panda/src/downloader/httpChannel_emscripten.h +++ b/panda/src/downloader/httpChannel_emscripten.h @@ -110,8 +110,8 @@ class EXPCL_PANDA_DOWNLOADER HTTPChannel : public TypedReferenceCount { BLOCKING INLINE bool get_subdocument(const DocumentSpec &url, size_t first_byte, size_t last_byte); BLOCKING INLINE bool get_header(const DocumentSpec &url); - BLOCKING INLINE bool post_form(const DocumentSpec &url, const std::string &body); - BLOCKING INLINE bool put_document(const DocumentSpec &url, const std::string &body); + BLOCKING INLINE bool post_form(const DocumentSpec &url, std::string body); + BLOCKING INLINE bool put_document(const DocumentSpec &url, std::string body); BLOCKING INLINE bool delete_document(const DocumentSpec &url); BLOCKING INLINE bool get_options(const DocumentSpec &url); @@ -119,7 +119,7 @@ class EXPCL_PANDA_DOWNLOADER HTTPChannel : public TypedReferenceCount { INLINE void begin_get_subdocument(const DocumentSpec &url, size_t first_byte, size_t last_byte); INLINE void begin_get_header(const DocumentSpec &url); - INLINE void begin_post_form(const DocumentSpec &url, const std::string &body); + INLINE void begin_post_form(const DocumentSpec &url, std::string body); bool run(); BLOCKING bool download_to_ram(Ramfile *ramfile, bool subdocument_resumes = true); @@ -143,7 +143,7 @@ class EXPCL_PANDA_DOWNLOADER HTTPChannel : public TypedReferenceCount { bool run_headers_received(); bool begin_request(HTTPEnum::Method method, const DocumentSpec &url, - const std::string &body, bool nonblocking, + std::string body, bool nonblocking, size_t first_byte, size_t last_byte); void reset_for_new_request(); diff --git a/panda/src/downloader/httpClient.I b/panda/src/downloader/httpClient.I index b22edde696e..5a88412abe7 100644 --- a/panda/src/downloader/httpClient.I +++ b/panda/src/downloader/httpClient.I @@ -51,8 +51,8 @@ set_client_certificate_filename(const Filename &filename) { * client certificate. */ INLINE void HTTPClient:: -set_client_certificate_pem(const std::string &pem) { - _client_certificate_pem = pem; +set_client_certificate_pem(std::string pem) { + _client_certificate_pem = std::move(pem); _client_certificate_filename = Filename(); unload_client_certificate(); } @@ -62,8 +62,8 @@ set_client_certificate_pem(const std::string &pem) { * named by set_client_certificate_filename() or set_client_certificate_pem(). */ INLINE void HTTPClient:: -set_client_certificate_passphrase(const std::string &passphrase) { - _client_certificate_passphrase = passphrase; +set_client_certificate_passphrase(std::string passphrase) { + _client_certificate_passphrase = std::move(passphrase); unload_client_certificate(); } @@ -116,8 +116,8 @@ get_verify_ssl() const { * "DEFAULT" to use the built-in OpenSSL default value. */ INLINE void HTTPClient:: -set_cipher_list(const std::string &cipher_list) { - _cipher_list = cipher_list; +set_cipher_list(std::string cipher_list) { + _cipher_list = std::move(cipher_list); } /** @@ -135,7 +135,7 @@ get_cipher_list() const { * C++ code should probably use HTTPAuthorization directly. */ INLINE std::string HTTPClient:: -base64_encode(const std::string &s) { +base64_encode(std::string_view s) { return HTTPAuthorization::base64_encode(s); } @@ -145,6 +145,6 @@ base64_encode(const std::string &s) { * C++ code should probably use HTTPAuthorization directly. */ INLINE std::string HTTPClient:: -base64_decode(const std::string &s) { +base64_decode(std::string_view s) { return HTTPAuthorization::base64_decode(s); } diff --git a/panda/src/downloader/httpClient.cxx b/panda/src/downloader/httpClient.cxx index 84ee519689c..6417426d737 100644 --- a/panda/src/downloader/httpClient.cxx +++ b/panda/src/downloader/httpClient.cxx @@ -297,7 +297,7 @@ init_random_seed() { * of explicit calls to add_proxy() for each scheme/proxy pair. */ void HTTPClient:: -set_proxy_spec(const string &proxy_spec) { +set_proxy_spec(std::string_view proxy_spec) { clear_proxy(); string trim_proxy_spec = trim(proxy_spec); @@ -375,7 +375,7 @@ get_proxy_spec() const { * contain wildcard characters ("*"). */ void HTTPClient:: -set_direct_host_spec(const string &direct_host_spec) { +set_direct_host_spec(std::string_view direct_host_spec) { clear_direct_host(); // Tokenize the string based on the semicolons. @@ -434,15 +434,14 @@ clear_proxy() { * to indicate a direct connection. */ void HTTPClient:: -add_proxy(const string &scheme, const URLSpec &proxy) { +add_proxy(std::string_view scheme, const URLSpec &proxy) { URLSpec proxy_url(proxy); // The scheme is always converted to lowercase. string lc_scheme; lc_scheme.reserve(scheme.length()); - string::const_iterator si; - for (si = scheme.begin(); si != scheme.end(); ++si) { - lc_scheme += tolower(*si); + for (char c : scheme) { + lc_scheme += tolower(c); } // Remove the trailing colon, if there is one. @@ -487,17 +486,15 @@ clear_direct_host() { * IP address, and it may include the * as a wildcard character. */ void HTTPClient:: -add_direct_host(const string &hostname) { +add_direct_host(std::string_view hostname) { // The hostname is always converted to lowercase. string lc_hostname; lc_hostname.reserve(hostname.length()); - for (string::const_iterator si = hostname.begin(); - si != hostname.end(); - ++si) { - lc_hostname += tolower(*si); + for (char c : hostname) { + lc_hostname += tolower(c); } - _direct_hosts.push_back(GlobPattern(lc_hostname)); + _direct_hosts.push_back(GlobPattern(std::move(lc_hostname))); } /** @@ -628,12 +625,14 @@ get_proxies_for_url(const URLSpec &url) const { * the particular server/realm pair. */ void HTTPClient:: -set_username(const string &server, const string &realm, const string &username) { - string key = server + ":" + realm; +set_username(std::string_view server, std::string_view realm, std::string username) { + string key; + key.reserve(server.size() + 1 + realm.size()); + key.append(server).append(1, ':').append(realm); if (username.empty()) { _usernames.erase(key); } else { - _usernames[key] = username; + _usernames[std::move(key)] = std::move(username); } } @@ -642,8 +641,10 @@ set_username(const string &server, const string &realm, const string &username) * empty string if nothing has been set. See set_username(). */ string HTTPClient:: -get_username(const string &server, const string &realm) const { - string key = server + ":" + realm; +get_username(std::string_view server, std::string_view realm) const { + string key; + key.reserve(server.size() + 1 + realm.size()); + key.append(server).append(1, ':').append(realm); Usernames::const_iterator ui; ui = _usernames.find(key); if (ui != _usernames.end()) { @@ -916,7 +917,7 @@ add_preapproved_server_certificate_filename(const URLSpec &url, const Filename & * weaker add_preapproved_server_certificate_name(). */ bool HTTPClient:: -add_preapproved_server_certificate_pem(const URLSpec &url, const string &pem) { +add_preapproved_server_certificate_pem(const URLSpec &url, std::string_view pem) { // Create an in-memory BIO to read the "file" from the memory buffer, and // call the low-level routine to read the cert from the BIO. BIO *mbio = BIO_new_mem_buf((void *)pem.data(), pem.length()); @@ -962,7 +963,7 @@ add_preapproved_server_certificate_pem(const URLSpec &url, const string &pem) { * type0=value0/type1=value1/type2=... */ bool HTTPClient:: -add_preapproved_server_certificate_name(const URLSpec &url, const string &name) { +add_preapproved_server_certificate_name(const URLSpec &url, std::string_view name) { X509_NAME *cert_name = parse_x509_name(name); if (cert_name == nullptr) { downloader_cat.warning() @@ -1028,7 +1029,7 @@ get_http_version_string() const { * HV_other if the version is unknown. */ HTTPEnum::HTTPVersion HTTPClient:: -parse_http_version_string(const string &version) { +parse_http_version_string(std::string_view version) { if (version == "HTTP/1.0") { return HTTPEnum::HV_10; } else if (version == "HTTP/1.1") { @@ -1081,9 +1082,9 @@ make_channel(bool persistent_connection) { * document was retrieved. */ PT(HTTPChannel) HTTPClient:: -post_form(const URLSpec &url, const string &body) { +post_form(const URLSpec &url, std::string body) { PT(HTTPChannel) doc = new HTTPChannel(this); - doc->post_form(url, body); + doc->post_form(url, std::move(body)); return doc; } @@ -1226,7 +1227,7 @@ check_preapproved_server_certificate(const URLSpec &url, X509 *cert, * list. Returns true if any were added, false otherwise. */ bool HTTPClient:: -get_proxies_for_scheme(const string &scheme, pvector &proxies) const { +get_proxies_for_scheme(std::string_view scheme, pvector &proxies) const { ProxiesByScheme::const_iterator si = _proxies_by_scheme.find(scheme); if (si == _proxies_by_scheme.end()) { return false; @@ -1250,15 +1251,15 @@ get_proxies_for_scheme(const string &scheme, pvector &proxies) const { * may be empty, or just server:username:password or username:password. */ void HTTPClient:: -add_http_username(const string &http_username) { +add_http_username(std::string_view http_username) { size_t c1 = http_username.find(':'); - if (c1 != string::npos) { + if (c1 != std::string_view::npos) { size_t c2 = http_username.find(':', c1 + 1); - if (c2 != string::npos) { + if (c2 != std::string_view::npos) { size_t c3 = http_username.find(':', c2 + 1); - if (c3 != string::npos) { + if (c3 != std::string_view::npos) { size_t c4 = http_username.find(':', c3 + 1); - if (c4 != string::npos) { + if (c4 != std::string_view::npos) { // Oops, we have five? Problem. downloader_cat.error() << "Invalid http-username " << http_username << "\n"; @@ -1267,18 +1268,18 @@ add_http_username(const string &http_username) { // Ok, we have four. set_username(http_username.substr(0, c1), http_username.substr(c1 + 1, c2 - (c1 + 1)), - http_username.substr(c2 + 1)); + std::string(http_username.substr(c2 + 1))); } } else { // We have only three. - set_username(string(), + set_username(std::string_view(), http_username.substr(0, c1), - http_username.substr(c1 + 1)); + std::string(http_username.substr(c1 + 1))); } } else { // We have only two. - set_username(string(), string(), http_username); + set_username(std::string_view(), std::string_view(), std::string(http_username)); } } else { // We have only one? Problem. @@ -1291,7 +1292,7 @@ add_http_username(const string &http_username) { * Chooses a suitable username:password string for the given URL and realm. */ string HTTPClient:: -select_username(const URLSpec &url, bool is_proxy, const string &realm) const { +select_username(const URLSpec &url, bool is_proxy, std::string_view realm) const { string username; // Look in several places in order to find the matching username. @@ -1338,7 +1339,7 @@ select_username(const URLSpec &url, bool is_proxy, const string &realm) const { * Returns NULL if no authorization matches. */ HTTPAuthorization *HTTPClient:: -select_auth(const URLSpec &url, bool is_proxy, const string &last_realm) { +select_auth(const URLSpec &url, bool is_proxy, std::string_view last_realm) { Domains &domains = is_proxy ? _proxy_domains : _www_domains; string canon = HTTPAuthorization::get_canonical_url(url).get_url(); @@ -1390,7 +1391,7 @@ select_auth(const URLSpec &url, bool is_proxy, const string &last_realm) { * may be a subset of the server, or it may include multiple servers). */ PT(HTTPAuthorization) HTTPClient:: -generate_auth(const URLSpec &url, bool is_proxy, const string &challenge) { +generate_auth(const URLSpec &url, bool is_proxy, std::string_view challenge) { HTTPAuthorization::AuthenticationSchemes schemes; HTTPAuthorization::parse_authentication_schemes(schemes, challenge); @@ -1454,13 +1455,13 @@ unload_client_certificate() { * newly allocated X509_NAME object. Returns NULL if the string is invalid. */ X509_NAME *HTTPClient:: -parse_x509_name(const string &source) { +parse_x509_name(std::string_view source) { X509_NAME *result = nullptr; result = X509_NAME_new(); bool added_any = false; - string::const_iterator si; + std::string_view::const_iterator si; si = source.begin(); while (si != source.end()) { if ((*si) == '/') { @@ -1566,7 +1567,7 @@ x509_name_subset(X509_NAME *name_a, X509_NAME *name_b) { * Puts the first word of c into a, and the remainder into b. */ void HTTPClient:: -split_whitespace(string &a, string &b, const string &c) { +split_whitespace(string &a, string &b, std::string_view c) { size_t p = 0; // Skip initial whitespace diff --git a/panda/src/downloader/httpClient.h b/panda/src/downloader/httpClient.h index b2881532c85..9d9f6b253a9 100644 --- a/panda/src/downloader/httpClient.h +++ b/panda/src/downloader/httpClient.h @@ -62,24 +62,24 @@ class EXPCL_PANDA_DOWNLOADER HTTPClient : public ReferenceCount { static void init_random_seed(); - void set_proxy_spec(const std::string &proxy_spec); + void set_proxy_spec(std::string_view proxy_spec); std::string get_proxy_spec() const; - void set_direct_host_spec(const std::string &direct_host_spec); + void set_direct_host_spec(std::string_view direct_host_spec); std::string get_direct_host_spec() const; INLINE void set_try_all_direct(bool try_all_direct); INLINE bool get_try_all_direct() const; void clear_proxy(); - void add_proxy(const std::string &scheme, const URLSpec &proxy); + void add_proxy(std::string_view scheme, const URLSpec &proxy); void clear_direct_host(); - void add_direct_host(const std::string &hostname); + void add_direct_host(std::string_view hostname); std::string get_proxies_for_url(const URLSpec &url) const; - void set_username(const std::string &server, const std::string &realm, const std::string &username); - std::string get_username(const std::string &server, const std::string &realm) const; + void set_username(std::string_view server, std::string_view realm, std::string username); + std::string get_username(std::string_view server, std::string_view realm) const; void set_cookie(const HTTPCookie &cookie); bool clear_cookie(const HTTPCookie &cookie); @@ -92,20 +92,20 @@ class EXPCL_PANDA_DOWNLOADER HTTPClient : public ReferenceCount { void send_cookies(std::ostream &out, const URLSpec &url); INLINE void set_client_certificate_filename(const Filename &filename); - INLINE void set_client_certificate_pem(const std::string &pem); - INLINE void set_client_certificate_passphrase(const std::string &passphrase); + INLINE void set_client_certificate_pem(std::string pem); + INLINE void set_client_certificate_passphrase(std::string passphrase); bool load_client_certificate(); bool add_preapproved_server_certificate_filename(const URLSpec &url, const Filename &filename); - bool add_preapproved_server_certificate_pem(const URLSpec &url, const std::string &pem); - bool add_preapproved_server_certificate_name(const URLSpec &url, const std::string &name); + bool add_preapproved_server_certificate_pem(const URLSpec &url, std::string_view pem); + bool add_preapproved_server_certificate_name(const URLSpec &url, std::string_view name); void clear_preapproved_server_certificates(const URLSpec &url); void clear_all_preapproved_server_certificates(); INLINE void set_http_version(HTTPEnum::HTTPVersion version); INLINE HTTPEnum::HTTPVersion get_http_version() const; std::string get_http_version_string() const; - static HTTPEnum::HTTPVersion parse_http_version_string(const std::string &version); + static HTTPEnum::HTTPVersion parse_http_version_string(std::string_view version); bool load_certificates(const Filename &filename); @@ -118,16 +118,16 @@ class EXPCL_PANDA_DOWNLOADER HTTPClient : public ReferenceCount { INLINE void set_verify_ssl(VerifySSL verify_ssl); INLINE VerifySSL get_verify_ssl() const; - INLINE void set_cipher_list(const std::string &cipher_list); + INLINE void set_cipher_list(std::string cipher_list); INLINE const std::string &get_cipher_list() const; PT(HTTPChannel) make_channel(bool persistent_connection); - BLOCKING PT(HTTPChannel) post_form(const URLSpec &url, const std::string &body); + BLOCKING PT(HTTPChannel) post_form(const URLSpec &url, std::string body); BLOCKING PT(HTTPChannel) get_document(const URLSpec &url); BLOCKING PT(HTTPChannel) get_header(const URLSpec &url); - INLINE static std::string base64_encode(const std::string &s); - INLINE static std::string base64_decode(const std::string &s); + INLINE static std::string base64_encode(std::string_view s); + INLINE static std::string base64_decode(std::string_view s); static HTTPClient *get_global_ptr(); @@ -140,27 +140,27 @@ class EXPCL_PANDA_DOWNLOADER HTTPClient : public ReferenceCount { void check_preapproved_server_certificate(const URLSpec &url, X509 *cert, bool &cert_preapproved, bool &cert_name_preapproved) const; - bool get_proxies_for_scheme(const std::string &scheme, + bool get_proxies_for_scheme(std::string_view scheme, pvector &proxies) const; - void add_http_username(const std::string &http_username); + void add_http_username(std::string_view http_username); std::string select_username(const URLSpec &url, bool is_proxy, - const std::string &realm) const; + std::string_view realm) const; HTTPAuthorization *select_auth(const URLSpec &url, bool is_proxy, - const std::string &last_realm); + std::string_view last_realm); PT(HTTPAuthorization) generate_auth(const URLSpec &url, bool is_proxy, - const std::string &challenge); + std::string_view challenge); void unload_client_certificate(); - static X509_NAME *parse_x509_name(const std::string &source); + static X509_NAME *parse_x509_name(std::string_view source); static bool x509_name_subset(X509_NAME *name_a, X509_NAME *name_b); - static void split_whitespace(std::string &a, std::string &b, const std::string &c); + static void split_whitespace(std::string &a, std::string &b, std::string_view c); typedef pvector Proxies; - typedef pmap ProxiesByScheme; + typedef pmap> ProxiesByScheme; ProxiesByScheme _proxies_by_scheme; typedef pvector DirectHosts; DirectHosts _direct_hosts; @@ -170,10 +170,10 @@ class EXPCL_PANDA_DOWNLOADER HTTPClient : public ReferenceCount { VerifySSL _verify_ssl; std::string _cipher_list; - typedef pmap Usernames; + typedef pmap> Usernames; Usernames _usernames; - typedef pmap Realms; + typedef pmap> Realms; class Domain { public: Realms _realms; diff --git a/panda/src/downloader/httpClient_emscripten.I b/panda/src/downloader/httpClient_emscripten.I index e19d6258b8c..bc39bdb41f0 100644 --- a/panda/src/downloader/httpClient_emscripten.I +++ b/panda/src/downloader/httpClient_emscripten.I @@ -17,7 +17,7 @@ * C++ code should probably use HTTPAuthorization directly. */ INLINE std::string HTTPClient:: -base64_encode(const std::string &s) { +base64_encode(std::string_view s) { return HTTPAuthorization::base64_encode(s); } @@ -27,6 +27,6 @@ base64_encode(const std::string &s) { * C++ code should probably use HTTPAuthorization directly. */ INLINE std::string HTTPClient:: -base64_decode(const std::string &s) { +base64_decode(std::string_view s) { return HTTPAuthorization::base64_decode(s); } diff --git a/panda/src/downloader/httpClient_emscripten.cxx b/panda/src/downloader/httpClient_emscripten.cxx index a9c32d44ed5..1723a7c036b 100644 --- a/panda/src/downloader/httpClient_emscripten.cxx +++ b/panda/src/downloader/httpClient_emscripten.cxx @@ -59,12 +59,14 @@ HTTPClient() { * the particular server/realm pair. */ void HTTPClient:: -set_username(const string &server, const string &realm, const string &username) { - string key = server + ":" + realm; +set_username(std::string_view server, std::string_view realm, std::string username) { + string key; + key.reserve(server.size() + 1 + realm.size()); + key.append(server).append(1, ':').append(realm); if (username.empty()) { _usernames.erase(key); } else { - _usernames[key] = username; + _usernames[std::move(key)] = std::move(username); } } @@ -73,8 +75,10 @@ set_username(const string &server, const string &realm, const string &username) * empty string if nothing has been set. See set_username(). */ string HTTPClient:: -get_username(const string &server, const string &realm) const { - string key = server + ":" + realm; +get_username(std::string_view server, std::string_view realm) const { + string key; + key.reserve(server.size() + 1 + realm.size()); + key.append(server).append(1, ':').append(realm); Usernames::const_iterator ui; ui = _usernames.find(key); if (ui != _usernames.end()) { @@ -202,9 +206,9 @@ make_channel(bool persistent_connection) { * document was retrieved. */ PT(HTTPChannel) HTTPClient:: -post_form(const URLSpec &url, const string &body) { +post_form(const URLSpec &url, std::string body) { PT(HTTPChannel) doc = new HTTPChannel(this); - doc->post_form(url, body); + doc->post_form(url, std::move(body)); return doc; } @@ -250,15 +254,15 @@ get_global_ptr() { * may be empty, or just server:username:password or username:password. */ void HTTPClient:: -add_http_username(const string &http_username) { +add_http_username(std::string_view http_username) { size_t c1 = http_username.find(':'); - if (c1 != string::npos) { + if (c1 != std::string_view::npos) { size_t c2 = http_username.find(':', c1 + 1); - if (c2 != string::npos) { + if (c2 != std::string_view::npos) { size_t c3 = http_username.find(':', c2 + 1); - if (c3 != string::npos) { + if (c3 != std::string_view::npos) { size_t c4 = http_username.find(':', c3 + 1); - if (c4 != string::npos) { + if (c4 != std::string_view::npos) { // Oops, we have five? Problem. downloader_cat.error() << "Invalid http-username " << http_username << "\n"; @@ -267,19 +271,19 @@ add_http_username(const string &http_username) { // Ok, we have four. set_username(http_username.substr(0, c1), http_username.substr(c1 + 1, c2 - (c1 + 1)), - http_username.substr(c2 + 1)); + std::string(http_username.substr(c2 + 1))); } } else { // We have only three. - set_username(string(), + set_username(std::string_view(), http_username.substr(0, c1), - http_username.substr(c1 + 1)); + std::string(http_username.substr(c1 + 1))); } } else { // We have only two. - set_username(string(), string(), http_username); + set_username(std::string_view(), std::string_view(), std::string(http_username)); } } else { // We have only one? Problem. @@ -292,7 +296,7 @@ add_http_username(const string &http_username) { * Chooses a suitable username:password string for the given URL and realm. */ string HTTPClient:: -select_username(const URLSpec &url, const string &realm) const { +select_username(const URLSpec &url, std::string_view realm) const { string username; // Look in several places in order to find the matching username. @@ -329,7 +333,7 @@ select_username(const URLSpec &url, const string &realm) const { * Returns NULL if no authorization matches. */ HTTPAuthorization *HTTPClient:: -select_auth(const URLSpec &url, const string &last_realm) { +select_auth(const URLSpec &url, std::string_view last_realm) { Domains &domains = _www_domains; std::string canon = HTTPAuthorization::get_canonical_url(url).get_url(); @@ -381,7 +385,7 @@ select_auth(const URLSpec &url, const string &last_realm) { * may be a subset of the server, or it may include multiple servers). */ PT(HTTPAuthorization) HTTPClient:: -generate_auth(const URLSpec &url, const string &challenge) { +generate_auth(const URLSpec &url, std::string_view challenge) { HTTPAuthorization::AuthenticationSchemes schemes; HTTPAuthorization::parse_authentication_schemes(schemes, challenge); diff --git a/panda/src/downloader/httpClient_emscripten.h b/panda/src/downloader/httpClient_emscripten.h index fd56bb16f9f..fad1add99a3 100644 --- a/panda/src/downloader/httpClient_emscripten.h +++ b/panda/src/downloader/httpClient_emscripten.h @@ -41,8 +41,8 @@ class EXPCL_PANDA_DOWNLOADER HTTPClient : public ReferenceCount { HTTPClient(); PUBLISHED: - void set_username(const std::string &server, const std::string &realm, const std::string &username); - std::string get_username(const std::string &server, const std::string &realm) const; + void set_username(std::string_view server, std::string_view realm, std::string username); + std::string get_username(std::string_view server, std::string_view realm) const; void set_cookie(const HTTPCookie &cookie); bool clear_cookie(const HTTPCookie &cookie); @@ -53,27 +53,27 @@ class EXPCL_PANDA_DOWNLOADER HTTPClient : public ReferenceCount { void write_cookies(std::ostream &out) const; PT(HTTPChannel) make_channel(bool persistent_connection); - BLOCKING PT(HTTPChannel) post_form(const URLSpec &url, const std::string &body); + BLOCKING PT(HTTPChannel) post_form(const URLSpec &url, std::string body); BLOCKING PT(HTTPChannel) get_document(const URLSpec &url); BLOCKING PT(HTTPChannel) get_header(const URLSpec &url); - INLINE static std::string base64_encode(const std::string &s); - INLINE static std::string base64_decode(const std::string &s); + INLINE static std::string base64_encode(std::string_view s); + INLINE static std::string base64_decode(std::string_view s); static HTTPClient *get_global_ptr(); private: - void add_http_username(const std::string &http_username); - std::string select_username(const URLSpec &url, const std::string &realm) const; + void add_http_username(std::string_view http_username); + std::string select_username(const URLSpec &url, std::string_view realm) const; - HTTPAuthorization *select_auth(const URLSpec &url, const std::string &last_realm); + HTTPAuthorization *select_auth(const URLSpec &url, std::string_view last_realm); PT(HTTPAuthorization) generate_auth(const URLSpec &url, - const std::string &challenge); + std::string_view challenge); - typedef pmap Usernames; + typedef pmap> Usernames; Usernames _usernames; - typedef pmap Realms; + typedef pmap> Realms; class Domain { public: Realms _realms; diff --git a/panda/src/downloader/httpCookie.I b/panda/src/downloader/httpCookie.I index 95e9d4a5f63..009b8642a43 100644 --- a/panda/src/downloader/httpCookie.I +++ b/panda/src/downloader/httpCookie.I @@ -17,7 +17,7 @@ * the string with this constructor. */ INLINE HTTPCookie:: -HTTPCookie(const std::string &format, const URLSpec &url) { +HTTPCookie(std::string_view format, const URLSpec &url) { parse_set_cookie(format, url); } @@ -27,10 +27,10 @@ HTTPCookie(const std::string &format, const URLSpec &url) { * the HTTPClient. */ INLINE HTTPCookie:: -HTTPCookie(const std::string &name, const std::string &path, const std::string &domain) : - _name(name), - _path(path), - _domain(domain), +HTTPCookie(std::string name, std::string path, std::string domain) : + _name(std::move(name)), + _path(std::move(path)), + _domain(std::move(domain)), _secure(false), _samesite(SS_unspecified) { @@ -47,8 +47,8 @@ INLINE HTTPCookie:: * */ INLINE void HTTPCookie:: -set_name(const std::string &name) { - _name = name; +set_name(std::string name) { + _name = std::move(name); } /** @@ -64,8 +64,8 @@ get_name() const { * */ INLINE void HTTPCookie:: -set_value(const std::string &value) { - _value = value; +set_value(std::string value) { + _value = std::move(value); } /** @@ -81,8 +81,8 @@ get_value() const { * */ INLINE void HTTPCookie:: -set_domain(const std::string &domain) { - _domain = domain; +set_domain(std::string domain) { + _domain = std::move(domain); } /** @@ -97,8 +97,8 @@ get_domain() const { * */ INLINE void HTTPCookie:: -set_path(const std::string &path) { - _path = path; +set_path(std::string path) { + _path = std::move(path); } /** diff --git a/panda/src/downloader/httpCookie.cxx b/panda/src/downloader/httpCookie.cxx index 0578b72539e..818e4038e46 100644 --- a/panda/src/downloader/httpCookie.cxx +++ b/panda/src/downloader/httpCookie.cxx @@ -69,7 +69,7 @@ update_from(const HTTPCookie &other) { * is parsed correctly, false if something is not understood. */ bool HTTPCookie:: -parse_set_cookie(const string &format, const URLSpec &url) { +parse_set_cookie(std::string_view format, const URLSpec &url) { _name = string(); _value = string(); _domain = url.get_server(); @@ -169,11 +169,11 @@ output(std::ostream &out) const { * false on failure. */ bool HTTPCookie:: -parse_cookie_param(const string ¶m, bool first_param) { +parse_cookie_param(std::string_view param, bool first_param) { size_t equals = param.find('='); - string key, value; - if (equals == string::npos) { + std::string_view key, value; + if (equals == std::string_view::npos) { key = param; } else { key = param.substr(0, equals); @@ -181,21 +181,21 @@ parse_cookie_param(const string ¶m, bool first_param) { } if (first_param) { - _name = key; - _value = value; + _name.assign(key); + _value.assign(value); } else { - key = downcase(key); - if (key == "expires") { + string lc_key = downcase(key); + if (lc_key == "expires") { _expires = HTTPDate(value); if (!_expires.is_valid()) { return false; } - } else if (key == "path") { - _path = value; + } else if (lc_key == "path") { + _path.assign(value); - } else if (key == "domain") { + } else if (lc_key == "domain") { _domain = downcase(value); // From RFC 2965: If an explicitly specified value does not start with a @@ -204,18 +204,18 @@ parse_cookie_param(const string ¶m, bool first_param) { _domain = string(".") + _domain; } - } else if (key == "secure") { + } else if (lc_key == "secure") { _secure = true; - } else if (key == "samesite") { - value = downcase(value); - if (value == "lax") { + } else if (lc_key == "samesite") { + string lc_value = downcase(value); + if (lc_value == "lax") { _samesite = SS_lax; } - else if (value == "strict") { + else if (lc_value == "strict") { _samesite = SS_strict; } - else if (value == "none") { + else if (lc_value == "none") { _samesite = SS_none; } diff --git a/panda/src/downloader/httpCookie.h b/panda/src/downloader/httpCookie.h index 73284f1f8cf..7ed64e513c5 100644 --- a/panda/src/downloader/httpCookie.h +++ b/panda/src/downloader/httpCookie.h @@ -32,21 +32,21 @@ class EXPCL_PANDA_DOWNLOADER HTTPCookie { PUBLISHED: INLINE HTTPCookie() = default; - INLINE explicit HTTPCookie(const std::string &format, const URLSpec &url); - INLINE explicit HTTPCookie(const std::string &name, const std::string &path, - const std::string &domain); + INLINE explicit HTTPCookie(std::string_view format, const URLSpec &url); + INLINE explicit HTTPCookie(std::string name, std::string path, + std::string domain); INLINE ~HTTPCookie(); - INLINE void set_name(const std::string &name); + INLINE void set_name(std::string name); INLINE const std::string &get_name() const; - INLINE void set_value(const std::string &value); + INLINE void set_value(std::string value); INLINE const std::string &get_value() const; - INLINE void set_domain(const std::string &domain); + INLINE void set_domain(std::string domain); INLINE const std::string &get_domain() const; - INLINE void set_path(const std::string &path); + INLINE void set_path(std::string path); INLINE const std::string &get_path() const; INLINE void set_expires(const HTTPDate &expires); @@ -70,7 +70,7 @@ class EXPCL_PANDA_DOWNLOADER HTTPCookie { bool operator < (const HTTPCookie &other) const; void update_from(const HTTPCookie &other); - bool parse_set_cookie(const std::string &format, const URLSpec &url); + bool parse_set_cookie(std::string_view format, const URLSpec &url); INLINE bool is_expired(const HTTPDate &now = HTTPDate::now()) const; bool matches_url(const URLSpec &url) const; @@ -85,7 +85,7 @@ class EXPCL_PANDA_DOWNLOADER HTTPCookie { MAKE_PROPERTY(secure, get_secure, set_secure); private: - bool parse_cookie_param(const std::string ¶m, bool first_param); + bool parse_cookie_param(std::string_view param, bool first_param); std::string _name; std::string _value; diff --git a/panda/src/downloader/httpDate.cxx b/panda/src/downloader/httpDate.cxx index f4a2fc8564a..c77ac2386d8 100644 --- a/panda/src/downloader/httpDate.cxx +++ b/panda/src/downloader/httpDate.cxx @@ -36,7 +36,7 @@ static const char * const months[num_months] = { * string cannot be correctly decoded. */ HTTPDate:: -HTTPDate(const string &format) { +HTTPDate(std::string_view format) { _time = (time_t)(-1); struct tm t; @@ -296,7 +296,7 @@ output(std::ostream &out) const { * next character following the last digit (unless it is a letter). */ string HTTPDate:: -get_token(const string &str, size_t &pos) { +get_token(std::string_view str, size_t &pos) { // Start by scanning for the first alphanumeric character. size_t start = pos; while (start < str.length() && !isalnum(str[start])) { diff --git a/panda/src/downloader/httpDate.h b/panda/src/downloader/httpDate.h index 4ee58dcf307..b2d87b6021c 100644 --- a/panda/src/downloader/httpDate.h +++ b/panda/src/downloader/httpDate.h @@ -28,7 +28,7 @@ class EXPCL_PANDA_DOWNLOADER HTTPDate { PUBLISHED: INLINE HTTPDate(); INLINE HTTPDate(time_t time); - HTTPDate(const std::string &format); + HTTPDate(std::string_view format); INLINE HTTPDate(const HTTPDate ©); INLINE void operator = (const HTTPDate ©); INLINE static HTTPDate now(); @@ -55,7 +55,7 @@ class EXPCL_PANDA_DOWNLOADER HTTPDate { void output(std::ostream &out) const; private: - static std::string get_token(const std::string &str, size_t &pos); + static std::string get_token(std::string_view str, size_t &pos); time_t _time; }; diff --git a/panda/src/downloader/httpDigestAuthorization.cxx b/panda/src/downloader/httpDigestAuthorization.cxx index 1a57a691cf7..ec23c409756 100644 --- a/panda/src/downloader/httpDigestAuthorization.cxx +++ b/panda/src/downloader/httpDigestAuthorization.cxx @@ -128,19 +128,19 @@ get_mechanism() const { * the given username:password. */ string HTTPDigestAuthorization:: -generate(HTTPEnum::Method method, const string &request_path, - const string &username, const string &body) { +generate(HTTPEnum::Method method, std::string_view request_path, + std::string_view username, std::string_view body) { _nonce_count++; size_t colon = username.find(':'); - string username_only = username.substr(0, colon); - string password_only = username.substr(colon + 1); + std::string_view username_only = username.substr(0, colon); + std::string_view password_only = username.substr(colon + 1); string digest = calc_request_digest(username_only, password_only, method, request_path, body); ostringstream strm; - strm << "Digest username=\"" << username.substr(0, colon) << "\"" + strm << "Digest username=\"" << username_only << "\"" << ", realm=\"" << get_realm() << "\"" << ", nonce=\"" << _nonce << "\"" << ", uri=" << request_path @@ -165,7 +165,7 @@ generate(HTTPEnum::Method method, const string &request_path, * if the token string is unrecognized. */ int HTTPDigestAuthorization:: -match_qop_token(const string &token) { +match_qop_token(std::string_view token) { if (token == "auth") { return Q_auth; } else if (token == "auth-int") { @@ -178,9 +178,9 @@ match_qop_token(const string &token) { * Calculates the appropriate digest response, according to RFC 2617. */ string HTTPDigestAuthorization:: -calc_request_digest(const string &username, const string &password, - HTTPEnum::Method method, const string &request_path, - const string &body) { +calc_request_digest(std::string_view username, std::string_view password, + HTTPEnum::Method method, std::string_view request_path, + std::string_view body) { _chosen_qop = Q_unused; string h_a1 = calc_h(get_a1(username, password)); string h_a2 = calc_h(get_a2(method, request_path, body)); @@ -205,7 +205,7 @@ calc_request_digest(const string &username, const string &password, * 2617. */ string HTTPDigestAuthorization:: -calc_h(const string &data) const { +calc_h(std::string_view data) const { switch (_algorithm) { case A_unknown: case A_md5: @@ -221,12 +221,16 @@ calc_h(const string &data) const { * indicated secret, according to RFC 2617. */ string HTTPDigestAuthorization:: -calc_kd(const string &secret, const string &data) const { +calc_kd(std::string_view secret, std::string_view data) const { switch (_algorithm) { case A_unknown: case A_md5: - case A_md5_sess: - return calc_h(secret + ":" + data); + case A_md5_sess: { + string combined; + combined.reserve(secret.size() + 1 + data.size()); + combined.append(secret).append(1, ':').append(data); + return calc_h(combined); + } } return string(); @@ -236,16 +240,24 @@ calc_kd(const string &secret, const string &data) const { * Returns the A1 value, as defined by RFC 2617. */ string HTTPDigestAuthorization:: -get_a1(const string &username, const string &password) { +get_a1(std::string_view username, std::string_view password) { switch (_algorithm) { case A_unknown: - case A_md5: - return username + ":" + get_realm() + ":" + password; + case A_md5: { + const std::string &realm = get_realm(); + string a1; + a1.reserve(username.size() + 1 + realm.size() + 1 + password.size()); + a1.append(username).append(1, ':').append(realm).append(1, ':').append(password); + return a1; + } case A_md5_sess: if (_a1.empty()) { - _a1 = calc_h(username + ":" + get_realm() + ":" + password) + - ":" + _nonce + ":" + _cnonce; + const std::string &realm = get_realm(); + string base; + base.reserve(username.size() + 1 + realm.size() + 1 + password.size()); + base.append(username).append(1, ':').append(realm).append(1, ':').append(password); + _a1 = calc_h(base) + ":" + _nonce + ":" + _cnonce; } return _a1; } @@ -257,8 +269,8 @@ get_a1(const string &username, const string &password) { * Returns the A2 value, as defined by RFC 2617. */ string HTTPDigestAuthorization:: -get_a2(HTTPEnum::Method method, const string &request_path, - const string &body) { +get_a2(HTTPEnum::Method method, std::string_view request_path, + std::string_view body) { ostringstream strm; if ((_qop & Q_auth_int) != 0 && !body.empty()) { @@ -290,7 +302,7 @@ get_hex_nonce_count() const { * hexadecimal string of 32 ASCII characters. */ string HTTPDigestAuthorization:: -calc_md5(const string &source) { +calc_md5(std::string_view source) { HashVal hv; hv.hash_string(source); return hv.as_hex(); diff --git a/panda/src/downloader/httpDigestAuthorization.h b/panda/src/downloader/httpDigestAuthorization.h index 78efdbc1a09..017f8e10165 100644 --- a/panda/src/downloader/httpDigestAuthorization.h +++ b/panda/src/downloader/httpDigestAuthorization.h @@ -38,8 +38,8 @@ class HTTPDigestAuthorization : public HTTPAuthorization { virtual const std::string &get_mechanism() const; virtual bool is_valid(); - virtual std::string generate(HTTPEnum::Method method, const std::string &request_path, - const std::string &username, const std::string &body); + virtual std::string generate(HTTPEnum::Method method, std::string_view request_path, + std::string_view username, std::string_view body); public: enum Algorithm { @@ -55,19 +55,19 @@ class HTTPDigestAuthorization : public HTTPAuthorization { }; private: - static int match_qop_token(const std::string &token); + static int match_qop_token(std::string_view token); - std::string calc_request_digest(const std::string &username, const std::string &password, + std::string calc_request_digest(std::string_view username, std::string_view password, HTTPEnum::Method method, - const std::string &request_path, const std::string &body); - std::string calc_h(const std::string &data) const; - std::string calc_kd(const std::string &secret, const std::string &data) const; - std::string get_a1(const std::string &username, const std::string &password); - std::string get_a2(HTTPEnum::Method method, const std::string &request_path, - const std::string &body); + std::string_view request_path, std::string_view body); + std::string calc_h(std::string_view data) const; + std::string calc_kd(std::string_view secret, std::string_view data) const; + std::string get_a1(std::string_view username, std::string_view password); + std::string get_a2(HTTPEnum::Method method, std::string_view request_path, + std::string_view body); std::string get_hex_nonce_count() const; - static std::string calc_md5(const std::string &source); + static std::string calc_md5(std::string_view source); INLINE static char hexdigit(int value); std::string _cnonce; diff --git a/panda/src/downloader/httpEntityTag.I b/panda/src/downloader/httpEntityTag.I index 3cdee7d4f32..7acc216c94d 100644 --- a/panda/src/downloader/httpEntityTag.I +++ b/panda/src/downloader/httpEntityTag.I @@ -24,9 +24,9 @@ HTTPEntityTag() { * tag string. */ INLINE HTTPEntityTag:: -HTTPEntityTag(bool weak, const std::string &tag) : +HTTPEntityTag(bool weak, std::string tag) : _weak(weak), - _tag(tag) + _tag(std::move(tag)) { } diff --git a/panda/src/downloader/httpEntityTag.cxx b/panda/src/downloader/httpEntityTag.cxx index 1d4b79922a6..0fb868f7c1d 100644 --- a/panda/src/downloader/httpEntityTag.cxx +++ b/panda/src/downloader/httpEntityTag.cxx @@ -21,12 +21,12 @@ using std::string; * the tag is quoted, with an optional W/ prefix.) */ HTTPEntityTag:: -HTTPEntityTag(const string &text) { +HTTPEntityTag(std::string_view text) { _weak = false; size_t p = 0; if (text.length() >= 2) { - string sub = text.substr(0, 2); + std::string_view sub = text.substr(0, 2); if (sub == "W/" || sub == "w/") { _weak = true; p = 2; @@ -65,7 +65,7 @@ get_string() const { case '"': case '\\': result << '\\'; - // fall through + [[fallthrough]]; default: result << (*ti); diff --git a/panda/src/downloader/httpEntityTag.h b/panda/src/downloader/httpEntityTag.h index 07b8a0196bd..15c2cba2a18 100644 --- a/panda/src/downloader/httpEntityTag.h +++ b/panda/src/downloader/httpEntityTag.h @@ -24,8 +24,8 @@ class EXPCL_PANDA_DOWNLOADER HTTPEntityTag { PUBLISHED: INLINE HTTPEntityTag(); - HTTPEntityTag(const std::string &text); - INLINE explicit HTTPEntityTag(bool weak, const std::string &tag); + HTTPEntityTag(std::string_view text); + INLINE explicit HTTPEntityTag(bool weak, std::string tag); INLINE HTTPEntityTag(const HTTPEntityTag ©); INLINE void operator = (const HTTPEntityTag ©); diff --git a/panda/src/downloader/identityStreamBuf.cxx b/panda/src/downloader/identityStreamBuf.cxx index 852c252f32b..b8c17ae7861 100644 --- a/panda/src/downloader/identityStreamBuf.cxx +++ b/panda/src/downloader/identityStreamBuf.cxx @@ -27,17 +27,10 @@ IdentityStreamBuf() { _wanted_nonblocking = false; _read_state = ISocketStream::RS_initial; -#ifdef PHAVE_IOSTREAM _buffer = (char *)PANDA_MALLOC_ARRAY(4096); char *ebuf = _buffer + 4096; setg(_buffer, ebuf, ebuf); setp(_buffer, ebuf); - -#else - allocate(); - setg(base(), ebuf(), ebuf()); - setp(base(), ebuf()); -#endif } /** @@ -46,9 +39,7 @@ IdentityStreamBuf() { IdentityStreamBuf:: ~IdentityStreamBuf() { close_read(); -#ifdef PHAVE_IOSTREAM PANDA_FREE_ARRAY(_buffer); -#endif } /** diff --git a/panda/src/downloader/multiplexStreamBuf.cxx b/panda/src/downloader/multiplexStreamBuf.cxx index 9c585932828..6521c98a51b 100644 --- a/panda/src/downloader/multiplexStreamBuf.cxx +++ b/panda/src/downloader/multiplexStreamBuf.cxx @@ -80,11 +80,6 @@ write_string(const string &str) { */ MultiplexStreamBuf:: MultiplexStreamBuf() { -#ifndef PHAVE_IOSTREAM - // Older iostream implementations required this. - allocate(); - setp(base(), ebuf()); -#endif } /** diff --git a/panda/src/downloader/urlSpec.I b/panda/src/downloader/urlSpec.I index 083b2ca9f59..ac4de0cdd1b 100644 --- a/panda/src/downloader/urlSpec.I +++ b/panda/src/downloader/urlSpec.I @@ -15,7 +15,7 @@ * */ INLINE URLSpec:: -URLSpec(const std::string &url, bool server_name_expected) { +URLSpec(std::string_view url, bool server_name_expected) { set_url(url, server_name_expected); } @@ -27,6 +27,14 @@ operator = (const std::string &url) { set_url(url); } +/** + * + */ +INLINE void URLSpec:: +operator = (std::string_view url) { + set_url(url); +} + /** * */ diff --git a/panda/src/downloader/urlSpec.cxx b/panda/src/downloader/urlSpec.cxx index 1925c6a775a..3ceb04ebf4d 100644 --- a/panda/src/downloader/urlSpec.cxx +++ b/panda/src/downloader/urlSpec.cxx @@ -169,7 +169,7 @@ is_default_port() const { * no known default. */ int URLSpec:: -get_default_port_for_scheme(const string &scheme) { +get_default_port_for_scheme(std::string_view scheme) { if (scheme == "http" || scheme.empty()) { return 80; @@ -239,14 +239,14 @@ get_path_and_query() const { * Replaces the scheme part of the URL specification. */ void URLSpec:: -set_scheme(const string &scheme) { +set_scheme(std::string_view scheme) { int length_adjust; // The scheme is always converted to lowercase. string lc_scheme; lc_scheme.reserve(scheme.length()); - for (string::const_iterator si = scheme.begin(); si != scheme.end(); ++si) { - lc_scheme += tolower(*si); + for (char c : scheme) { + lc_scheme += tolower(c); } if (lc_scheme.empty()) { @@ -307,7 +307,7 @@ set_scheme(const string &scheme) { * username, server, and port. */ void URLSpec:: -set_authority(const string &authority) { +set_authority(std::string_view authority) { int length_adjust; int extra_slash_adjust = 0; @@ -330,13 +330,22 @@ set_authority(const string &authority) { // Insert a new authority specification. length_adjust = authority.length() + 2; - string extra_slash; + bool need_extra_slash = false; if (has_path() && _url[_path_start] != '/') { // If we have a path but it doesn't begin with a slash, it should. - extra_slash = '/'; + need_extra_slash = true; extra_slash_adjust = 1; } - _url = _url.substr(0, _username_start) + "//" + authority + extra_slash + _url.substr(_port_end); + string new_url; + new_url.reserve(_username_start + 2 + authority.size() + (need_extra_slash ? 1 : 0) + (_url.size() - _port_end)); + new_url.append(_url, 0, _username_start); + new_url += "//"; + new_url.append(authority); + if (need_extra_slash) { + new_url += '/'; + } + new_url.append(_url, _port_end); + _url = std::move(new_url); _flags |= F_has_authority; _username_start += 2; @@ -344,7 +353,12 @@ set_authority(const string &authority) { // Replace an existing authority specification. int old_length = (int)_port_end - (int)_username_start; length_adjust = authority.length() - old_length; - _url = _url.substr(0, _username_start) + authority + _url.substr(_port_end); + string new_url; + new_url.reserve(_username_start + authority.size() + (_url.size() - _port_end)); + new_url.append(_url, 0, _username_start); + new_url.append(authority); + new_url.append(_url, _port_end); + _url = std::move(new_url); } _port_end += length_adjust; @@ -359,26 +373,29 @@ set_authority(const string &authority) { * Replaces the username part of the URL specification. */ void URLSpec:: -set_username(const string &username) { +set_username(std::string_view username) { if (username.empty() && !has_authority()) { return; } string authority; if (!username.empty()) { - authority = username + "@"; + authority.append(username); + authority += '@'; } string server = get_server(); if (server.find(':') != string::npos) { // Protect an IPv6 address by enclosing it in square brackets. - authority += "[" + server + "]"; + authority += '['; + authority += server; + authority += ']'; } else { authority += server; } if (has_port()) { - authority += ":"; + authority += ':'; authority += get_port_str(); } @@ -391,25 +408,28 @@ set_username(const string &username) { * be enclosed in square brackets. */ void URLSpec:: -set_server(const string &server) { +set_server(std::string_view server) { if (server.empty() && !has_authority()) { return; } string authority; if (has_username()) { - authority = get_username() + "@"; + authority = get_username(); + authority += '@'; } - if (server.find(':') != string::npos) { + if (server.find(':') != std::string_view::npos) { // Protect an IPv6 address by enclosing it in square brackets. - authority += "[" + server + "]"; + authority += '['; + authority.append(server); + authority += ']'; } else { - authority += server; + authority.append(server); } if (has_port()) { - authority += ":"; + authority += ':'; authority += get_port_str(); } @@ -420,27 +440,30 @@ set_server(const string &server) { * Replaces the port part of the URL specification. */ void URLSpec:: -set_port(const string &port) { +set_port(std::string_view port) { if (port.empty() && !has_authority()) { return; } string authority; if (has_username()) { - authority = get_username() + "@"; + authority = get_username(); + authority += '@'; } string server = get_server(); if (server.find(':') != string::npos) { // Protect an IPv6 address by enclosing it in square brackets. - authority += "[" + server + "]"; + authority += '['; + authority += server; + authority += ']'; } else { authority += server; } if (!port.empty()) { - authority += ":"; - authority += port; + authority += ':'; + authority.append(port); } set_authority(authority); @@ -462,16 +485,17 @@ set_port(uint16_t port) { * Any IPv6 address must be enclosed in square brackets. */ void URLSpec:: -set_server_and_port(const string &server_and_port) { +set_server_and_port(std::string_view server_and_port) { if (server_and_port.empty() && !has_authority()) { return; } string authority; if (has_username()) { - authority = get_username() + "@"; + authority = get_username(); + authority += '@'; } - authority += server_and_port; + authority.append(server_and_port); set_authority(authority); } @@ -479,7 +503,7 @@ set_server_and_port(const string &server_and_port) { * Replaces the path part of the URL specification. */ void URLSpec:: -set_path(const string &path) { +set_path(std::string_view path) { int length_adjust; if (path.empty()) { @@ -491,28 +515,29 @@ set_path(const string &path) { _url = _url.substr(0, _path_start) + _url.substr(_path_end); _flags &= ~F_has_path; - } else if (!has_path()) { - // Insert a new path specification. - string cpath = path; - if (cpath[0] != '/') { - // Paths must always begin with a slash. - cpath = '/' + cpath; + } else { + // Build the new path, ensuring it begins with a slash. + string cpath; + if (path[0] != '/') { + cpath.reserve(path.size() + 1); + cpath += '/'; + cpath.append(path); + } else { + cpath.assign(path); } - length_adjust = cpath.length(); - _url = _url.substr(0, _path_start) + cpath + _url.substr(_path_end); - _flags |= F_has_path; + if (!has_path()) { + // Insert a new path specification. + length_adjust = cpath.length(); + _url = _url.substr(0, _path_start) + cpath + _url.substr(_path_end); + _flags |= F_has_path; - } else { - // Replace an existing path specification. - string cpath = path; - if (cpath[0] != '/') { - // Paths must always begin with a slash. - cpath = '/' + cpath; + } else { + // Replace an existing path specification. + int old_length = (int)_path_end - (int)_path_start; + length_adjust = cpath.length() - old_length; + _url = _url.substr(0, _path_start) + cpath + _url.substr(_path_end); } - int old_length = (int)_path_end - (int)_path_start; - length_adjust = cpath.length() - old_length; - _url = _url.substr(0, _path_start) + cpath + _url.substr(_path_end); } _path_end += length_adjust; @@ -523,25 +548,32 @@ set_path(const string &path) { * Replaces the query part of the URL specification. */ void URLSpec:: -set_query(const string &query) { +set_query(std::string_view query) { if (query.empty()) { // Remove the query specification. if (!has_query()) { return; } _query_start--; - _url = _url.substr(0, _query_start); + _url.resize(_query_start); _flags &= ~F_has_query; - } else if (!has_query()) { - // Insert a new query specification. - _url = _url.substr(0, _query_start) + "?" + query; - _flags |= F_has_query; - _query_start++; - } else { - // Replace an existing query specification. - _url = _url.substr(0, _query_start) + query; + // Copy query first in case it aliases _url's own buffer. + std::string new_query(query); + if (!has_query()) { + // Insert a new query specification. + _url.resize(_query_start); + _url += '?'; + _url.append(new_query); + _flags |= F_has_query; + _query_start++; + + } else { + // Replace an existing query specification. + _url.resize(_query_start); + _url.append(new_query); + } } } @@ -551,7 +583,7 @@ set_query(const string &query) { * probably a server name, not a local filename. */ void URLSpec:: -set_url(const string &url, bool server_name_expected) { +set_url(std::string_view url, bool server_name_expected) { size_t p, q; // Omit leading and trailing whitespace. @@ -716,12 +748,11 @@ output(ostream &out) const { * string, are left alone; all others are converted to hex representation. */ string URLSpec:: -quote(const string &source, const string &safe) { +quote(std::string_view source, std::string_view safe) { ostringstream result; result << std::hex << setfill('0'); - for (string::const_iterator si = source.begin(); si != source.end(); ++si) { - char ch = (*si); + for (char ch : source) { switch (ch) { case '_': case ',': @@ -736,7 +767,7 @@ quote(const string &source, const string &safe) { // Letters and digits are safe. result << ch; - } else if (safe.find(ch) != string::npos) { + } else if (safe.find(ch) != std::string_view::npos) { // If it's listed in "safe", it's safe. result << ch; @@ -755,12 +786,11 @@ quote(const string &source, const string &safe) { * plus signs. */ string URLSpec:: -quote_plus(const string &source, const string &safe) { +quote_plus(std::string_view source, std::string_view safe) { ostringstream result; result << std::hex << setfill('0'); - for (string::const_iterator si = source.begin(); si != source.end(); ++si) { - char ch = (*si); + for (char ch : source) { switch (ch) { case '_': case ',': @@ -779,7 +809,7 @@ quote_plus(const string &source, const string &safe) { // Letters and digits are safe. result << ch; - } else if (safe.find(ch) != string::npos) { + } else if (safe.find(ch) != std::string_view::npos) { // If it's listed in "safe", it's safe. result << ch; @@ -798,7 +828,7 @@ quote_plus(const string &source, const string &safe) { * "%xx" to their ascii equivalent. */ string URLSpec:: -unquote(const string &source) { +unquote(std::string_view source) { string result; size_t p = 0; @@ -834,7 +864,7 @@ unquote(const string &source) { * spaces. */ string URLSpec:: -unquote_plus(const string &source) { +unquote_plus(std::string_view source) { string result; size_t p = 0; diff --git a/panda/src/downloader/urlSpec.h b/panda/src/downloader/urlSpec.h index 91a4e7a5bf7..4924a15d7ac 100644 --- a/panda/src/downloader/urlSpec.h +++ b/panda/src/downloader/urlSpec.h @@ -28,9 +28,10 @@ class Filename; class EXPCL_PANDA_DOWNLOADER URLSpec { PUBLISHED: URLSpec(); - INLINE URLSpec(const std::string &url, bool server_name_expected = false); + INLINE URLSpec(std::string_view url, bool server_name_expected = false); explicit URLSpec(const URLSpec &url, const Filename &path); INLINE void operator = (const std::string &url); + INLINE void operator = (std::string_view url); INLINE bool operator == (const URLSpec &other) const; INLINE bool operator != (const URLSpec &other) const; @@ -54,7 +55,7 @@ class EXPCL_PANDA_DOWNLOADER URLSpec { uint16_t get_port() const; std::string get_server_and_port() const; bool is_default_port() const; - static int get_default_port_for_scheme(const std::string &scheme); + static int get_default_port_for_scheme(std::string_view scheme); std::string get_path() const; INLINE std::string get_query() const; std::string get_path_and_query() const; @@ -62,17 +63,17 @@ class EXPCL_PANDA_DOWNLOADER URLSpec { INLINE const std::string &get_url() const; - void set_scheme(const std::string &scheme); - void set_authority(const std::string &authority); - void set_username(const std::string &username); - void set_server(const std::string &server); - void set_port(const std::string &port); + void set_scheme(std::string_view scheme); + void set_authority(std::string_view authority); + void set_username(std::string_view username); + void set_server(std::string_view server); + void set_port(std::string_view port); void set_port(uint16_t port); - void set_server_and_port(const std::string &server_and_port); - void set_path(const std::string &path); - void set_query(const std::string &query); + void set_server_and_port(std::string_view server_and_port); + void set_path(std::string_view path); + void set_query(std::string_view query); - void set_url(const std::string &url, bool server_name_expected = false); + void set_url(std::string_view url, bool server_name_expected = false); INLINE operator const std::string & () const; INLINE const char *c_str() const; @@ -85,10 +86,10 @@ class EXPCL_PANDA_DOWNLOADER URLSpec { bool input(std::istream &in); void output(std::ostream &out) const; - static std::string quote(const std::string &source, const std::string &safe = "/"); - static std::string quote_plus(const std::string &source, const std::string &safe = "/"); - static std::string unquote(const std::string &source); - static std::string unquote_plus(const std::string &source); + static std::string quote(std::string_view source, std::string_view safe = "/"); + static std::string quote_plus(std::string_view source, std::string_view safe = "/"); + static std::string unquote(std::string_view source); + static std::string unquote_plus(std::string_view source); MAKE_PROPERTY(scheme, get_scheme, set_scheme); MAKE_PROPERTY(authority, get_authority, set_authority); diff --git a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx index e4ba7819d7a..399c6998b1a 100644 --- a/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx +++ b/panda/src/dxgsg9/dxGraphicsStateGuardian9.cxx @@ -4443,21 +4443,21 @@ set_texture_blend_mode(int i, const TextureStage *stage) { (i, D3DTSS_COLORARG0, get_texture_argument(stage->get_combine_rgb_source2(), stage->get_combine_rgb_operand2())); - // fall through + [[fallthrough]]; case 2: set_texture_stage_state (i, D3DTSS_COLORARG2, get_texture_argument(stage->get_combine_rgb_source1(), stage->get_combine_rgb_operand1())); - // fall through + [[fallthrough]]; case 1: set_texture_stage_state (i, D3DTSS_COLORARG1, get_texture_argument(stage->get_combine_rgb_source0(), stage->get_combine_rgb_operand0())); - // fall through + [[fallthrough]]; default: break; @@ -4474,21 +4474,21 @@ set_texture_blend_mode(int i, const TextureStage *stage) { (i, D3DTSS_ALPHAARG0, get_texture_argument(stage->get_combine_alpha_source2(), stage->get_combine_alpha_operand2())); - // fall through + [[fallthrough]]; case 2: set_texture_stage_state (i, D3DTSS_ALPHAARG2, get_texture_argument(stage->get_combine_alpha_source1(), stage->get_combine_alpha_operand1())); - // fall through + [[fallthrough]]; case 1: set_texture_stage_state (i, D3DTSS_ALPHAARG1, get_texture_argument(stage->get_combine_alpha_source0(), stage->get_combine_alpha_operand0())); - // fall through + [[fallthrough]]; default: break; diff --git a/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx b/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx index d43febe03eb..1fe9bd0e97c 100644 --- a/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx +++ b/panda/src/dxgsg9/wdxGraphicsBuffer9.cxx @@ -30,13 +30,13 @@ TypeHandle wdxGraphicsBuffer9::_type_handle; */ wdxGraphicsBuffer9:: wdxGraphicsBuffer9(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host): - GraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + GraphicsBuffer(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { // initialize all class members _cube_map_index = -1; diff --git a/panda/src/dxgsg9/wdxGraphicsBuffer9.h b/panda/src/dxgsg9/wdxGraphicsBuffer9.h index 747307642b0..ec19801dcd5 100644 --- a/panda/src/dxgsg9/wdxGraphicsBuffer9.h +++ b/panda/src/dxgsg9/wdxGraphicsBuffer9.h @@ -29,7 +29,7 @@ class EXPCL_PANDADX wdxGraphicsBuffer9 : public GraphicsBuffer { public: wdxGraphicsBuffer9(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/dxgsg9/wdxGraphicsPipe9.cxx b/panda/src/dxgsg9/wdxGraphicsPipe9.cxx index 1e9222a637e..c636a8ed53f 100644 --- a/panda/src/dxgsg9/wdxGraphicsPipe9.cxx +++ b/panda/src/dxgsg9/wdxGraphicsPipe9.cxx @@ -80,7 +80,7 @@ pipe_constructor() { * Creates a new window on the pipe, if possible. */ PT(GraphicsOutput) wdxGraphicsPipe9:: -make_output(const std::string &name, +make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -120,7 +120,7 @@ make_output(const std::string &name, return nullptr; } } - return new wdxGraphicsWindow9(engine, this, name, fb_prop, win_prop, + return new wdxGraphicsWindow9(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } @@ -151,7 +151,7 @@ make_output(const std::string &name, wdxgsg->get_supports_render_texture()) { precertify = true; } - return new wdxGraphicsBuffer9(engine, this, name, fb_prop, win_prop, + return new wdxGraphicsBuffer9(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } diff --git a/panda/src/dxgsg9/wdxGraphicsPipe9.h b/panda/src/dxgsg9/wdxGraphicsPipe9.h index ff25433e79c..54bfd730f83 100644 --- a/panda/src/dxgsg9/wdxGraphicsPipe9.h +++ b/panda/src/dxgsg9/wdxGraphicsPipe9.h @@ -50,7 +50,7 @@ class EXPCL_PANDADX wdxGraphicsPipe9 : public WinGraphicsPipe { bool special_check_fullscreen_resolution(DXScreenData &scrn, UINT x_size,UINT y_size); protected: - virtual PT(GraphicsOutput) make_output(const std::string &name, + virtual PT(GraphicsOutput) make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/dxgsg9/wdxGraphicsWindow9.cxx b/panda/src/dxgsg9/wdxGraphicsWindow9.cxx index 329a5d21b33..ebcd9a5ba96 100644 --- a/panda/src/dxgsg9/wdxGraphicsWindow9.cxx +++ b/panda/src/dxgsg9/wdxGraphicsWindow9.cxx @@ -35,13 +35,13 @@ TypeHandle wdxGraphicsWindow9::_type_handle; */ wdxGraphicsWindow9:: wdxGraphicsWindow9(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host): - WinGraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + WinGraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { // don't actually create the window in the constructor. reason: multi- // threading requires panda C++ window object to exist in separate thread diff --git a/panda/src/dxgsg9/wdxGraphicsWindow9.h b/panda/src/dxgsg9/wdxGraphicsWindow9.h index 42a6fe6763e..22e60a08175 100644 --- a/panda/src/dxgsg9/wdxGraphicsWindow9.h +++ b/panda/src/dxgsg9/wdxGraphicsWindow9.h @@ -27,7 +27,7 @@ class wdxGraphicsPipe9; class EXPCL_PANDADX wdxGraphicsWindow9 : public WinGraphicsWindow { public: wdxGraphicsWindow9(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/egg/eggAnimData.I b/panda/src/egg/eggAnimData.I index 20b6c6d62c4..f409b594333 100644 --- a/panda/src/egg/eggAnimData.I +++ b/panda/src/egg/eggAnimData.I @@ -17,7 +17,7 @@ * */ INLINE EggAnimData:: -EggAnimData(const std::string &name) : EggNode(name) { +EggAnimData(std::string name) : EggNode(std::move(name)) { _has_fps = false; } diff --git a/panda/src/egg/eggAnimData.h b/panda/src/egg/eggAnimData.h index 9bcb68030be..6b1310b89a4 100644 --- a/panda/src/egg/eggAnimData.h +++ b/panda/src/egg/eggAnimData.h @@ -29,7 +29,7 @@ */ class EXPCL_PANDA_EGG EggAnimData : public EggNode { PUBLISHED: - INLINE explicit EggAnimData(const std::string &name = ""); + INLINE explicit EggAnimData(std::string name = ""); INLINE EggAnimData(const EggAnimData ©); INLINE EggAnimData &operator = (const EggAnimData ©); diff --git a/panda/src/egg/eggAnimPreload.I b/panda/src/egg/eggAnimPreload.I index a13a42ba3d5..ae0f98f387e 100644 --- a/panda/src/egg/eggAnimPreload.I +++ b/panda/src/egg/eggAnimPreload.I @@ -15,7 +15,7 @@ * */ INLINE EggAnimPreload:: -EggAnimPreload(const std::string &name) : EggNode(name) { +EggAnimPreload(std::string name) : EggNode(std::move(name)) { _has_fps = false; _has_num_frames = false; } diff --git a/panda/src/egg/eggAnimPreload.h b/panda/src/egg/eggAnimPreload.h index 1eef9f80840..a306e2d47ec 100644 --- a/panda/src/egg/eggAnimPreload.h +++ b/panda/src/egg/eggAnimPreload.h @@ -23,7 +23,7 @@ */ class EXPCL_PANDA_EGG EggAnimPreload : public EggNode { PUBLISHED: - INLINE explicit EggAnimPreload(const std::string &name = ""); + INLINE explicit EggAnimPreload(std::string name = ""); INLINE EggAnimPreload(const EggAnimPreload ©); INLINE EggAnimPreload &operator = (const EggAnimPreload ©); diff --git a/panda/src/egg/eggBin.cxx b/panda/src/egg/eggBin.cxx index 95a8bdc0a94..b410149c822 100644 --- a/panda/src/egg/eggBin.cxx +++ b/panda/src/egg/eggBin.cxx @@ -21,7 +21,7 @@ TypeHandle EggBin::_type_handle; * */ EggBin:: -EggBin(const std::string &name) : EggGroup(name) { +EggBin(std::string name) : EggGroup(std::move(name)) { _bin_number = 0; } diff --git a/panda/src/egg/eggBin.h b/panda/src/egg/eggBin.h index d6b09dde22c..51668c9bac5 100644 --- a/panda/src/egg/eggBin.h +++ b/panda/src/egg/eggBin.h @@ -25,7 +25,7 @@ */ class EXPCL_PANDA_EGG EggBin : public EggGroup { PUBLISHED: - explicit EggBin(const std::string &name = ""); + explicit EggBin(std::string name = ""); EggBin(const EggGroup ©); EggBin(const EggBin ©); diff --git a/panda/src/egg/eggComment.I b/panda/src/egg/eggComment.I index ac99fb54e9f..0ba77ff8dae 100644 --- a/panda/src/egg/eggComment.I +++ b/panda/src/egg/eggComment.I @@ -15,8 +15,8 @@ * */ INLINE EggComment:: -EggComment(const std::string &node_name, const std::string &comment) - : EggNode(node_name), _comment(comment) { +EggComment(std::string node_name, std::string comment) + : EggNode(std::move(node_name)), _comment(std::move(comment)) { } /** @@ -31,8 +31,8 @@ EggComment(const EggComment ©) : EggNode(copy), _comment(copy._comment) { * */ INLINE EggComment &EggComment:: -operator = (const std::string &comment) { - _comment = comment; +operator = (std::string comment) { + _comment = std::move(comment); return *this; } @@ -60,8 +60,8 @@ operator const std::string & () const { * */ INLINE void EggComment:: -set_comment(const std::string &comment) { - _comment = comment; +set_comment(std::string comment) { + _comment = std::move(comment); } diff --git a/panda/src/egg/eggComment.h b/panda/src/egg/eggComment.h index aab3d1d2396..f72a70c7d8b 100644 --- a/panda/src/egg/eggComment.h +++ b/panda/src/egg/eggComment.h @@ -23,20 +23,20 @@ */ class EXPCL_PANDA_EGG EggComment : public EggNode { PUBLISHED: - INLINE explicit EggComment(const std::string &node_name, const std::string &comment); + INLINE explicit EggComment(std::string node_name, std::string comment); INLINE EggComment(const EggComment ©); // You can use the string operators to directly set and manipulate the // comment. - INLINE EggComment &operator = (const std::string &comment); + INLINE EggComment &operator = (std::string comment); INLINE EggComment &operator = (const EggComment ©); INLINE operator const std::string & () const; // Or, you can set and get it explicitly. - INLINE void set_comment(const std::string &comment); + INLINE void set_comment(std::string comment); INLINE std::string get_comment() const; virtual void write(std::ostream &out, int indent_level) const; diff --git a/panda/src/egg/eggCompositePrimitive.I b/panda/src/egg/eggCompositePrimitive.I index 9adfd8742a8..b5c00ac3097 100644 --- a/panda/src/egg/eggCompositePrimitive.I +++ b/panda/src/egg/eggCompositePrimitive.I @@ -15,7 +15,7 @@ * */ INLINE EggCompositePrimitive:: -EggCompositePrimitive(const std::string &name) : EggPrimitive(name) { +EggCompositePrimitive(std::string name) : EggPrimitive(std::move(name)) { } /** diff --git a/panda/src/egg/eggCompositePrimitive.h b/panda/src/egg/eggCompositePrimitive.h index d7e169624bf..860d9561ab0 100644 --- a/panda/src/egg/eggCompositePrimitive.h +++ b/panda/src/egg/eggCompositePrimitive.h @@ -25,7 +25,7 @@ */ class EXPCL_PANDA_EGG EggCompositePrimitive : public EggPrimitive { PUBLISHED: - INLINE explicit EggCompositePrimitive(const std::string &name = ""); + INLINE explicit EggCompositePrimitive(std::string name = ""); INLINE EggCompositePrimitive(const EggCompositePrimitive ©); INLINE EggCompositePrimitive &operator = (const EggCompositePrimitive ©); virtual ~EggCompositePrimitive(); diff --git a/panda/src/egg/eggCurve.I b/panda/src/egg/eggCurve.I index 2fe86edf6de..4b722776d30 100644 --- a/panda/src/egg/eggCurve.I +++ b/panda/src/egg/eggCurve.I @@ -15,7 +15,7 @@ * */ INLINE EggCurve:: -EggCurve(const std::string &name) : EggPrimitive(name) { +EggCurve(std::string name) : EggPrimitive(std::move(name)) { _subdiv = 0; _type = CT_none; } diff --git a/panda/src/egg/eggCurve.cxx b/panda/src/egg/eggCurve.cxx index 1c18a9ac5e9..1cb548dc94f 100644 --- a/panda/src/egg/eggCurve.cxx +++ b/panda/src/egg/eggCurve.cxx @@ -25,7 +25,7 @@ TypeHandle EggCurve::_type_handle; * CurveType value. */ EggCurve::CurveType EggCurve:: -string_curve_type(const std::string &string) { +string_curve_type(std::string_view string) { if (cmp_nocase_uh(string, "xyz") == 0) { return CT_xyz; } else if (cmp_nocase_uh(string, "hpr") == 0) { diff --git a/panda/src/egg/eggCurve.h b/panda/src/egg/eggCurve.h index 736869fbdbe..5dc91da4c4b 100644 --- a/panda/src/egg/eggCurve.h +++ b/panda/src/egg/eggCurve.h @@ -23,7 +23,7 @@ */ class EXPCL_PANDA_EGG EggCurve : public EggPrimitive { PUBLISHED: - INLINE explicit EggCurve(const std::string &name = ""); + INLINE explicit EggCurve(std::string name = ""); INLINE EggCurve(const EggCurve ©); INLINE EggCurve &operator = (const EggCurve ©); @@ -40,7 +40,7 @@ class EXPCL_PANDA_EGG EggCurve : public EggPrimitive { INLINE void set_curve_type(CurveType type); INLINE CurveType get_curve_type() const; - static CurveType string_curve_type(const std::string &string); + static CurveType string_curve_type(std::string_view string); private: int _subdiv; diff --git a/panda/src/egg/eggExternalReference.cxx b/panda/src/egg/eggExternalReference.cxx index e124e05238d..f69caa320bd 100644 --- a/panda/src/egg/eggExternalReference.cxx +++ b/panda/src/egg/eggExternalReference.cxx @@ -24,8 +24,8 @@ TypeHandle EggExternalReference::_type_handle; * */ EggExternalReference:: -EggExternalReference(const std::string &node_name, const std::string &filename) - : EggFilenameNode(node_name, filename) { +EggExternalReference(std::string node_name, Filename filename) + : EggFilenameNode(std::move(node_name), std::move(filename)) { } /** diff --git a/panda/src/egg/eggExternalReference.h b/panda/src/egg/eggExternalReference.h index d19879397da..b6dff3ae760 100644 --- a/panda/src/egg/eggExternalReference.h +++ b/panda/src/egg/eggExternalReference.h @@ -24,7 +24,7 @@ */ class EXPCL_PANDA_EGG EggExternalReference : public EggFilenameNode { PUBLISHED: - explicit EggExternalReference(const std::string &node_name, const std::string &filename); + explicit EggExternalReference(std::string node_name, Filename filename); EggExternalReference(const EggExternalReference ©); EggExternalReference &operator = (const EggExternalReference ©); diff --git a/panda/src/egg/eggFilenameNode.I b/panda/src/egg/eggFilenameNode.I index c368becdaa5..4328f418e16 100644 --- a/panda/src/egg/eggFilenameNode.I +++ b/panda/src/egg/eggFilenameNode.I @@ -22,11 +22,11 @@ EggFilenameNode() { * */ INLINE EggFilenameNode:: -EggFilenameNode(const std::string &node_name, const Filename &filename) : - EggNode(node_name), - _filename(filename), - _fullpath(filename) +EggFilenameNode(std::string node_name, Filename filename) : + EggNode(std::move(node_name)), + _filename(std::move(filename)) { + _fullpath = _filename; } /** diff --git a/panda/src/egg/eggFilenameNode.h b/panda/src/egg/eggFilenameNode.h index ee98f8d091d..24e46abe398 100644 --- a/panda/src/egg/eggFilenameNode.h +++ b/panda/src/egg/eggFilenameNode.h @@ -27,7 +27,7 @@ class EXPCL_PANDA_EGG EggFilenameNode : public EggNode { PUBLISHED: INLINE EggFilenameNode(); - INLINE explicit EggFilenameNode(const std::string &node_name, const Filename &filename); + INLINE explicit EggFilenameNode(std::string node_name, Filename filename); INLINE EggFilenameNode(const EggFilenameNode ©); INLINE EggFilenameNode &operator = (const EggFilenameNode ©); diff --git a/panda/src/egg/eggGroup.I b/panda/src/egg/eggGroup.I index 7809867047d..54ea0d21238 100644 --- a/panda/src/egg/eggGroup.I +++ b/panda/src/egg/eggGroup.I @@ -127,8 +127,8 @@ get_cs_type() const { * */ INLINE void EggGroup:: -set_collision_name(const std::string &collision_name) { - _collision_name = collision_name; +set_collision_name(std::string collision_name) { + _collision_name = std::move(collision_name); } /** @@ -259,8 +259,8 @@ get_switch_fps() const { * */ INLINE void EggGroup:: -add_object_type(const std::string &object_type) { - _object_types.push_back(object_type); +add_object_type(std::string object_type) { + _object_types.push_back(std::move(object_type)); } /** @@ -717,8 +717,8 @@ get_lod() const { * of any one key's value. */ INLINE void EggGroup:: -set_tag(const std::string &key, const std::string &value) { - _tag_data[key] = value; +set_tag(std::string key, std::string value) { + _tag_data[std::move(key)] = std::move(value); } /** @@ -727,7 +727,7 @@ set_tag(const std::string &key, const std::string &value) { * the empty string. */ INLINE std::string EggGroup:: -get_tag(const std::string &key) const { +get_tag(std::string_view key) const { TagData::const_iterator ti; ti = _tag_data.find(key); if (ti != _tag_data.end()) { @@ -742,7 +742,7 @@ get_tag(const std::string &key) const { * set. */ INLINE bool EggGroup:: -has_tag(const std::string &key) const { +has_tag(std::string_view key) const { TagData::const_iterator ti; ti = _tag_data.find(key); return (ti != _tag_data.end()); @@ -753,8 +753,11 @@ has_tag(const std::string &key) const { * call to clear_tag(), has_tag() will return false for the indicated key. */ INLINE void EggGroup:: -clear_tag(const std::string &key) { - _tag_data.erase(key); +clear_tag(std::string_view key) { + TagData::iterator ti = _tag_data.find(key); + if (ti != _tag_data.end()) { + _tag_data.erase(ti); + } } /** diff --git a/panda/src/egg/eggGroup.cxx b/panda/src/egg/eggGroup.cxx index f47e0cab984..d7003cad4ea 100644 --- a/panda/src/egg/eggGroup.cxx +++ b/panda/src/egg/eggGroup.cxx @@ -32,7 +32,7 @@ TypeHandle EggGroup::_type_handle; * */ EggGroup:: -EggGroup(const string &name) : EggGroupNode(name) { +EggGroup(std::string name) : EggGroupNode(std::move(name)) { _flags = 0; _flags2 = 0; _fps = 0.0; @@ -142,7 +142,7 @@ set_group_type(GroupType type) { * false otherwise. */ bool EggGroup:: -has_object_type(const string &object_type) const { +has_object_type(std::string_view object_type) const { vector_string::const_iterator oi; for (oi = _object_types.begin(); oi != _object_types.end(); ++oi) { if (cmp_nocase_uh((*oi), object_type) == 0) { @@ -158,7 +158,7 @@ has_object_type(const string &object_type) const { * false otherwise. */ bool EggGroup:: -remove_object_type(const string &object_type) { +remove_object_type(std::string_view object_type) { vector_string::iterator oi; for (oi = _object_types.begin(); oi != _object_types.end(); ++oi) { if (cmp_nocase_uh((*oi), object_type) == 0) { @@ -805,7 +805,7 @@ clear_group_refs() { * GroupType value. */ EggGroup::GroupType EggGroup:: -string_group_type(const string &strval) { +string_group_type(std::string_view strval) { if (cmp_nocase_uh(strval, "group") == 0) { return GT_group; } else if (cmp_nocase_uh(strval, "instance") == 0) { @@ -822,7 +822,7 @@ string_group_type(const string &strval) { * or DT_none if the string does not match any known DartType value. */ EggGroup::DartType EggGroup:: -string_dart_type(const string &strval) { +string_dart_type(std::string_view strval) { if (cmp_nocase_uh(strval, "sync") == 0) { return DT_sync; } else if (cmp_nocase_uh(strval, "nosync") == 0) { @@ -841,7 +841,7 @@ string_dart_type(const string &strval) { * or DC_unspecified if the string does not match any known DCSType value. */ EggGroup::DCSType EggGroup:: -string_dcs_type(const string &strval) { +string_dcs_type(std::string_view strval) { if (cmp_nocase_uh(strval, "none") == 0) { return DC_none; } else if (cmp_nocase_uh(strval, "local") == 0) { @@ -863,7 +863,7 @@ string_dcs_type(const string &strval) { * BillboardType value. */ EggGroup::BillboardType EggGroup:: -string_billboard_type(const string &strval) { +string_billboard_type(std::string_view strval) { if (cmp_nocase_uh(strval, "axis") == 0) { return BT_axis; } else if (cmp_nocase_uh(strval, "point_eye") == 0) { @@ -883,7 +883,7 @@ string_billboard_type(const string &strval) { * CollisionSolidType value. */ EggGroup::CollisionSolidType EggGroup:: -string_cs_type(const string &strval) { +string_cs_type(std::string_view strval) { if (cmp_nocase_uh(strval, "plane") == 0) { return CST_plane; } else if (cmp_nocase_uh(strval, "polygon") == 0) { @@ -915,7 +915,7 @@ string_cs_type(const string &strval) { * attempt to parse a string of keywords. */ EggGroup::CollideFlags EggGroup:: -string_collide_flags(const string &strval) { +string_collide_flags(std::string_view strval) { if (cmp_nocase_uh(strval, "intangible") == 0) { return CF_intangible; } else if (cmp_nocase_uh(strval, "event") == 0) { @@ -943,7 +943,7 @@ string_collide_flags(const string &strval) { * BlendMode. */ EggGroup::BlendMode EggGroup:: -string_blend_mode(const string &strval) { +string_blend_mode(std::string_view strval) { if (cmp_nocase_uh(strval, "none") == 0) { return BM_none; } else if (cmp_nocase_uh(strval, "add") == 0) { @@ -967,7 +967,7 @@ string_blend_mode(const string &strval) { * BlendOperand. */ EggGroup::BlendOperand EggGroup:: -string_blend_operand(const string &strval) { +string_blend_operand(std::string_view strval) { if (cmp_nocase_uh(strval, "zero") == 0) { return BO_zero; } else if (cmp_nocase_uh(strval, "one") == 0) { diff --git a/panda/src/egg/eggGroup.h b/panda/src/egg/eggGroup.h index 639d5eb202c..de7303c7c02 100644 --- a/panda/src/egg/eggGroup.h +++ b/panda/src/egg/eggGroup.h @@ -34,7 +34,7 @@ class EXPCL_PANDA_EGG EggGroup : public EggGroupNode, public EggRenderMode, public EggTransform { PUBLISHED: typedef pmap VertexRef; - typedef pmap TagData; + typedef pmap> TagData; // These bits are all stored somewhere in _flags. enum GroupType { @@ -132,7 +132,7 @@ class EXPCL_PANDA_EGG EggGroup : public EggGroupNode, public EggRenderMode, publ BO_one_minus_alpha_scale, }; - explicit EggGroup(const std::string &name = ""); + explicit EggGroup(std::string name = ""); EggGroup(const EggGroup ©); EggGroup &operator = (const EggGroup ©); ~EggGroup(); @@ -177,7 +177,7 @@ class EXPCL_PANDA_EGG EggGroup : public EggGroupNode, public EggRenderMode, publ INLINE void set_collide_flags(int flags); INLINE CollideFlags get_collide_flags() const; - INLINE void set_collision_name(const std::string &collision_name); + INLINE void set_collision_name(std::string collision_name); INLINE void clear_collision_name(); INLINE bool has_collision_name() const; INLINE const std::string &get_collision_name() const; @@ -195,13 +195,13 @@ class EXPCL_PANDA_EGG EggGroup : public EggGroupNode, public EggRenderMode, publ INLINE void set_switch_fps(double fps); INLINE double get_switch_fps() const; - INLINE void add_object_type(const std::string &object_type); + INLINE void add_object_type(std::string object_type); INLINE void clear_object_types(); INLINE int get_num_object_types() const; INLINE std::string get_object_type(int index) const; MAKE_SEQ(get_object_types, get_num_object_types, get_object_type); - bool has_object_type(const std::string &object_type) const; - bool remove_object_type(const std::string &object_type); + bool has_object_type(std::string_view object_type) const; + bool remove_object_type(std::string_view object_type); INLINE void set_model_flag(bool flag); INLINE bool get_model_flag() const; @@ -263,10 +263,10 @@ class EXPCL_PANDA_EGG EggGroup : public EggGroupNode, public EggRenderMode, publ INLINE bool has_lod() const; INLINE const EggSwitchCondition &get_lod() const; - INLINE void set_tag(const std::string &key, const std::string &value); - INLINE std::string get_tag(const std::string &key) const; - INLINE bool has_tag(const std::string &key) const; - INLINE void clear_tag(const std::string &key); + INLINE void set_tag(std::string key, std::string value); + INLINE std::string get_tag(std::string_view key) const; + INLINE bool has_tag(std::string_view key) const; + INLINE void clear_tag(std::string_view key); INLINE const EggTransform &get_default_pose() const; INLINE EggTransform &modify_default_pose(); @@ -355,14 +355,14 @@ class EXPCL_PANDA_EGG EggGroup : public EggGroupNode, public EggRenderMode, publ void remove_group_ref(int n); void clear_group_refs(); - static GroupType string_group_type(const std::string &strval); - static DartType string_dart_type(const std::string &strval); - static DCSType string_dcs_type(const std::string &strval); - static BillboardType string_billboard_type(const std::string &strval); - static CollisionSolidType string_cs_type(const std::string &strval); - static CollideFlags string_collide_flags(const std::string &strval); - static BlendMode string_blend_mode(const std::string &strval); - static BlendOperand string_blend_operand(const std::string &strval); + static GroupType string_group_type(std::string_view strval); + static DartType string_dart_type(std::string_view strval); + static DCSType string_dcs_type(std::string_view strval); + static BillboardType string_billboard_type(std::string_view strval); + static CollisionSolidType string_cs_type(std::string_view strval); + static CollideFlags string_collide_flags(std::string_view strval); + static BlendMode string_blend_mode(std::string_view strval); + static BlendOperand string_blend_operand(std::string_view strval); public: virtual EggTransform *as_transform(); diff --git a/panda/src/egg/eggGroupNode.cxx b/panda/src/egg/eggGroupNode.cxx index 7eb2cdb64df..e68601a399d 100644 --- a/panda/src/egg/eggGroupNode.cxx +++ b/panda/src/egg/eggGroupNode.cxx @@ -293,7 +293,7 @@ steal_children(EggGroupNode &other) { * recursively. */ EggNode *EggGroupNode:: -find_child(const string &name) const { +find_child(std::string_view name) const { Children::const_iterator ci; for (ci = _children.begin(); ci != _children.end(); ++ci) { EggNode *child = (*ci); diff --git a/panda/src/egg/eggGroupNode.h b/panda/src/egg/eggGroupNode.h index 75c0c224b0c..44b5cb3d4ec 100644 --- a/panda/src/egg/eggGroupNode.h +++ b/panda/src/egg/eggGroupNode.h @@ -58,7 +58,7 @@ class EXPCL_PANDA_EGG EggGroupNode : public EggNode { // Here begins the actual public interface to EggGroupNode. PUBLISHED: - explicit EggGroupNode(const std::string &name = "") : EggNode(name) { } + explicit EggGroupNode(std::string name = "") : EggNode(std::move(name)) { } EggGroupNode(const EggGroupNode ©); EggGroupNode &operator = (const EggGroupNode ©); virtual ~EggGroupNode(); @@ -115,7 +115,7 @@ class EXPCL_PANDA_EGG EggGroupNode : public EggNode { PT(EggNode) remove_child(EggNode *node); void steal_children(EggGroupNode &other); - EggNode *find_child(const std::string &name) const; + EggNode *find_child(std::string_view name) const; bool has_absolute_pathnames() const; void resolve_filenames(const DSearchPath &searchpath); diff --git a/panda/src/egg/eggGroupUniquifier.cxx b/panda/src/egg/eggGroupUniquifier.cxx index b43529a0928..159bd9d8603 100644 --- a/panda/src/egg/eggGroupUniquifier.cxx +++ b/panda/src/egg/eggGroupUniquifier.cxx @@ -96,7 +96,7 @@ filter_name(EggNode *node) { * uniquely-generated number that may be useful for synthesizing the name. */ string EggGroupUniquifier:: -generate_name(EggNode *node, const string &category, int index) { +generate_name(EggNode *node, std::string_view category, int index) { std::ostringstream str; str << node->get_name() << "_group" << index; return str.str(); diff --git a/panda/src/egg/eggGroupUniquifier.h b/panda/src/egg/eggGroupUniquifier.h index 4c8c142d1a1..98b0dc3b72e 100644 --- a/panda/src/egg/eggGroupUniquifier.h +++ b/panda/src/egg/eggGroupUniquifier.h @@ -30,7 +30,7 @@ class EXPCL_PANDA_EGG EggGroupUniquifier : public EggNameUniquifier { virtual std::string get_category(EggNode *node); virtual std::string filter_name(EggNode *node); virtual std::string generate_name(EggNode *node, - const std::string &category, int index); + std::string_view category, int index); private: bool _filter_names; diff --git a/panda/src/egg/eggLine.I b/panda/src/egg/eggLine.I index 6892c34db0c..4909ba7db0e 100644 --- a/panda/src/egg/eggLine.I +++ b/panda/src/egg/eggLine.I @@ -15,8 +15,8 @@ * */ INLINE EggLine:: -EggLine(const std::string &name) : - EggCompositePrimitive(name), +EggLine(std::string name) : + EggCompositePrimitive(std::move(name)), _has_thick(false) { } diff --git a/panda/src/egg/eggLine.h b/panda/src/egg/eggLine.h index e4c67ff279d..03fb86fa6f9 100644 --- a/panda/src/egg/eggLine.h +++ b/panda/src/egg/eggLine.h @@ -24,7 +24,7 @@ */ class EXPCL_PANDA_EGG EggLine : public EggCompositePrimitive { PUBLISHED: - INLINE explicit EggLine(const std::string &name = ""); + INLINE explicit EggLine(std::string name = ""); INLINE EggLine(const EggLine ©); INLINE EggLine &operator = (const EggLine ©); virtual ~EggLine(); diff --git a/panda/src/egg/eggMaterial.cxx b/panda/src/egg/eggMaterial.cxx index 3d543645a13..945acb93df7 100644 --- a/panda/src/egg/eggMaterial.cxx +++ b/panda/src/egg/eggMaterial.cxx @@ -22,8 +22,8 @@ TypeHandle EggMaterial::_type_handle; * */ EggMaterial:: -EggMaterial(const std::string &mref_name) - : EggNode(mref_name) +EggMaterial(std::string mref_name) + : EggNode(std::move(mref_name)) { _flags = 0; } diff --git a/panda/src/egg/eggMaterial.h b/panda/src/egg/eggMaterial.h index 6d9f9798485..715216187a2 100644 --- a/panda/src/egg/eggMaterial.h +++ b/panda/src/egg/eggMaterial.h @@ -25,7 +25,7 @@ */ class EXPCL_PANDA_EGG EggMaterial : public EggNode { PUBLISHED: - explicit EggMaterial(const std::string &mref_name); + explicit EggMaterial(std::string mref_name); EggMaterial(const EggMaterial ©); virtual void write(std::ostream &out, int indent_level) const; diff --git a/panda/src/egg/eggMaterialCollection.cxx b/panda/src/egg/eggMaterialCollection.cxx index 527bd7a0a69..5482feef287 100644 --- a/panda/src/egg/eggMaterialCollection.cxx +++ b/panda/src/egg/eggMaterialCollection.cxx @@ -383,7 +383,7 @@ create_unique_material(const EggMaterial ©, int eq) { * matches. */ EggMaterial *EggMaterialCollection:: -find_mref(const std::string &mref_name) const { +find_mref(std::string_view mref_name) const { // This requires a complete linear traversal, not terribly efficient. OrderedMaterials::const_iterator oti; for (oti = _ordered_materials.begin(); diff --git a/panda/src/egg/eggMaterialCollection.h b/panda/src/egg/eggMaterialCollection.h index 9f4d196b62b..9f6368ee3e4 100644 --- a/panda/src/egg/eggMaterialCollection.h +++ b/panda/src/egg/eggMaterialCollection.h @@ -90,7 +90,7 @@ class EXPCL_PANDA_EGG EggMaterialCollection { EggMaterial *create_unique_material(const EggMaterial ©, int eq); // Find a material with a particular MRef name. - EggMaterial *find_mref(const std::string &mref_name) const; + EggMaterial *find_mref(std::string_view mref_name) const; private: Materials _materials; diff --git a/panda/src/egg/eggMesherStrip.cxx b/panda/src/egg/eggMesherStrip.cxx index 27260b96b0b..3b65367c49e 100644 --- a/panda/src/egg/eggMesherStrip.cxx +++ b/panda/src/egg/eggMesherStrip.cxx @@ -1113,7 +1113,8 @@ would_reverse_tail(EggMesherStrip::PrimType want_type) const { case PT_tri: case PT_tristrip: - // We don't convert tristrips to quadstrips; fall through. + // We don't convert tristrips to quadstrips. + [[fallthrough]]; default: egg_cat.fatal() << "Invalid conversion!\n"; @@ -1183,7 +1184,8 @@ convert_to_type(EggMesherStrip::PrimType want_type) { case PT_tri: case PT_tristrip: - // We don't convert tristrips to quadstrips; fall through. + // We don't convert tristrips to quadstrips. + [[fallthrough]]; default: egg_cat.fatal() << "Invalid conversion!\n"; diff --git a/panda/src/egg/eggMiscFuncs.cxx b/panda/src/egg/eggMiscFuncs.cxx index 11d684a185f..145556107c9 100644 --- a/panda/src/egg/eggMiscFuncs.cxx +++ b/panda/src/egg/eggMiscFuncs.cxx @@ -27,13 +27,13 @@ using std::string; * always_quote is true, writes quotation marks regardless. */ ostream & -enquote_string(ostream &out, const string &str, int indent_level, +enquote_string(ostream &out, std::string_view str, int indent_level, bool always_quote) { indent(out, indent_level); // First, see if we need to enquote it. bool legal = !always_quote; - string::const_iterator p; + std::string_view::const_iterator p; for (p = str.begin(); p != str.end() && legal; ++p) { legal = (isalnum(*p) || *p=='-' || *p=='_' || *p=='#' || *p=='.'); } diff --git a/panda/src/egg/eggMiscFuncs.h b/panda/src/egg/eggMiscFuncs.h index 6d51d6abc0b..02e4cee5ab0 100644 --- a/panda/src/egg/eggMiscFuncs.h +++ b/panda/src/egg/eggMiscFuncs.h @@ -28,7 +28,7 @@ * always_quote is true, writes quotation marks regardless. */ std::ostream & -enquote_string(std::ostream &out, const std::string &str, +enquote_string(std::ostream &out, std::string_view str, int indent_level = 0, bool always_quote = false); diff --git a/panda/src/egg/eggMorph.I b/panda/src/egg/eggMorph.I index c49f36306f4..0eb7d57b545 100644 --- a/panda/src/egg/eggMorph.I +++ b/panda/src/egg/eggMorph.I @@ -16,8 +16,8 @@ */ template INLINE EggMorph:: -EggMorph(const std::string &name, const Parameter &offset) - : Namable(name), _offset(offset) { +EggMorph(std::string name, const Parameter &offset) + : Namable(std::move(name)), _offset(offset) { } @@ -89,7 +89,7 @@ compare_to(const EggMorph &other, double threshold) const { */ template INLINE void EggMorph:: -output(std::ostream &out, const std::string &tag, int num_dimensions) const { +output(std::ostream &out, std::string_view tag, int num_dimensions) const { out << tag << " " << get_name() << " {"; for (int i = 0; i < num_dimensions; ++i) { out << " " << MAYBE_ZERO(_offset[i]); diff --git a/panda/src/egg/eggMorph.h b/panda/src/egg/eggMorph.h index 29c42cecabe..5ac426ebee8 100644 --- a/panda/src/egg/eggMorph.h +++ b/panda/src/egg/eggMorph.h @@ -29,7 +29,7 @@ template class EggMorph : public Namable { public: - INLINE EggMorph(const std::string &name, const Parameter &offset); + INLINE EggMorph(std::string name, const Parameter &offset); INLINE void set_offset(const Parameter &offset); INLINE const Parameter &get_offset() const; @@ -39,7 +39,7 @@ class EggMorph : public Namable { INLINE int compare_to(const EggMorph &other, double threshold) const; - INLINE void output(std::ostream &out, const std::string &tag, + INLINE void output(std::ostream &out, std::string_view tag, int num_dimensions) const; private: diff --git a/panda/src/egg/eggMorphList.I b/panda/src/egg/eggMorphList.I index 0a2f337550d..2b55a3fd6b4 100644 --- a/panda/src/egg/eggMorphList.I +++ b/panda/src/egg/eggMorphList.I @@ -189,7 +189,7 @@ clear() { */ template void EggMorphList:: -write(std::ostream &out, int indent_level, const std::string &tag, +write(std::ostream &out, int indent_level, std::string_view tag, int num_dimensions) const { const_iterator i; diff --git a/panda/src/egg/eggMorphList.h b/panda/src/egg/eggMorphList.h index 0c890e54f22..e55f3f7229b 100644 --- a/panda/src/egg/eggMorphList.h +++ b/panda/src/egg/eggMorphList.h @@ -57,7 +57,7 @@ class EggMorphList { INLINE void clear(); void write(std::ostream &out, int indent_level, - const std::string &tag, int num_dimensions) const; + std::string_view tag, int num_dimensions) const; private: Morphs _morphs; diff --git a/panda/src/egg/eggNameUniquifier.cxx b/panda/src/egg/eggNameUniquifier.cxx index 239a2b692b5..bec795b8f70 100644 --- a/panda/src/egg/eggNameUniquifier.cxx +++ b/panda/src/egg/eggNameUniquifier.cxx @@ -102,7 +102,7 @@ uniquify(EggNode *node) { * the name has not been used. */ EggNode *EggNameUniquifier:: -get_node(const string &category, const string &name) const { +get_node(std::string_view category, std::string_view name) const { Categories::const_iterator ci; ci = _categories.find(category); if (ci == _categories.end()) { @@ -124,7 +124,7 @@ get_node(const string &category, const string &name) const { * false otherwise. */ bool EggNameUniquifier:: -has_name(const string &category, const string &name) const { +has_name(std::string_view category, std::string_view name) const { Categories::const_iterator ci; ci = _categories.find(category); if (ci == _categories.end()) { @@ -147,8 +147,8 @@ has_name(const string &category, const string &name) const { * added, or false if it was already in use for the category. */ bool EggNameUniquifier:: -add_name(const string &category, const string &name, EggNode *node) { - UsedNames &names = _categories[category]; +add_name(std::string_view category, std::string_view name, EggNode *node) { + UsedNames &names = _categories[std::string(category)]; bool inserted = names.insert(UsedNames::value_type(name, node)).second; return inserted; } @@ -172,7 +172,7 @@ filter_name(EggNode *node) { * uniquely-generated number that may be useful for synthesizing the name. */ string EggNameUniquifier:: -generate_name(EggNode *node, const string &category, int index) { +generate_name(EggNode *node, std::string_view category, int index) { string name = filter_name(node); std::ostringstream str; diff --git a/panda/src/egg/eggNameUniquifier.h b/panda/src/egg/eggNameUniquifier.h index 4b1f0f48d0a..557b688bb6e 100644 --- a/panda/src/egg/eggNameUniquifier.h +++ b/panda/src/egg/eggNameUniquifier.h @@ -65,19 +65,19 @@ class EXPCL_PANDA_EGG EggNameUniquifier : public EggObject { void uniquify(EggNode *node); - EggNode *get_node(const std::string &category, const std::string &name) const; - bool has_name(const std::string &category, const std::string &name) const; - bool add_name(const std::string &category, const std::string &name, + EggNode *get_node(std::string_view category, std::string_view name) const; + bool has_name(std::string_view category, std::string_view name) const; + bool add_name(std::string_view category, std::string_view name, EggNode *node = nullptr); virtual std::string get_category(EggNode *node)=0; virtual std::string filter_name(EggNode *node); virtual std::string generate_name(EggNode *node, - const std::string &category, int index); + std::string_view category, int index); private: - typedef pmap UsedNames; - typedef pmap Categories; + typedef pmap> UsedNames; + typedef pmap> Categories; Categories _categories; int _index; diff --git a/panda/src/egg/eggNamedObject.I b/panda/src/egg/eggNamedObject.I index 77bb78194fd..d99b5ef1112 100644 --- a/panda/src/egg/eggNamedObject.I +++ b/panda/src/egg/eggNamedObject.I @@ -15,7 +15,7 @@ * */ INLINE EggNamedObject:: -EggNamedObject(const std::string &name) : Namable(name) { +EggNamedObject(std::string name) : Namable(std::move(name)) { } diff --git a/panda/src/egg/eggNamedObject.h b/panda/src/egg/eggNamedObject.h index 880dd0ca2d5..456f9a7e44c 100644 --- a/panda/src/egg/eggNamedObject.h +++ b/panda/src/egg/eggNamedObject.h @@ -25,7 +25,7 @@ */ class EXPCL_PANDA_EGG EggNamedObject : public EggObject, public Namable { PUBLISHED: - INLINE explicit EggNamedObject(const std::string &name = ""); + INLINE explicit EggNamedObject(std::string name = ""); INLINE EggNamedObject(const EggNamedObject ©); INLINE EggNamedObject &operator = (const EggNamedObject ©); diff --git a/panda/src/egg/eggNode.I b/panda/src/egg/eggNode.I index 4022139ea5f..c771b4c7e66 100644 --- a/panda/src/egg/eggNode.I +++ b/panda/src/egg/eggNode.I @@ -15,7 +15,7 @@ * */ INLINE EggNode:: -EggNode(const std::string &name) : EggNamedObject(name) { +EggNode(std::string name) : EggNamedObject(std::move(name)) { _parent = nullptr; _depth = 0; _under_flags = 0; diff --git a/panda/src/egg/eggNode.h b/panda/src/egg/eggNode.h index de9c6e3170f..2a837e40745 100644 --- a/panda/src/egg/eggNode.h +++ b/panda/src/egg/eggNode.h @@ -37,7 +37,7 @@ struct EggLexerState; */ class EXPCL_PANDA_EGG EggNode : public EggNamedObject { PUBLISHED: - INLINE explicit EggNode(const std::string &name = ""); + INLINE explicit EggNode(std::string name = ""); INLINE EggNode(const EggNode ©); INLINE EggNode &operator = (const EggNode ©); diff --git a/panda/src/egg/eggNurbsCurve.I b/panda/src/egg/eggNurbsCurve.I index 60f16cc9ca0..57b7503ee40 100644 --- a/panda/src/egg/eggNurbsCurve.I +++ b/panda/src/egg/eggNurbsCurve.I @@ -15,7 +15,7 @@ * */ INLINE EggNurbsCurve:: -EggNurbsCurve(const std::string &name) : EggCurve(name) { +EggNurbsCurve(std::string name) : EggCurve(std::move(name)) { _order = 0; } diff --git a/panda/src/egg/eggNurbsCurve.h b/panda/src/egg/eggNurbsCurve.h index 33eeaaae26f..7c9b2a93b22 100644 --- a/panda/src/egg/eggNurbsCurve.h +++ b/panda/src/egg/eggNurbsCurve.h @@ -25,7 +25,7 @@ */ class EXPCL_PANDA_EGG EggNurbsCurve : public EggCurve { PUBLISHED: - INLINE explicit EggNurbsCurve(const std::string &name = ""); + INLINE explicit EggNurbsCurve(std::string name = ""); INLINE EggNurbsCurve(const EggNurbsCurve ©); INLINE EggNurbsCurve &operator = (const EggNurbsCurve ©); diff --git a/panda/src/egg/eggNurbsSurface.I b/panda/src/egg/eggNurbsSurface.I index cced43e69d4..167b05ae787 100644 --- a/panda/src/egg/eggNurbsSurface.I +++ b/panda/src/egg/eggNurbsSurface.I @@ -15,7 +15,7 @@ * */ INLINE EggNurbsSurface:: -EggNurbsSurface(const std::string &name) : EggSurface(name) { +EggNurbsSurface(std::string name) : EggSurface(std::move(name)) { _u_order = 0; _v_order = 0; } diff --git a/panda/src/egg/eggNurbsSurface.h b/panda/src/egg/eggNurbsSurface.h index 329c50920cc..1d21f1819d4 100644 --- a/panda/src/egg/eggNurbsSurface.h +++ b/panda/src/egg/eggNurbsSurface.h @@ -32,7 +32,7 @@ class EXPCL_PANDA_EGG EggNurbsSurface : public EggSurface { typedef Loops Trim; typedef plist Trims; - INLINE explicit EggNurbsSurface(const std::string &name = ""); + INLINE explicit EggNurbsSurface(std::string name = ""); INLINE EggNurbsSurface(const EggNurbsSurface ©); INLINE EggNurbsSurface &operator = (const EggNurbsSurface ©); diff --git a/panda/src/egg/eggPatch.I b/panda/src/egg/eggPatch.I index 7356ec98eff..999c686ee89 100644 --- a/panda/src/egg/eggPatch.I +++ b/panda/src/egg/eggPatch.I @@ -15,7 +15,7 @@ * */ INLINE EggPatch:: -EggPatch(const std::string &name) : EggPrimitive(name) { +EggPatch(std::string name) : EggPrimitive(std::move(name)) { } /** diff --git a/panda/src/egg/eggPatch.h b/panda/src/egg/eggPatch.h index 72530df4cb9..12aa4db0225 100644 --- a/panda/src/egg/eggPatch.h +++ b/panda/src/egg/eggPatch.h @@ -24,7 +24,7 @@ */ class EXPCL_PANDA_EGG EggPatch : public EggPrimitive { PUBLISHED: - INLINE explicit EggPatch(const std::string &name = ""); + INLINE explicit EggPatch(std::string name = ""); INLINE EggPatch(const EggPatch ©); INLINE EggPatch &operator = (const EggPatch ©); diff --git a/panda/src/egg/eggPoint.I b/panda/src/egg/eggPoint.I index 722e6b7cc58..cb601f8b0ac 100644 --- a/panda/src/egg/eggPoint.I +++ b/panda/src/egg/eggPoint.I @@ -15,8 +15,8 @@ * */ INLINE EggPoint:: -EggPoint(const std::string &name) : - EggPrimitive(name), +EggPoint(std::string name) : + EggPrimitive(std::move(name)), _flags(0), _thick(1.0) { diff --git a/panda/src/egg/eggPoint.h b/panda/src/egg/eggPoint.h index 5c113280c5d..482c2128546 100644 --- a/panda/src/egg/eggPoint.h +++ b/panda/src/egg/eggPoint.h @@ -24,7 +24,7 @@ */ class EXPCL_PANDA_EGG EggPoint : public EggPrimitive { PUBLISHED: - INLINE explicit EggPoint(const std::string &name = ""); + INLINE explicit EggPoint(std::string name = ""); INLINE EggPoint(const EggPoint ©); INLINE EggPoint &operator = (const EggPoint ©); diff --git a/panda/src/egg/eggPolygon.I b/panda/src/egg/eggPolygon.I index 08811e3f7fb..83500470f01 100644 --- a/panda/src/egg/eggPolygon.I +++ b/panda/src/egg/eggPolygon.I @@ -15,7 +15,7 @@ * */ INLINE EggPolygon:: -EggPolygon(const std::string &name) : EggPrimitive(name) { +EggPolygon(std::string name) : EggPrimitive(std::move(name)) { } /** diff --git a/panda/src/egg/eggPolygon.h b/panda/src/egg/eggPolygon.h index ec3c236644f..f60b89faea5 100644 --- a/panda/src/egg/eggPolygon.h +++ b/panda/src/egg/eggPolygon.h @@ -23,7 +23,7 @@ */ class EXPCL_PANDA_EGG EggPolygon : public EggPrimitive { PUBLISHED: - INLINE explicit EggPolygon(const std::string &name = ""); + INLINE explicit EggPolygon(std::string name = ""); INLINE EggPolygon(const EggPolygon ©); INLINE EggPolygon &operator = (const EggPolygon ©); diff --git a/panda/src/egg/eggPrimitive.I b/panda/src/egg/eggPrimitive.I index b98679ff67b..86fe8713b70 100644 --- a/panda/src/egg/eggPrimitive.I +++ b/panda/src/egg/eggPrimitive.I @@ -15,7 +15,7 @@ * */ INLINE EggPrimitive:: -EggPrimitive(const std::string &name): EggNode(name) { +EggPrimitive(std::string name): EggNode(std::move(name)) { _bface = false; _connected_shading = S_unknown; } diff --git a/panda/src/egg/eggPrimitive.h b/panda/src/egg/eggPrimitive.h index f5901e25e92..2d66889f2bb 100644 --- a/panda/src/egg/eggPrimitive.h +++ b/panda/src/egg/eggPrimitive.h @@ -67,7 +67,7 @@ class EXPCL_PANDA_EGG EggPrimitive : public EggNode, public EggAttributes, S_per_vertex }; - INLINE explicit EggPrimitive(const std::string &name = ""); + INLINE explicit EggPrimitive(std::string name = ""); INLINE EggPrimitive(const EggPrimitive ©); INLINE EggPrimitive &operator = (const EggPrimitive ©); INLINE ~EggPrimitive(); diff --git a/panda/src/egg/eggRenderMode.I b/panda/src/egg/eggRenderMode.I index ee21aabf349..24d2f9d6f02 100644 --- a/panda/src/egg/eggRenderMode.I +++ b/panda/src/egg/eggRenderMode.I @@ -186,8 +186,8 @@ clear_draw_order() { * CullTraverser) in use for this to work. See also set_draw_order(). */ INLINE void EggRenderMode:: -set_bin(const std::string &bin) { - _bin = bin; +set_bin(std::string bin) { + _bin = std::move(bin); } /** diff --git a/panda/src/egg/eggRenderMode.cxx b/panda/src/egg/eggRenderMode.cxx index 5ac4b058441..603f74369ec 100644 --- a/panda/src/egg/eggRenderMode.cxx +++ b/panda/src/egg/eggRenderMode.cxx @@ -170,7 +170,7 @@ operator < (const EggRenderMode &other) const { * AlphaMode value. */ EggRenderMode::AlphaMode EggRenderMode:: -string_alpha_mode(const string &string) { +string_alpha_mode(std::string_view string) { if (cmp_nocase_uh(string, "off") == 0) { return AM_off; } else if (cmp_nocase_uh(string, "on") == 0) { @@ -200,7 +200,7 @@ string_alpha_mode(const string &string) { * DepthWriteMode value. */ EggRenderMode::DepthWriteMode EggRenderMode:: -string_depth_write_mode(const string &string) { +string_depth_write_mode(std::string_view string) { if (cmp_nocase_uh(string, "off") == 0) { return DWM_off; } else if (cmp_nocase_uh(string, "on") == 0) { @@ -216,7 +216,7 @@ string_depth_write_mode(const string &string) { * DepthTestMode value. */ EggRenderMode::DepthTestMode EggRenderMode:: -string_depth_test_mode(const string &string) { +string_depth_test_mode(std::string_view string) { if (cmp_nocase_uh(string, "off") == 0) { return DTM_off; } else if (cmp_nocase_uh(string, "on") == 0) { @@ -232,7 +232,7 @@ string_depth_test_mode(const string &string) { * HiddenMode value. */ EggRenderMode::VisibilityMode EggRenderMode:: -string_visibility_mode(const string &string) { +string_visibility_mode(std::string_view string) { if (cmp_nocase_uh(string, "hidden") == 0) { return VM_hidden; } else if (cmp_nocase_uh(string, "normal") == 0) { diff --git a/panda/src/egg/eggRenderMode.h b/panda/src/egg/eggRenderMode.h index 3730cde3da7..28ac364b360 100644 --- a/panda/src/egg/eggRenderMode.h +++ b/panda/src/egg/eggRenderMode.h @@ -83,7 +83,7 @@ class EXPCL_PANDA_EGG EggRenderMode { INLINE bool has_draw_order() const; INLINE void clear_draw_order(); - INLINE void set_bin(const std::string &bin); + INLINE void set_bin(std::string bin); INLINE std::string get_bin() const; INLINE bool has_bin() const; INLINE void clear_bin(); @@ -93,10 +93,10 @@ class EXPCL_PANDA_EGG EggRenderMode { INLINE bool operator != (const EggRenderMode &other) const; bool operator < (const EggRenderMode &other) const; - static AlphaMode string_alpha_mode(const std::string &string); - static DepthWriteMode string_depth_write_mode(const std::string &string); - static DepthTestMode string_depth_test_mode(const std::string &string); - static VisibilityMode string_visibility_mode(const std::string &string); + static AlphaMode string_alpha_mode(std::string_view string); + static DepthWriteMode string_depth_write_mode(std::string_view string); + static DepthTestMode string_depth_test_mode(std::string_view string); + static VisibilityMode string_visibility_mode(std::string_view string); private: AlphaMode _alpha_mode; diff --git a/panda/src/egg/eggSAnimData.I b/panda/src/egg/eggSAnimData.I index e1fe187d549..376a04cd6de 100644 --- a/panda/src/egg/eggSAnimData.I +++ b/panda/src/egg/eggSAnimData.I @@ -15,7 +15,7 @@ * */ INLINE EggSAnimData:: -EggSAnimData(const std::string &name) : EggAnimData(name) { +EggSAnimData(std::string name) : EggAnimData(std::move(name)) { } diff --git a/panda/src/egg/eggSAnimData.h b/panda/src/egg/eggSAnimData.h index c1c28eb2c53..16bc635a21c 100644 --- a/panda/src/egg/eggSAnimData.h +++ b/panda/src/egg/eggSAnimData.h @@ -24,7 +24,7 @@ */ class EXPCL_PANDA_EGG EggSAnimData : public EggAnimData { PUBLISHED: - INLINE explicit EggSAnimData(const std::string &name = ""); + INLINE explicit EggSAnimData(std::string name = ""); INLINE EggSAnimData(const EggSAnimData ©); INLINE EggSAnimData &operator = (const EggSAnimData ©); diff --git a/panda/src/egg/eggSurface.I b/panda/src/egg/eggSurface.I index e03d790408a..def97d8aa74 100644 --- a/panda/src/egg/eggSurface.I +++ b/panda/src/egg/eggSurface.I @@ -15,7 +15,7 @@ * */ INLINE EggSurface:: -EggSurface(const std::string &name) : EggPrimitive(name) { +EggSurface(std::string name) : EggPrimitive(std::move(name)) { _u_subdiv = 0; _v_subdiv = 0; } diff --git a/panda/src/egg/eggSurface.h b/panda/src/egg/eggSurface.h index 19ee6cb907c..311902fc5db 100644 --- a/panda/src/egg/eggSurface.h +++ b/panda/src/egg/eggSurface.h @@ -23,7 +23,7 @@ */ class EXPCL_PANDA_EGG EggSurface : public EggPrimitive { PUBLISHED: - INLINE explicit EggSurface(const std::string &name = ""); + INLINE explicit EggSurface(std::string name = ""); INLINE EggSurface(const EggSurface ©); INLINE EggSurface &operator = (const EggSurface ©); diff --git a/panda/src/egg/eggTable.I b/panda/src/egg/eggTable.I index d5822455ff6..3034f2747ac 100644 --- a/panda/src/egg/eggTable.I +++ b/panda/src/egg/eggTable.I @@ -15,7 +15,7 @@ * */ INLINE EggTable:: -EggTable(const std::string &name) : EggGroupNode(name) { +EggTable(std::string name) : EggGroupNode(std::move(name)) { _type = TT_table; } diff --git a/panda/src/egg/eggTable.cxx b/panda/src/egg/eggTable.cxx index 234c40c5f8f..77de4bc3993 100644 --- a/panda/src/egg/eggTable.cxx +++ b/panda/src/egg/eggTable.cxx @@ -69,7 +69,7 @@ write(std::ostream &out, int indent_level) const { * TableType value. */ EggTable::TableType EggTable:: -string_table_type(const std::string &string) { +string_table_type(std::string_view string) { if (cmp_nocase_uh(string, "table") == 0) { return TT_table; } else if (cmp_nocase_uh(string, "bundle") == 0) { diff --git a/panda/src/egg/eggTable.h b/panda/src/egg/eggTable.h index 59d76e9a086..cc992db0bde 100644 --- a/panda/src/egg/eggTable.h +++ b/panda/src/egg/eggTable.h @@ -32,7 +32,7 @@ class EXPCL_PANDA_EGG EggTable : public EggGroupNode { TT_bundle, }; - INLINE explicit EggTable(const std::string &name = ""); + INLINE explicit EggTable(std::string name = ""); INLINE EggTable(const EggTable ©); INLINE EggTable &operator = (const EggTable ©); @@ -42,7 +42,7 @@ class EXPCL_PANDA_EGG EggTable : public EggGroupNode { bool has_transform() const; virtual void write(std::ostream &out, int indent_level) const; - static TableType string_table_type(const std::string &string); + static TableType string_table_type(std::string_view string); protected: virtual void r_transform(const LMatrix4d &mat, const LMatrix4d &inv, diff --git a/panda/src/egg/eggTexture.I b/panda/src/egg/eggTexture.I index 7a71261e31e..201b55e90ce 100644 --- a/panda/src/egg/eggTexture.I +++ b/panda/src/egg/eggTexture.I @@ -376,8 +376,8 @@ get_quality_level() const { * Each different TextureStage in the world must be uniquely named. */ INLINE void EggTexture:: -set_stage_name(const std::string &stage_name) { - _stage_name = stage_name; +set_stage_name(std::string stage_name) { + _stage_name = std::move(stage_name); _flags |= F_has_stage_name; } @@ -526,11 +526,11 @@ get_border_color() const { * texture coordinates will be used. */ INLINE void EggTexture:: -set_uv_name(const std::string &uv_name) { +set_uv_name(std::string uv_name) { if (uv_name == "default" || uv_name.empty()) { clear_uv_name(); } else { - _uv_name = uv_name; + _uv_name = std::move(uv_name); _flags |= F_has_uv_name; } } diff --git a/panda/src/egg/eggTexture.cxx b/panda/src/egg/eggTexture.cxx index 8b4e261455c..dbc253a4c3d 100644 --- a/panda/src/egg/eggTexture.cxx +++ b/panda/src/egg/eggTexture.cxx @@ -28,8 +28,8 @@ TypeHandle EggTexture::_type_handle; * */ EggTexture:: -EggTexture(const string &tref_name, const Filename &filename) - : EggFilenameNode(tref_name, filename) +EggTexture(std::string tref_name, const Filename &filename) + : EggFilenameNode(std::move(tref_name), filename) { _texture_type = TT_unspecified; _format = F_unspecified; @@ -661,7 +661,7 @@ multitexture_over(EggTexture *other) { * TextureType value. */ EggTexture::TextureType EggTexture:: -string_texture_type(const string &string) { +string_texture_type(std::string_view string) { if (cmp_nocase_uh(string, "1d") == 0 || cmp_nocase_uh(string, "1dtexture") == 0 || cmp_nocase_uh(string, "1d_texture") == 0) { @@ -692,7 +692,7 @@ string_texture_type(const string &string) { * or F_unspecified if the string does not match any known Format value. */ EggTexture::Format EggTexture:: -string_format(const string &string) { +string_format(std::string_view string) { if (cmp_nocase_uh(string, "rgba") == 0) { return F_rgba; } else if (cmp_nocase_uh(string, "srgb_alpha") == 0) { @@ -749,7 +749,7 @@ string_format(const string &string) { * CompressionMode value. */ EggTexture::CompressionMode EggTexture:: -string_compression_mode(const string &string) { +string_compression_mode(std::string_view string) { if (cmp_nocase_uh(string, "off") == 0) { return CM_off; } else if (cmp_nocase_uh(string, "on") == 0) { @@ -776,7 +776,7 @@ string_compression_mode(const string &string) { * or WM_unspecified if the string does not match any known WrapMode value. */ EggTexture::WrapMode EggTexture:: -string_wrap_mode(const string &string) { +string_wrap_mode(std::string_view string) { if (cmp_nocase_uh(string, "repeat") == 0) { return WM_repeat; } else if (cmp_nocase_uh(string, "clamp") == 0) { @@ -798,7 +798,7 @@ string_wrap_mode(const string &string) { * FilterType value. */ EggTexture::FilterType EggTexture:: -string_filter_type(const string &string) { +string_filter_type(std::string_view string) { // Old egg filter types. if (cmp_nocase_uh(string, "point") == 0) { return FT_nearest; @@ -843,7 +843,7 @@ string_filter_type(const string &string) { * or ET_unspecified if the string does not match any known EnvType value. */ EggTexture::EnvType EggTexture:: -string_env_type(const string &string) { +string_env_type(std::string_view string) { if (cmp_nocase_uh(string, "modulate") == 0) { return ET_modulate; @@ -910,7 +910,7 @@ string_env_type(const string &string) { * CombineMode value. */ EggTexture::CombineMode EggTexture:: -string_combine_mode(const string &string) { +string_combine_mode(std::string_view string) { if (cmp_nocase_uh(string, "replace") == 0) { return CM_replace; @@ -946,7 +946,7 @@ string_combine_mode(const string &string) { * CombineSource value. */ EggTexture::CombineSource EggTexture:: -string_combine_source(const string &string) { +string_combine_source(std::string_view string) { if (cmp_nocase_uh(string, "texture") == 0) { return CS_texture; @@ -976,7 +976,7 @@ string_combine_source(const string &string) { * CombineOperand value. */ EggTexture::CombineOperand EggTexture:: -string_combine_operand(const string &string) { +string_combine_operand(std::string_view string) { if (cmp_nocase_uh(string, "src_color") == 0) { return CO_src_color; @@ -999,7 +999,7 @@ string_combine_operand(const string &string) { * or ET_unspecified if the string does not match any known TexGen value. */ EggTexture::TexGen EggTexture:: -string_tex_gen(const string &string) { +string_tex_gen(std::string_view string) { if (cmp_nocase_uh(string, "unspecified") == 0) { return TG_unspecified; @@ -1039,7 +1039,7 @@ string_tex_gen(const string &string) { * or ET_unspecified if the string does not match any known TexGen value. */ EggTexture::QualityLevel EggTexture:: -string_quality_level(const string &string) { +string_quality_level(std::string_view string) { if (cmp_nocase_uh(string, "unspecified") == 0) { return QL_unspecified; diff --git a/panda/src/egg/eggTexture.h b/panda/src/egg/eggTexture.h index 8a8435c9e9c..692aa88fa08 100644 --- a/panda/src/egg/eggTexture.h +++ b/panda/src/egg/eggTexture.h @@ -29,7 +29,7 @@ */ class EXPCL_PANDA_EGG EggTexture : public EggFilenameNode, public EggRenderMode, public EggTransform { PUBLISHED: - explicit EggTexture(const std::string &tref_name, const Filename &filename); + explicit EggTexture(std::string tref_name, const Filename &filename); EggTexture(const EggTexture ©); EggTexture &operator = (const EggTexture ©); virtual ~EggTexture(); @@ -227,7 +227,7 @@ class EXPCL_PANDA_EGG EggTexture : public EggFilenameNode, public EggRenderMode, INLINE void set_quality_level(QualityLevel quality_level); INLINE QualityLevel get_quality_level() const; - INLINE void set_stage_name(const std::string &stage_name); + INLINE void set_stage_name(std::string stage_name); INLINE void clear_stage_name(); INLINE bool has_stage_name() const; INLINE const std::string &get_stage_name() const; @@ -247,7 +247,7 @@ class EXPCL_PANDA_EGG EggTexture : public EggFilenameNode, public EggRenderMode, INLINE bool has_border_color() const; INLINE const LColor &get_border_color() const; - INLINE void set_uv_name(const std::string &uv_name); + INLINE void set_uv_name(std::string uv_name); INLINE void clear_uv_name(); INLINE bool has_uv_name() const; INLINE const std::string &get_uv_name() const; @@ -305,17 +305,17 @@ class EXPCL_PANDA_EGG EggTexture : public EggFilenameNode, public EggRenderMode, bool multitexture_over(EggTexture *other); INLINE int get_multitexture_sort() const; - static TextureType string_texture_type(const std::string &string); - static Format string_format(const std::string &string); - static CompressionMode string_compression_mode(const std::string &string); - static WrapMode string_wrap_mode(const std::string &string); - static FilterType string_filter_type(const std::string &string); - static EnvType string_env_type(const std::string &string); - static CombineMode string_combine_mode(const std::string &string); - static CombineSource string_combine_source(const std::string &string); - static CombineOperand string_combine_operand(const std::string &string); - static TexGen string_tex_gen(const std::string &string); - static QualityLevel string_quality_level(const std::string &string); + static TextureType string_texture_type(std::string_view string); + static Format string_format(std::string_view string); + static CompressionMode string_compression_mode(std::string_view string); + static WrapMode string_wrap_mode(std::string_view string); + static FilterType string_filter_type(std::string_view string); + static EnvType string_env_type(std::string_view string); + static CombineMode string_combine_mode(std::string_view string); + static CombineSource string_combine_source(std::string_view string); + static CombineOperand string_combine_operand(std::string_view string); + static TexGen string_tex_gen(std::string_view string); + static QualityLevel string_quality_level(std::string_view string); PUBLISHED: MAKE_PROPERTY(texture_type, get_texture_type, set_texture_type); diff --git a/panda/src/egg/eggTextureCollection.cxx b/panda/src/egg/eggTextureCollection.cxx index 0c1b46eea76..ae2025d70f4 100644 --- a/panda/src/egg/eggTextureCollection.cxx +++ b/panda/src/egg/eggTextureCollection.cxx @@ -453,7 +453,7 @@ create_unique_texture(const EggTexture ©, int eq) { * matches. */ EggTexture *EggTextureCollection:: -find_tref(const std::string &tref_name) const { +find_tref(std::string_view tref_name) const { // This requires a complete linear traversal, not terribly efficient. OrderedTextures::const_iterator oti; for (oti = _ordered_textures.begin(); diff --git a/panda/src/egg/eggTextureCollection.h b/panda/src/egg/eggTextureCollection.h index 040a8e0da8e..b0e998bc16b 100644 --- a/panda/src/egg/eggTextureCollection.h +++ b/panda/src/egg/eggTextureCollection.h @@ -98,7 +98,7 @@ class EXPCL_PANDA_EGG EggTextureCollection { EggTexture *create_unique_texture(const EggTexture ©, int eq); // Find a texture with a particular TRef name. - EggTexture *find_tref(const std::string &tref_name) const; + EggTexture *find_tref(std::string_view tref_name) const; // Find a texture with a particular filename. EggTexture *find_filename(const Filename &filename) const; diff --git a/panda/src/egg/eggTransform.cxx b/panda/src/egg/eggTransform.cxx index 65ba63c3e7f..9653405cb9e 100644 --- a/panda/src/egg/eggTransform.cxx +++ b/panda/src/egg/eggTransform.cxx @@ -186,7 +186,7 @@ add_uniform_scale(double scale) { * Writes the transform to the indicated stream in Egg format. */ void EggTransform:: -write(std::ostream &out, int indent_level, const std::string &label) const { +write(std::ostream &out, int indent_level, std::string_view label) const { indent(out, indent_level) << label << " {\n"; int num_components = get_num_components(); diff --git a/panda/src/egg/eggTransform.h b/panda/src/egg/eggTransform.h index 529b84d174a..bd8570a6f07 100644 --- a/panda/src/egg/eggTransform.h +++ b/panda/src/egg/eggTransform.h @@ -84,7 +84,7 @@ class EXPCL_PANDA_EGG EggTransform : public MemoryBase { INLINE const LMatrix4d &get_component_mat4(int n) const; void write(std::ostream &out, int indent_level, - const std::string &label) const; + std::string_view label) const; protected: void internal_clear_transform(); diff --git a/panda/src/egg/eggTriangleFan.I b/panda/src/egg/eggTriangleFan.I index d2ddbbdeb3a..46443c5e723 100644 --- a/panda/src/egg/eggTriangleFan.I +++ b/panda/src/egg/eggTriangleFan.I @@ -15,7 +15,7 @@ * */ INLINE EggTriangleFan:: -EggTriangleFan(const std::string &name) : EggCompositePrimitive(name) { +EggTriangleFan(std::string name) : EggCompositePrimitive(std::move(name)) { } /** diff --git a/panda/src/egg/eggTriangleFan.h b/panda/src/egg/eggTriangleFan.h index 29485b2f5f9..47817a7c86b 100644 --- a/panda/src/egg/eggTriangleFan.h +++ b/panda/src/egg/eggTriangleFan.h @@ -24,7 +24,7 @@ */ class EXPCL_PANDA_EGG EggTriangleFan : public EggCompositePrimitive { PUBLISHED: - INLINE explicit EggTriangleFan(const std::string &name = ""); + INLINE explicit EggTriangleFan(std::string name = ""); INLINE EggTriangleFan(const EggTriangleFan ©); INLINE EggTriangleFan &operator = (const EggTriangleFan ©); virtual ~EggTriangleFan(); diff --git a/panda/src/egg/eggTriangleStrip.I b/panda/src/egg/eggTriangleStrip.I index 5e2e5bd33af..ef0881a90eb 100644 --- a/panda/src/egg/eggTriangleStrip.I +++ b/panda/src/egg/eggTriangleStrip.I @@ -15,7 +15,7 @@ * */ INLINE EggTriangleStrip:: -EggTriangleStrip(const std::string &name) : EggCompositePrimitive(name) { +EggTriangleStrip(std::string name) : EggCompositePrimitive(std::move(name)) { } /** diff --git a/panda/src/egg/eggTriangleStrip.h b/panda/src/egg/eggTriangleStrip.h index 052d1742326..7b5d25acbf4 100644 --- a/panda/src/egg/eggTriangleStrip.h +++ b/panda/src/egg/eggTriangleStrip.h @@ -24,7 +24,7 @@ */ class EXPCL_PANDA_EGG EggTriangleStrip : public EggCompositePrimitive { PUBLISHED: - INLINE explicit EggTriangleStrip(const std::string &name = ""); + INLINE explicit EggTriangleStrip(std::string name = ""); INLINE EggTriangleStrip(const EggTriangleStrip ©); INLINE EggTriangleStrip &operator = (const EggTriangleStrip ©); virtual ~EggTriangleStrip(); diff --git a/panda/src/egg/eggVertex.cxx b/panda/src/egg/eggVertex.cxx index cebf9608e72..82df66bcd5a 100644 --- a/panda/src/egg/eggVertex.cxx +++ b/panda/src/egg/eggVertex.cxx @@ -112,7 +112,7 @@ EggVertex:: * UV coordinate pair is 2-d, false otherwise. */ bool EggVertex:: -has_uv(const string &name) const { +has_uv(std::string_view name) const { UVMap::const_iterator ui = _uv_map.find(EggVertexUV::filter_name(name)); if (ui != _uv_map.end()) { EggVertexUV *uv_obj = (*ui).second; @@ -126,7 +126,7 @@ has_uv(const string &name) const { * named UV coordinate triple is 3-d, false otherwise. */ bool EggVertex:: -has_uvw(const string &name) const { +has_uvw(std::string_view name) const { UVMap::const_iterator ui = _uv_map.find(EggVertexUV::filter_name(name)); if (ui != _uv_map.end()) { EggVertexUV *uv_obj = (*ui).second; @@ -139,7 +139,7 @@ has_uvw(const string &name) const { * Returns true if the vertex has the named auxiliary data quadruple. */ bool EggVertex:: -has_aux(const string &name) const { +has_aux(std::string_view name) const { AuxMap::const_iterator xi = _aux_map.find(name); return (xi != _aux_map.end()); } @@ -149,7 +149,7 @@ has_aux(const string &name) const { * this if has_uv(name) returned false. */ LTexCoordd EggVertex:: -get_uv(const string &name) const { +get_uv(std::string_view name) const { UVMap::const_iterator ui = _uv_map.find(EggVertexUV::filter_name(name)); nassertr(ui != _uv_map.end(), LTexCoordd::zero()); return (*ui).second->get_uv(); @@ -160,7 +160,7 @@ get_uv(const string &name) const { * call this if has_uvw(name) returned false. */ const LTexCoord3d &EggVertex:: -get_uvw(const string &name) const { +get_uvw(std::string_view name) const { UVMap::const_iterator ui = _uv_map.find(EggVertexUV::filter_name(name)); nassertr(ui != _uv_map.end(), LTexCoord3d::zero()); return (*ui).second->get_uvw(); @@ -171,7 +171,7 @@ get_uvw(const string &name) const { * to call this if has_aux(name) returned false. */ const LVecBase4d &EggVertex:: -get_aux(const string &name) const { +get_aux(std::string_view name) const { AuxMap::const_iterator xi = _aux_map.find(name); nassertr(xi != _aux_map.end(), LVecBase4d::zero()); return (*xi).second->get_aux(); @@ -183,7 +183,7 @@ get_aux(const string &name) const { * morphs. */ void EggVertex:: -set_uv(const string &name, const LTexCoordd &uv) { +set_uv(std::string_view name, const LTexCoordd &uv) { string fname = EggVertexUV::filter_name(name); PT(EggVertexUV) &uv_obj = _uv_map[fname]; @@ -203,7 +203,7 @@ set_uv(const string &name, const LTexCoordd &uv) { * preserves UV morphs. */ void EggVertex:: -set_uvw(const string &name, const LTexCoord3d &uvw) { +set_uvw(std::string_view name, const LTexCoord3d &uvw) { string fname = EggVertexUV::filter_name(name); PT(EggVertexUV) &uv_obj = _uv_map[fname]; @@ -222,11 +222,11 @@ set_uvw(const string &name, const LTexCoord3d &uvw) { * any auxiliary data with the same name already on the vertex. */ void EggVertex:: -set_aux(const string &name, const LVecBase4d &aux) { +set_aux(std::string name, const LVecBase4d &aux) { PT(EggVertexAux) &aux_obj = _aux_map[name]; if (aux_obj.is_null()) { - aux_obj = new EggVertexAux(name, aux); + aux_obj = new EggVertexAux(std::move(name), aux); } else { aux_obj = new EggVertexAux(*aux_obj); aux_obj->set_aux(aux); @@ -242,7 +242,7 @@ set_aux(const string &name, const LVecBase4d &aux) { * call modify_uv_object to return a modifiable pointer. */ const EggVertexUV *EggVertex:: -get_uv_obj(const string &name) const { +get_uv_obj(std::string_view name) const { UVMap::const_iterator ui = _uv_map.find(EggVertexUV::filter_name(name)); if (ui != _uv_map.end()) { return (*ui).second; @@ -257,7 +257,7 @@ get_uv_obj(const string &name) const { * to return a modifiable pointer. */ const EggVertexAux *EggVertex:: -get_aux_obj(const string &name) const { +get_aux_obj(std::string_view name) const { AuxMap::const_iterator xi = _aux_map.find(name); if (xi != _aux_map.end()) { return (*xi).second; @@ -271,7 +271,7 @@ get_aux_obj(const string &name) const { * if there is no such named UV object. */ EggVertexUV *EggVertex:: -modify_uv_obj(const string &name) { +modify_uv_obj(std::string_view name) { UVMap::iterator ui = _uv_map.find(EggVertexUV::filter_name(name)); if (ui != _uv_map.end()) { if ((*ui).second->get_ref_count() != 1) { @@ -290,7 +290,7 @@ modify_uv_obj(const string &name) { * named UV object. */ EggVertexAux *EggVertex:: -modify_aux_obj(const string &name) { +modify_aux_obj(std::string_view name) { AuxMap::iterator xi = _aux_map.find(name); if (xi != _aux_map.end()) { if ((*xi).second->get_ref_count() != 1) { @@ -327,7 +327,7 @@ set_aux_obj(EggVertexAux *aux) { * morphs. */ void EggVertex:: -clear_uv(const string &name) { +clear_uv(std::string_view name) { _uv_map.erase(EggVertexUV::filter_name(name)); } @@ -335,8 +335,11 @@ clear_uv(const string &name) { * Removes the named auxiliary data from the vertex. */ void EggVertex:: -clear_aux(const string &name) { - _aux_map.erase(name); +clear_aux(std::string_view name) { + AuxMap::iterator xi = _aux_map.find(name); + if (xi != _aux_map.end()) { + _aux_map.erase(xi); + } } /** diff --git a/panda/src/egg/eggVertex.h b/panda/src/egg/eggVertex.h index 55dbc8a3d3e..c8b23abd3e4 100644 --- a/panda/src/egg/eggVertex.h +++ b/panda/src/egg/eggVertex.h @@ -40,8 +40,8 @@ class EXPCL_PANDA_EGG EggVertex : public EggObject, public EggAttributes { public: typedef pset GroupRef; typedef pmultiset PrimitiveRef; - typedef pmap< std::string, PT(EggVertexUV) > UVMap; - typedef pmap< std::string, PT(EggVertexAux) > AuxMap; + typedef pmap< std::string, PT(EggVertexUV), std::less<> > UVMap; + typedef pmap< std::string, PT(EggVertexAux), std::less<> > AuxMap; typedef second_of_pair_iterator uv_iterator; typedef uv_iterator const_uv_iterator; @@ -85,26 +85,26 @@ class EXPCL_PANDA_EGG EggVertex : public EggObject, public EggAttributes { INLINE LTexCoordd get_uv() const; INLINE void set_uv(const LTexCoordd &texCoord); INLINE void clear_uv(); - bool has_uv(const std::string &name) const; - bool has_uvw(const std::string &name) const; - LTexCoordd get_uv(const std::string &name) const; - const LTexCoord3d &get_uvw(const std::string &name) const; - void set_uv(const std::string &name, const LTexCoordd &texCoord); - void set_uvw(const std::string &name, const LTexCoord3d &texCoord); - const EggVertexUV *get_uv_obj(const std::string &name) const; - EggVertexUV *modify_uv_obj(const std::string &name); + bool has_uv(std::string_view name) const; + bool has_uvw(std::string_view name) const; + LTexCoordd get_uv(std::string_view name) const; + const LTexCoord3d &get_uvw(std::string_view name) const; + void set_uv(std::string_view name, const LTexCoordd &texCoord); + void set_uvw(std::string_view name, const LTexCoord3d &texCoord); + const EggVertexUV *get_uv_obj(std::string_view name) const; + EggVertexUV *modify_uv_obj(std::string_view name); void set_uv_obj(EggVertexUV *vertex_uv); - void clear_uv(const std::string &name); + void clear_uv(std::string_view name); INLINE bool has_aux() const; INLINE void clear_aux(); - bool has_aux(const std::string &name) const; - const LVecBase4d &get_aux(const std::string &name) const; - void set_aux(const std::string &name, const LVecBase4d &aux); - const EggVertexAux *get_aux_obj(const std::string &name) const; - EggVertexAux *modify_aux_obj(const std::string &name); + bool has_aux(std::string_view name) const; + const LVecBase4d &get_aux(std::string_view name) const; + void set_aux(std::string name, const LVecBase4d &aux); + const EggVertexAux *get_aux_obj(std::string_view name) const; + EggVertexAux *modify_aux_obj(std::string_view name); void set_aux_obj(EggVertexAux *vertex_aux); - void clear_aux(const std::string &name); + void clear_aux(std::string_view name); static PT(EggVertex) make_average(const EggVertex *first, const EggVertex *second); diff --git a/panda/src/egg/eggVertexAux.I b/panda/src/egg/eggVertexAux.I index 0ff1966d464..8f470afdace 100644 --- a/panda/src/egg/eggVertexAux.I +++ b/panda/src/egg/eggVertexAux.I @@ -15,8 +15,8 @@ * */ INLINE void EggVertexAux:: -set_name(const std::string &name) { - Namable::set_name(name); +set_name(std::string name) { + Namable::set_name(std::move(name)); } /** diff --git a/panda/src/egg/eggVertexAux.cxx b/panda/src/egg/eggVertexAux.cxx index b421c527f6d..637b1ebc65a 100644 --- a/panda/src/egg/eggVertexAux.cxx +++ b/panda/src/egg/eggVertexAux.cxx @@ -22,8 +22,8 @@ TypeHandle EggVertexAux::_type_handle; * */ EggVertexAux:: -EggVertexAux(const std::string &name, const LVecBase4d &aux) : - EggNamedObject(name), +EggVertexAux(std::string name, const LVecBase4d &aux) : + EggNamedObject(std::move(name)), _aux(aux) { } diff --git a/panda/src/egg/eggVertexAux.h b/panda/src/egg/eggVertexAux.h index db8bb67cccb..5a3586c60e2 100644 --- a/panda/src/egg/eggVertexAux.h +++ b/panda/src/egg/eggVertexAux.h @@ -29,12 +29,12 @@ */ class EXPCL_PANDA_EGG EggVertexAux : public EggNamedObject { PUBLISHED: - explicit EggVertexAux(const std::string &name, const LVecBase4d &aux); + explicit EggVertexAux(std::string name, const LVecBase4d &aux); EggVertexAux(const EggVertexAux ©); EggVertexAux &operator = (const EggVertexAux ©); virtual ~EggVertexAux(); - INLINE void set_name(const std::string &name); + INLINE void set_name(std::string name); INLINE const LVecBase4d &get_aux() const; INLINE void set_aux(const LVecBase4d &aux); diff --git a/panda/src/egg/eggVertexPool.cxx b/panda/src/egg/eggVertexPool.cxx index be1a9ff1d79..8aa80642678 100644 --- a/panda/src/egg/eggVertexPool.cxx +++ b/panda/src/egg/eggVertexPool.cxx @@ -28,7 +28,7 @@ TypeHandle EggVertexPool::_type_handle; * */ EggVertexPool:: -EggVertexPool(const string &name) : EggNode(name) { +EggVertexPool(std::string name) : EggNode(std::move(name)) { _highest_index = -1; } diff --git a/panda/src/egg/eggVertexPool.h b/panda/src/egg/eggVertexPool.h index 8ee26fa35b1..b976ce5e366 100644 --- a/panda/src/egg/eggVertexPool.h +++ b/panda/src/egg/eggVertexPool.h @@ -65,7 +65,7 @@ class EXPCL_PANDA_EGG EggVertexPool : public EggNode { // Here begins the actual public interface to EggVertexPool. PUBLISHED: - explicit EggVertexPool(const std::string &name); + explicit EggVertexPool(std::string name); EggVertexPool(const EggVertexPool ©); ~EggVertexPool(); diff --git a/panda/src/egg/eggVertexUV.I b/panda/src/egg/eggVertexUV.I index eef97e52e3a..77aa66b38dc 100644 --- a/panda/src/egg/eggVertexUV.I +++ b/panda/src/egg/eggVertexUV.I @@ -17,18 +17,18 @@ * the texture coordinate name "default" is mapped to the empty string. */ INLINE std::string EggVertexUV:: -filter_name(const std::string &name) { +filter_name(std::string_view name) { if (name == "default") { return std::string(); } - return name; + return std::string(name); } /** * */ INLINE void EggVertexUV:: -set_name(const std::string &name) { +set_name(std::string name) { Namable::set_name(filter_name(name)); } diff --git a/panda/src/egg/eggVertexUV.cxx b/panda/src/egg/eggVertexUV.cxx index bcc0c1055e2..ea6338aa526 100644 --- a/panda/src/egg/eggVertexUV.cxx +++ b/panda/src/egg/eggVertexUV.cxx @@ -22,8 +22,8 @@ TypeHandle EggVertexUV::_type_handle; * */ EggVertexUV:: -EggVertexUV(const std::string &name, const LTexCoordd &uv) : - EggNamedObject(name), +EggVertexUV(std::string name, const LTexCoordd &uv) : + EggNamedObject(std::move(name)), _flags(0), _uvw(uv[0], uv[1], 0.0) { @@ -36,8 +36,8 @@ EggVertexUV(const std::string &name, const LTexCoordd &uv) : * */ EggVertexUV:: -EggVertexUV(const std::string &name, const LTexCoord3d &uvw) : - EggNamedObject(name), +EggVertexUV(std::string name, const LTexCoord3d &uvw) : + EggNamedObject(std::move(name)), _flags(F_has_w), _uvw(uvw) { diff --git a/panda/src/egg/eggVertexUV.h b/panda/src/egg/eggVertexUV.h index e729f281010..9599f864c4c 100644 --- a/panda/src/egg/eggVertexUV.h +++ b/panda/src/egg/eggVertexUV.h @@ -28,14 +28,14 @@ */ class EXPCL_PANDA_EGG EggVertexUV : public EggNamedObject { PUBLISHED: - explicit EggVertexUV(const std::string &name, const LTexCoordd &uv); - explicit EggVertexUV(const std::string &name, const LTexCoord3d &uvw); + explicit EggVertexUV(std::string name, const LTexCoordd &uv); + explicit EggVertexUV(std::string name, const LTexCoord3d &uvw); EggVertexUV(const EggVertexUV ©); EggVertexUV &operator = (const EggVertexUV ©); virtual ~EggVertexUV(); - INLINE static std::string filter_name(const std::string &name); - INLINE void set_name(const std::string &name); + INLINE static std::string filter_name(std::string_view name); + INLINE void set_name(std::string name); INLINE int get_num_dimensions() const; INLINE bool has_w() const; diff --git a/panda/src/egg/eggXfmAnimData.I b/panda/src/egg/eggXfmAnimData.I index 92a888a3c63..f084f45af84 100644 --- a/panda/src/egg/eggXfmAnimData.I +++ b/panda/src/egg/eggXfmAnimData.I @@ -15,7 +15,7 @@ * */ INLINE EggXfmAnimData:: -EggXfmAnimData(const std::string &name, CoordinateSystem cs) : EggAnimData(name) { +EggXfmAnimData(std::string name, CoordinateSystem cs) : EggAnimData(std::move(name)) { _coordsys = cs; } @@ -50,8 +50,8 @@ operator = (const EggXfmAnimData ©) { * */ INLINE void EggXfmAnimData:: -set_order(const std::string &order) { - _order = order; +set_order(std::string order) { + _order = std::move(order); } /** @@ -97,8 +97,8 @@ get_standard_order() { * */ INLINE void EggXfmAnimData:: -set_contents(const std::string &contents) { - _contents = contents; +set_contents(std::string contents) { + _contents = std::move(contents); } /** diff --git a/panda/src/egg/eggXfmAnimData.h b/panda/src/egg/eggXfmAnimData.h index 1fdaec39feb..2fd7d0f1ca1 100644 --- a/panda/src/egg/eggXfmAnimData.h +++ b/panda/src/egg/eggXfmAnimData.h @@ -28,20 +28,20 @@ */ class EXPCL_PANDA_EGG EggXfmAnimData : public EggAnimData { PUBLISHED: - INLINE explicit EggXfmAnimData(const std::string &name = "", + INLINE explicit EggXfmAnimData(std::string name = "", CoordinateSystem cs = CS_default); EggXfmAnimData(const EggXfmSAnim &convert_from); INLINE EggXfmAnimData(const EggXfmAnimData ©); INLINE EggXfmAnimData &operator = (const EggXfmAnimData ©); - INLINE void set_order(const std::string &order); + INLINE void set_order(std::string order); INLINE void clear_order(); INLINE bool has_order() const; INLINE const std::string &get_order() const; INLINE static const std::string &get_standard_order(); - INLINE void set_contents(const std::string &contents); + INLINE void set_contents(std::string contents); INLINE void clear_contents(); INLINE bool has_contents() const; INLINE const std::string &get_contents() const; diff --git a/panda/src/egg/eggXfmSAnim.I b/panda/src/egg/eggXfmSAnim.I index 62ba4300963..9ad7e2862e1 100644 --- a/panda/src/egg/eggXfmSAnim.I +++ b/panda/src/egg/eggXfmSAnim.I @@ -15,7 +15,7 @@ * */ INLINE EggXfmSAnim:: -EggXfmSAnim(const std::string &name, CoordinateSystem cs) : EggGroupNode(name) { +EggXfmSAnim(std::string name, CoordinateSystem cs) : EggGroupNode(std::move(name)) { _has_fps = false; _coordsys = cs; } @@ -88,8 +88,8 @@ get_fps() const { * */ INLINE void EggXfmSAnim:: -set_order(const std::string &order) { - _order = order; +set_order(std::string order) { + _order = std::move(order); } /** diff --git a/panda/src/egg/eggXfmSAnim.cxx b/panda/src/egg/eggXfmSAnim.cxx index 4158d46491c..a89669adeb5 100644 --- a/panda/src/egg/eggXfmSAnim.cxx +++ b/panda/src/egg/eggXfmSAnim.cxx @@ -205,7 +205,7 @@ compose_with_order(LMatrix4d &mat, const LVecBase3d &shear, const LVecBase3d &hpr, const LVecBase3d &trans, - const string &order, + std::string_view order, CoordinateSystem cs) { mat = LMatrix4d::ident_mat(); @@ -219,9 +219,8 @@ compose_with_order(LMatrix4d &mat, reverse_roll = true; } - string::const_iterator pi; - for (pi = order.begin(); pi != order.end(); ++pi) { - switch (*pi) { + for (char c : order) { + switch (c) { case 's': mat = mat * LMatrix4d::scale_shear_mat(scale, shear, cs); break; @@ -248,7 +247,7 @@ compose_with_order(LMatrix4d &mat, default: egg_cat.warning() - << "Invalid letter in order string: " << *pi << "\n"; + << "Invalid letter in order string: " << c << "\n"; } } } @@ -553,12 +552,12 @@ add_data(const LMatrix4d &mat) { * the table. */ void EggXfmSAnim:: -add_component_data(const string &component_name, double value) { +add_component_data(std::string_view component_name, double value) { EggNode *child = find_child(component_name); EggSAnimData *sanim; if (child == nullptr) { // We don't have this component yet; create it. - sanim = new EggSAnimData(component_name); + sanim = new EggSAnimData(std::string(component_name)); add_child(sanim); } else { diff --git a/panda/src/egg/eggXfmSAnim.h b/panda/src/egg/eggXfmSAnim.h index 1fd37c51ad5..bebe83522a1 100644 --- a/panda/src/egg/eggXfmSAnim.h +++ b/panda/src/egg/eggXfmSAnim.h @@ -27,7 +27,7 @@ class EggXfmAnimData; */ class EXPCL_PANDA_EGG EggXfmSAnim : public EggGroupNode { PUBLISHED: - INLINE explicit EggXfmSAnim(const std::string &name = "", + INLINE explicit EggXfmSAnim(std::string name = "", CoordinateSystem cs = CS_default); EggXfmSAnim(const EggXfmAnimData &convert_from); @@ -39,7 +39,7 @@ class EXPCL_PANDA_EGG EggXfmSAnim : public EggGroupNode { INLINE bool has_fps() const; INLINE double get_fps() const; - INLINE void set_order(const std::string &order); + INLINE void set_order(std::string order); INLINE void clear_order(); INLINE bool has_order() const; INLINE const std::string &get_order() const; @@ -57,7 +57,7 @@ class EXPCL_PANDA_EGG EggXfmSAnim : public EggGroupNode { INLINE void clear_data(); bool add_data(const LMatrix4d &mat); - void add_component_data(const std::string &component_name, double value); + void add_component_data(std::string_view component_name, double value); void add_component_data(int component, double value); virtual bool is_anim_matrix() const; @@ -68,7 +68,7 @@ class EXPCL_PANDA_EGG EggXfmSAnim : public EggGroupNode { const LVecBase3d &shear, const LVecBase3d &hpr, const LVecBase3d &trans, - const std::string &order, + std::string_view order, CoordinateSystem cs); protected: diff --git a/panda/src/egg/lexer.cxx.prebuilt b/panda/src/egg/lexer.cxx.prebuilt index 24e04b5cf90..08cdfbc29ec 100644 --- a/panda/src/egg/lexer.cxx.prebuilt +++ b/panda/src/egg/lexer.cxx.prebuilt @@ -1158,11 +1158,11 @@ static EggLexerState *eggyyget_extra(yyscan_t scanner); //////////////////////////////////////////////////////////////////// void -egg_init_lexer_state(EggLexerState &state, std::istream &in, const std::string &filename) { +egg_init_lexer_state(EggLexerState &state, std::istream &in, std::string filename) { state._error_count = 0; state._warning_count = 0; state._input_p = ∈ - state._egg_filename = filename; + state._egg_filename = std::move(filename); state._initial_token = START_EGG; } @@ -1194,7 +1194,7 @@ egg_start_primitive_body(EggLexerState &state) { //////////////////////////////////////////////////////////////////// void -eggyyerror(YYLTYPE *loc, yyscan_t scanner, const std::string &msg) { +eggyyerror(YYLTYPE *loc, yyscan_t scanner, std::string_view msg) { EggLexerState *lexer_state = eggyyget_extra(scanner); if (egg_cat.is_error()) { @@ -1243,7 +1243,7 @@ eggyyerror(YYLTYPE *loc, yyscan_t scanner, const std::string &msg) { } void -eggyywarning(YYLTYPE *loc, yyscan_t scanner, const std::string &msg) { +eggyywarning(YYLTYPE *loc, yyscan_t scanner, std::string_view msg) { EggLexerState *lexer_state = eggyyget_extra(scanner); if (egg_cat.is_warning()) { diff --git a/panda/src/egg/lexer.lxx b/panda/src/egg/lexer.lxx index 3edf547107e..6b85ddecfb9 100644 --- a/panda/src/egg/lexer.lxx +++ b/panda/src/egg/lexer.lxx @@ -31,11 +31,11 @@ static EggLexerState *eggyyget_extra(yyscan_t scanner); //////////////////////////////////////////////////////////////////// void -egg_init_lexer_state(EggLexerState &state, std::istream &in, const std::string &filename) { +egg_init_lexer_state(EggLexerState &state, std::istream &in, std::string filename) { state._error_count = 0; state._warning_count = 0; state._input_p = ∈ - state._egg_filename = filename; + state._egg_filename = std::move(filename); state._initial_token = START_EGG; } @@ -67,7 +67,7 @@ egg_start_primitive_body(EggLexerState &state) { //////////////////////////////////////////////////////////////////// void -eggyyerror(YYLTYPE *loc, yyscan_t scanner, const std::string &msg) { +eggyyerror(YYLTYPE *loc, yyscan_t scanner, std::string_view msg) { EggLexerState *lexer_state = eggyyget_extra(scanner); if (egg_cat.is_error()) { @@ -116,7 +116,7 @@ eggyyerror(YYLTYPE *loc, yyscan_t scanner, const std::string &msg) { } void -eggyywarning(YYLTYPE *loc, yyscan_t scanner, const std::string &msg) { +eggyywarning(YYLTYPE *loc, yyscan_t scanner, std::string_view msg) { EggLexerState *lexer_state = eggyyget_extra(scanner); if (egg_cat.is_warning()) { diff --git a/panda/src/egg/lexerDefs.h b/panda/src/egg/lexerDefs.h index a6186575270..d7e086f0a74 100644 --- a/panda/src/egg/lexerDefs.h +++ b/panda/src/egg/lexerDefs.h @@ -25,7 +25,7 @@ struct EggParserState; struct EggTokenType; struct EggLocType; -void egg_init_lexer_state(EggLexerState &state, std::istream &in, const std::string &filename); +void egg_init_lexer_state(EggLexerState &state, std::istream &in, std::string filename); void egg_cleanup_lexer_state(EggLexerState &state); void egg_start_group_body(EggLexerState &state); @@ -36,8 +36,8 @@ void egg_start_primitive_body(EggLexerState &state); int eggyylex_init_extra(EggLexerState *state, yyscan_t *scanner); int eggyylex_destroy(yyscan_t scanner); -void eggyyerror(EggLocType *loc, yyscan_t scanner, const std::string &msg); -void eggyywarning(EggLocType *loc, yyscan_t scanner, const std::string &msg); +void eggyyerror(EggLocType *loc, yyscan_t scanner, std::string_view msg); +void eggyywarning(EggLocType *loc, yyscan_t scanner, std::string_view msg); int eggyylex(EggTokenType *yylval_param, EggLocType *yylloc_param, yyscan_t yyscanner); diff --git a/panda/src/egg2pg/animBundleMaker.cxx b/panda/src/egg2pg/animBundleMaker.cxx index ea5ac4285f1..976e9d54085 100644 --- a/panda/src/egg2pg/animBundleMaker.cxx +++ b/panda/src/egg2pg/animBundleMaker.cxx @@ -214,10 +214,9 @@ build_hierarchy(EggTable *egg_table, AnimGroup *parent) { * structure. */ AnimChannelScalarTable *AnimBundleMaker:: -create_s_channel(EggSAnimData *egg_anim, const std::string &name, - AnimGroup *parent) { +create_s_channel(EggSAnimData *egg_anim, std::string name, AnimGroup *parent) { AnimChannelScalarTable *table - = new AnimChannelScalarTable(parent, name); + = new AnimChannelScalarTable(parent, std::move(name)); // First we have to copy the table data from PTA_double to PTA_stdfloat. PTA_stdfloat new_data = PTA_stdfloat::empty_array(egg_anim->get_num_rows(), @@ -238,16 +237,15 @@ create_s_channel(EggSAnimData *egg_anim, const std::string &name, * structure, if possible. */ AnimChannelMatrixXfmTable *AnimBundleMaker:: -create_xfm_channel(EggNode *egg_node, const std::string &name, - AnimGroup *parent) { +create_xfm_channel(EggNode *egg_node, std::string name, AnimGroup *parent) { if (egg_node->is_of_type(EggXfmAnimData::get_class_type())) { EggXfmAnimData *egg_anim = DCAST(EggXfmAnimData, egg_node); EggXfmSAnim new_anim(*egg_anim); - return create_xfm_channel(&new_anim, name, parent); + return create_xfm_channel(&new_anim, std::move(name), parent); } else if (egg_node->is_of_type(EggXfmSAnim::get_class_type())) { EggXfmSAnim *egg_anim = DCAST(EggXfmSAnim, egg_node); - return create_xfm_channel(egg_anim, name, parent); + return create_xfm_channel(egg_anim, std::move(name), parent); } egg2pg_cat.warning() @@ -262,13 +260,12 @@ create_xfm_channel(EggNode *egg_node, const std::string &name, * structure. */ AnimChannelMatrixXfmTable *AnimBundleMaker:: -create_xfm_channel(EggXfmSAnim *egg_anim, const std::string &name, - AnimGroup *parent) { +create_xfm_channel(EggXfmSAnim *egg_anim, std::string name, AnimGroup *parent) { // Ensure that the anim table is optimal and that it is standard order. egg_anim->optimize_to_standard_order(); AnimChannelMatrixXfmTable *table - = new AnimChannelMatrixXfmTable(parent, name); + = new AnimChannelMatrixXfmTable(parent, std::move(name)); // The EggXfmSAnim structure has a number of children which are EggSAnimData // tables. Each of these represents a separate component of the transform @@ -281,7 +278,7 @@ create_xfm_channel(EggXfmSAnim *egg_anim, const std::string &name, if (child->get_name().empty()) { egg2pg_cat.warning() - << "Unnamed subtable of " << name + << "Unnamed subtable of " << table->get_name() << "\n"; } else { char table_id = child->get_name()[0]; @@ -290,12 +287,12 @@ create_xfm_channel(EggXfmSAnim *egg_anim, const std::string &name, !table->is_valid_id(table_id)) { egg2pg_cat.warning() << "Unexpected table name " << child->get_name() - << ", child of " << name << "\n"; + << ", child of " << table->get_name() << "\n"; } else if (table->has_table(table_id)) { egg2pg_cat.warning() << "Duplicate table definition for " << table_id - << " under " << name << "\n"; + << " under " << table->get_name() << "\n"; } else { diff --git a/panda/src/egg2pg/animBundleMaker.h b/panda/src/egg2pg/animBundleMaker.h index 602675c209d..3e9fd5b8c3f 100644 --- a/panda/src/egg2pg/animBundleMaker.h +++ b/panda/src/egg2pg/animBundleMaker.h @@ -45,14 +45,11 @@ class EXPCL_PANDA_EGG2PG AnimBundleMaker { void build_hierarchy(EggTable *egg_table, AnimGroup *parent); AnimChannelScalarTable * - create_s_channel(EggSAnimData *egg_anim, const std::string &name, - AnimGroup *parent); + create_s_channel(EggSAnimData *egg_anim, std::string name, AnimGroup *parent); AnimChannelMatrixXfmTable * - create_xfm_channel(EggNode *egg_node, const std::string &name, - AnimGroup *parent); + create_xfm_channel(EggNode *egg_node, std::string name, AnimGroup *parent); AnimChannelMatrixXfmTable * - create_xfm_channel(EggXfmSAnim *egg_anim, const std::string &name, - AnimGroup *parent); + create_xfm_channel(EggXfmSAnim *egg_anim, std::string name, AnimGroup *parent); PN_stdfloat _fps; int _num_frames; diff --git a/panda/src/egg2pg/characterMaker.cxx b/panda/src/egg2pg/characterMaker.cxx index 0c8bb036509..1494593895c 100644 --- a/panda/src/egg2pg/characterMaker.cxx +++ b/panda/src/egg2pg/characterMaker.cxx @@ -133,7 +133,7 @@ egg_to_index(EggNode *egg_node) const { * the character's top node. */ PandaNode *CharacterMaker:: -part_to_node(PartGroup *part, const string &name) const { +part_to_node(PartGroup *part, std::string_view name) const { PandaNode *node = _character_node; if (part->is_character_joint()) { @@ -156,7 +156,7 @@ part_to_node(PartGroup *part, const string &name) const { return child; } } - PT(GeomNode) geom_node = new GeomNode(name); + PT(GeomNode) geom_node = new GeomNode(std::string(name)); node->add_child(geom_node); return geom_node; } @@ -166,11 +166,11 @@ part_to_node(PartGroup *part, const string &name) const { * Creates a new morph slider of the given name, and returns its index. */ int CharacterMaker:: -create_slider(const string &name) { +create_slider(std::string name) { if (_morph_root == nullptr) { _morph_root = new PartGroup(_bundle, "morph"); } - CharacterSlider *slider = new CharacterSlider(_morph_root, name); + CharacterSlider *slider = new CharacterSlider(_morph_root, std::move(name)); int index = _parts.size(); _parts.push_back(slider); return index; @@ -180,16 +180,17 @@ create_slider(const string &name) { * Returns the VertexSlider corresponding to the indicated egg slider name. */ VertexSlider *CharacterMaker:: -egg_to_slider(const string &name) { +egg_to_slider(std::string_view name) { VertexSliders::iterator vi = _vertex_sliders.find(name); if (vi != _vertex_sliders.end()) { return (*vi).second; } - int index = create_slider(name); + std::string name_str(name); + int index = create_slider(name_str); PT(VertexSlider) slider = new CharacterVertexSlider(DCAST(CharacterSlider, _parts[index])); - _vertex_sliders[name] = slider; + _vertex_sliders[std::move(name_str)] = slider; return slider; } diff --git a/panda/src/egg2pg/characterMaker.h b/panda/src/egg2pg/characterMaker.h index dbbf8abb821..5a5285b8cea 100644 --- a/panda/src/egg2pg/characterMaker.h +++ b/panda/src/egg2pg/characterMaker.h @@ -51,10 +51,10 @@ class EXPCL_PANDA_EGG2PG CharacterMaker { PartGroup *egg_to_part(EggNode *egg_node) const; VertexTransform *egg_to_transform(EggNode *egg_node); int egg_to_index(EggNode *egg_node) const; - PandaNode *part_to_node(PartGroup *part, const std::string &name) const; + PandaNode *part_to_node(PartGroup *part, std::string_view name) const; - int create_slider(const std::string &name); - VertexSlider *egg_to_slider(const std::string &name); + int create_slider(std::string name); + VertexSlider *egg_to_slider(std::string_view name); private: CharacterJointBundle *make_bundle(); @@ -77,7 +77,7 @@ class EXPCL_PANDA_EGG2PG CharacterMaker { VertexTransforms _vertex_transforms; PT(VertexTransform) _identity_transform; - typedef pmap VertexSliders; + typedef pmap> VertexSliders; VertexSliders _vertex_sliders; EggLoader &_loader; diff --git a/panda/src/egg2pg/eggLoader.cxx b/panda/src/egg2pg/eggLoader.cxx index 2b5a037cabf..7173376e39b 100644 --- a/panda/src/egg2pg/eggLoader.cxx +++ b/panda/src/egg2pg/eggLoader.cxx @@ -982,7 +982,7 @@ load_texture(TextureDef &def, EggTexture *egg_tex) { case EggTexture::TT_unspecified: case EggTexture::TT_1d_texture: options.set_texture_flags(options.get_texture_flags() | LoaderOptions::TF_allow_1d); - // Fall through. + [[fallthrough]]; case EggTexture::TT_2d_texture: if (egg_tex->has_alpha_filename() && wanted_alpha) { @@ -2640,7 +2640,7 @@ make_blend_table(EggVertexPool *vertex_pool, EggNode *primitive_home, void EggLoader:: record_morph(GeomVertexArrayFormat *array_format, CharacterMaker *character_maker, - const string &morph_name, InternalName *column_name, + std::string_view morph_name, InternalName *column_name, int num_components) { PT(InternalName) delta_name = InternalName::get_morph(column_name, morph_name); @@ -3757,7 +3757,7 @@ expand_object_types(EggGroup *egg_group, const pset &expanded, bool EggLoader:: do_expand_object_type(EggGroup *egg_group, const pset &expanded, const pvector &expanded_history, - const string &object_type) { + std::string_view object_type) { // Try to find the egg syntax that the given objecttype is shorthand for. // First, look in the config file. @@ -3851,7 +3851,7 @@ get_combine_mode(const EggTexture *egg_tex, EggTexture::CombineChannel channel) { switch (egg_tex->get_combine_mode(channel)) { case EggTexture::CM_unspecified: - // fall through + [[fallthrough]]; case EggTexture::CM_modulate: return TextureStage::CM_modulate; @@ -3900,7 +3900,7 @@ get_combine_source(const EggTexture *egg_tex, case 2: return TextureStage::CS_constant; } - // Otherwise, fall through + [[fallthrough]]; case EggTexture::CS_texture: return TextureStage::CS_texture; diff --git a/panda/src/egg2pg/eggLoader.h b/panda/src/egg2pg/eggLoader.h index c6437a1674f..dd5e49c4306 100644 --- a/panda/src/egg2pg/eggLoader.h +++ b/panda/src/egg2pg/eggLoader.h @@ -151,7 +151,7 @@ class EXPCL_PANDA_EGG2PG EggLoader { CharacterMaker *character_maker); void record_morph (GeomVertexArrayFormat *array_format, - CharacterMaker *character_maker, const std::string &morph_name, + CharacterMaker *character_maker, std::string_view morph_name, InternalName *column_name, int num_components); void make_primitive(const EggRenderState *render_state, @@ -210,7 +210,7 @@ class EXPCL_PANDA_EGG2PG EggLoader { const pvector &expanded_history); bool do_expand_object_type(EggGroup *egg_group, const pset &expanded, const pvector &expanded_history, - const std::string &object_type); + std::string_view object_type); static TextureStage::CombineMode get_combine_mode(const EggTexture *egg_tex, diff --git a/panda/src/egldisplay/eglGraphicsBuffer.cxx b/panda/src/egldisplay/eglGraphicsBuffer.cxx index b4fd714659a..a0bbf953c1c 100644 --- a/panda/src/egldisplay/eglGraphicsBuffer.cxx +++ b/panda/src/egldisplay/eglGraphicsBuffer.cxx @@ -26,13 +26,13 @@ TypeHandle eglGraphicsBuffer::_type_handle; */ eglGraphicsBuffer:: eglGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + GraphicsBuffer(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { eglGraphicsPipe *egl_pipe; DCAST_INTO_V(egl_pipe, _pipe); diff --git a/panda/src/egldisplay/eglGraphicsBuffer.h b/panda/src/egldisplay/eglGraphicsBuffer.h index 60be353e47d..31c9857a0f4 100644 --- a/panda/src/egldisplay/eglGraphicsBuffer.h +++ b/panda/src/egldisplay/eglGraphicsBuffer.h @@ -25,7 +25,7 @@ class eglGraphicsBuffer : public GraphicsBuffer { public: eglGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/egldisplay/eglGraphicsPipe.cxx b/panda/src/egldisplay/eglGraphicsPipe.cxx index cd3c836cd0d..3cae5373706 100644 --- a/panda/src/egldisplay/eglGraphicsPipe.cxx +++ b/panda/src/egldisplay/eglGraphicsPipe.cxx @@ -236,7 +236,7 @@ release_current_context() { * Creates a new window on the pipe, if possible. */ PT(GraphicsOutput) eglGraphicsPipe:: -make_output(const std::string &name, +make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -282,7 +282,7 @@ make_output(const std::string &name, ((flags&BF_can_bind_every)!=0)) { return nullptr; } - return new eglGraphicsWindow(engine, this, name, fb_prop, win_prop, + return new eglGraphicsWindow(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); #else return nullptr; @@ -320,13 +320,13 @@ make_output(const std::string &name, precertify = true; } #ifdef OPENGLES_2 - return new GLES2GraphicsBuffer(engine, this, name, fb_prop, win_prop, + return new GLES2GraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); #elif defined(OPENGLES_1) - return new GLESGraphicsBuffer(engine, this, name, fb_prop, win_prop, + return new GLESGraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); #else - return new GLGraphicsBuffer(engine, this, name, fb_prop, win_prop, + return new GLGraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); #endif } @@ -348,7 +348,7 @@ make_output(const std::string &name, } } - return new eglGraphicsBuffer(engine, this, name, fb_prop, win_prop, + return new eglGraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } @@ -370,7 +370,7 @@ make_output(const std::string &name, return nullptr; } - return new eglGraphicsPixmap(engine, this, name, fb_prop, win_prop, + return new eglGraphicsPixmap(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); #else return nullptr; diff --git a/panda/src/egldisplay/eglGraphicsPipe.h b/panda/src/egldisplay/eglGraphicsPipe.h index 5e8b3ee2fbf..ce25c970bdc 100644 --- a/panda/src/egldisplay/eglGraphicsPipe.h +++ b/panda/src/egldisplay/eglGraphicsPipe.h @@ -67,7 +67,7 @@ class eglGraphicsPipe : public BaseGraphicsPipe { INLINE EGLDisplay get_egl_display() const; protected: - virtual PT(GraphicsOutput) make_output(const std::string &name, + virtual PT(GraphicsOutput) make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/egldisplay/eglGraphicsPixmap.cxx b/panda/src/egldisplay/eglGraphicsPixmap.cxx index 64630e43de0..9e7809ca90c 100644 --- a/panda/src/egldisplay/eglGraphicsPixmap.cxx +++ b/panda/src/egldisplay/eglGraphicsPixmap.cxx @@ -30,13 +30,13 @@ TypeHandle eglGraphicsPixmap::_type_handle; */ eglGraphicsPixmap:: eglGraphicsPixmap(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + GraphicsBuffer(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { eglGraphicsPipe *egl_pipe; DCAST_INTO_V(egl_pipe, _pipe); diff --git a/panda/src/egldisplay/eglGraphicsPixmap.h b/panda/src/egldisplay/eglGraphicsPixmap.h index cddb3430d32..65d854afdce 100644 --- a/panda/src/egldisplay/eglGraphicsPixmap.h +++ b/panda/src/egldisplay/eglGraphicsPixmap.h @@ -29,7 +29,7 @@ class eglGraphicsPixmap : public GraphicsBuffer { public: eglGraphicsPixmap(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/egldisplay/eglGraphicsWindow.cxx b/panda/src/egldisplay/eglGraphicsWindow.cxx index 65d8812de9c..f9db53be525 100644 --- a/panda/src/egldisplay/eglGraphicsWindow.cxx +++ b/panda/src/egldisplay/eglGraphicsWindow.cxx @@ -45,13 +45,13 @@ TypeHandle eglGraphicsWindow::_type_handle; */ eglGraphicsWindow:: eglGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - x11GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + x11GraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { eglGraphicsPipe *egl_pipe; DCAST_INTO_V(egl_pipe, _pipe); diff --git a/panda/src/egldisplay/eglGraphicsWindow.h b/panda/src/egldisplay/eglGraphicsWindow.h index 1a5efad7fd4..bfd21fb525d 100644 --- a/panda/src/egldisplay/eglGraphicsWindow.h +++ b/panda/src/egldisplay/eglGraphicsWindow.h @@ -27,7 +27,7 @@ class eglGraphicsWindow : public x11GraphicsWindow { public: eglGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/event/asyncFuture.I b/panda/src/event/asyncFuture.I index 201e103c3e1..5848b4f9526 100644 --- a/panda/src/event/asyncFuture.I +++ b/panda/src/event/asyncFuture.I @@ -46,9 +46,9 @@ cancelled() const { * a coroutine task that exits with an exception. */ INLINE void AsyncFuture:: -set_done_event(const std::string &done_event) { +set_done_event(std::string done_event) { nassertv(!done()); - _done_event = done_event; + _done_event = std::move(done_event); } /** diff --git a/panda/src/event/asyncFuture.h b/panda/src/event/asyncFuture.h index f9f71472f8d..6017df8187a 100644 --- a/panda/src/event/asyncFuture.h +++ b/panda/src/event/asyncFuture.h @@ -73,7 +73,7 @@ class EXPCL_PANDA_EVENT AsyncFuture : public TypedReferenceCount, protected Comp virtual bool cancel(); - INLINE void set_done_event(const std::string &done_event); + INLINE void set_done_event(std::string done_event); INLINE const std::string &get_done_event() const; MAKE_PROPERTY(done_event, get_done_event, set_done_event); diff --git a/panda/src/event/asyncTask.I b/panda/src/event/asyncTask.I index 68f69b862d4..3203b3e9ff0 100644 --- a/panda/src/event/asyncTask.I +++ b/panda/src/event/asyncTask.I @@ -176,9 +176,9 @@ get_priority() const { * returns S_inactive). */ INLINE void AsyncTask:: -set_done_event(const std::string &done_event) { +set_done_event(std::string done_event) { nassertv(_state == S_inactive); - _done_event = done_event; + _done_event = std::move(done_event); } /** diff --git a/panda/src/event/asyncTask.cxx b/panda/src/event/asyncTask.cxx index 371cb34abd8..30b9343e6b4 100644 --- a/panda/src/event/asyncTask.cxx +++ b/panda/src/event/asyncTask.cxx @@ -28,7 +28,7 @@ TypeHandle AsyncTask::_type_handle; * */ AsyncTask:: -AsyncTask(const string &name) : +AsyncTask(std::string name) : _chain_name("default"), _delay(0.0), _has_delay(false), @@ -45,7 +45,7 @@ AsyncTask(const string &name) : _total_dt(0.0), _num_frames(0) { - set_name(name); + set_name(std::move(name)); // Atomically increment _next_task_id so that we get a unique ID. _task_id = _next_task_id.fetch_add(1, std::memory_order_relaxed); @@ -165,7 +165,7 @@ get_elapsed_frames() const { * */ void AsyncTask:: -set_name(const string &name) { +set_name(std::string name) { if (_manager != nullptr) { MutexHolder holder(_manager->_lock); if (Namable::get_name() != name) { @@ -173,45 +173,48 @@ set_name(const string &name) { // index. _manager->remove_task_by_name(this); - Namable::set_name(name); + Namable::set_name(std::move(name)); _manager->add_task_by_name(this); } } else { // If it hasn't been started anywhere, we can just change the name. - Namable::set_name(name); + Namable::set_name(std::move(name)); } #ifdef DO_PSTATS // Update the PStatCollector with the new name. If the name includes a // colon, we stop the collector name there, and don't go further. - size_t end = name.size(); - size_t colon = name.find(':'); - if (colon != string::npos) { - end = std::min(end, colon); - } - - // If the name ends with a hyphen followed by a string of digits, we strip - // all that off, for the parent collector, to group related tasks together - // in the pstats graph. We still create a child collector that contains the - // full name, however. - size_t trimmed = end; - size_t p = trimmed; - while (true) { - while (p > 0 && isdigit(name[p - 1])) { - --p; + { + const std::string &name = get_name(); + size_t end = name.size(); + size_t colon = name.find(':'); + if (colon != string::npos) { + end = std::min(end, colon); } - if (p > 0 && (name[p - 1] == '-' || name[p - 1] == '_')) { - --p; - trimmed = p; - } else { - //p = trimmed; - break; + + // If the name ends with a hyphen followed by a string of digits, we strip + // all that off, for the parent collector, to group related tasks together + // in the pstats graph. We still create a child collector that contains the + // full name, however. + size_t trimmed = end; + size_t p = trimmed; + while (true) { + while (p > 0 && isdigit(name[p - 1])) { + --p; + } + if (p > 0 && (name[p - 1] == '-' || name[p - 1] == '_')) { + --p; + trimmed = p; + } else { + //p = trimmed; + break; + } } + PStatCollector parent(_tasks_pcollector, name.substr(0, trimmed)); + // prevent memory leak _task_pcollector = PStatCollector(parent, + // name.substr(0, end)); + _task_pcollector = parent; } - PStatCollector parent(_tasks_pcollector, name.substr(0, trimmed)); - // prevent memory leak _task_pcollector = PStatCollector(parent, - // name.substr(0, end)); - _task_pcollector = parent; #endif // DO_PSTATS } @@ -245,7 +248,7 @@ get_name_prefix() const { * chain runs tasks independently of the others. */ void AsyncTask:: -set_task_chain(const string &chain_name) { +set_task_chain(std::string_view chain_name) { if (chain_name != _chain_name) { if (_manager != nullptr) { MutexHolder holder(_manager->_lock); diff --git a/panda/src/event/asyncTask.h b/panda/src/event/asyncTask.h index 2bc29d2412c..b07976adc24 100644 --- a/panda/src/event/asyncTask.h +++ b/panda/src/event/asyncTask.h @@ -31,7 +31,7 @@ class AsyncTaskChain; */ class EXPCL_PANDA_EVENT AsyncTask : public AsyncFuture, public Namable { public: - AsyncTask(const std::string &name = std::string()); + AsyncTask(std::string name = ""); ALLOC_DELETED_CHAIN(AsyncTask); PUBLISHED: @@ -76,13 +76,13 @@ class EXPCL_PANDA_EVENT AsyncTask : public AsyncFuture, public Namable { INLINE int get_start_frame() const; int get_elapsed_frames() const; - void set_name(const std::string &name); + void set_name(std::string name); INLINE void clear_name(); std::string get_name_prefix() const; INLINE int get_task_id() const; - void set_task_chain(const std::string &chain_name); + void set_task_chain(std::string_view chain_name); INLINE const std::string &get_task_chain() const; void set_sort(int sort); @@ -91,7 +91,7 @@ class EXPCL_PANDA_EVENT AsyncTask : public AsyncFuture, public Namable { void set_priority(int priority); INLINE int get_priority() const; - INLINE void set_done_event(const std::string &done_event); + INLINE void set_done_event(std::string done_event); INLINE double get_dt() const; INLINE double get_max_dt() const; diff --git a/panda/src/event/asyncTaskChain.I b/panda/src/event/asyncTaskChain.I index bd727098176..130e7de23d2 100644 --- a/panda/src/event/asyncTaskChain.I +++ b/panda/src/event/asyncTaskChain.I @@ -36,11 +36,11 @@ is_started() const { */ template INLINE AsyncTask *AsyncTaskChain:: -add(Callable callable, const std::string &name, int sort, int priority) { +add(Callable callable, std::string name, int sort, int priority) { class InlineTask final : public AsyncTask { public: - InlineTask(Callable callable, const std::string &name, int sort, int priority) : - AsyncTask(name), + InlineTask(Callable callable, std::string name, int sort, int priority) : + AsyncTask(std::move(name)), _callable(std::move(callable)) { _sort = sort; _priority = priority; @@ -55,7 +55,7 @@ add(Callable callable, const std::string &name, int sort, int priority) { Callable _callable; }; - AsyncTask *task = new InlineTask(std::move(callable), name, sort, priority); + AsyncTask *task = new InlineTask(std::move(callable), std::move(name), sort, priority); add(task); return task; } diff --git a/panda/src/event/asyncTaskChain.cxx b/panda/src/event/asyncTaskChain.cxx index 9ab2093fa39..9f261e2b064 100644 --- a/panda/src/event/asyncTaskChain.cxx +++ b/panda/src/event/asyncTaskChain.cxx @@ -37,9 +37,9 @@ PStatCollector AsyncTaskChain::_wait_pcollector("Wait"); * */ AsyncTaskChain:: -AsyncTaskChain(AsyncTaskManager *manager, const string &name, int num_threads, +AsyncTaskChain(AsyncTaskManager *manager, std::string name, int num_threads, ThreadPriority thread_priority) : - Namable(name), + Namable(std::move(name)), _manager(manager), _cvar(manager->_lock), _tick_clock(false), @@ -1425,8 +1425,8 @@ write_task_line(ostream &out, int indent_level, AsyncTask *task, double now) con * */ AsyncTaskChain::AsyncTaskChainThread:: -AsyncTaskChainThread(const string &name, AsyncTaskChain *chain) : - Thread(name, chain->get_name()), +AsyncTaskChainThread(std::string name, AsyncTaskChain *chain) : + Thread(std::move(name), chain->get_name()), _chain(chain), _servicing(nullptr) { diff --git a/panda/src/event/asyncTaskChain.h b/panda/src/event/asyncTaskChain.h index ed54cbf42cc..e2e72ae46fb 100644 --- a/panda/src/event/asyncTaskChain.h +++ b/panda/src/event/asyncTaskChain.h @@ -49,7 +49,7 @@ class AsyncTaskManager; */ class EXPCL_PANDA_EVENT AsyncTaskChain : public TypedReferenceCount, public Namable { public: - AsyncTaskChain(AsyncTaskManager *manager, const std::string &name, + AsyncTaskChain(AsyncTaskManager *manager, std::string name, int num_threads=0, ThreadPriority thread_priority=TP_normal); ~AsyncTaskChain(); @@ -80,7 +80,7 @@ class EXPCL_PANDA_EVENT AsyncTaskChain : public TypedReferenceCount, public Nama void add(AsyncTask *task); #ifndef CPPPARSER template - INLINE AsyncTask *add(Callable callable, const std::string &name, + INLINE AsyncTask *add(Callable callable, std::string name, int sort = 0, int priority = 0); #endif bool has_task(AsyncTask *task) const; @@ -130,7 +130,7 @@ class EXPCL_PANDA_EVENT AsyncTaskChain : public TypedReferenceCount, public Nama protected: class AsyncTaskChainThread : public Thread { public: - AsyncTaskChainThread(const std::string &name, AsyncTaskChain *chain); + AsyncTaskChainThread(std::string name, AsyncTaskChain *chain); virtual void thread_main(); AsyncTaskChain *_chain; diff --git a/panda/src/event/asyncTaskCollection.cxx b/panda/src/event/asyncTaskCollection.cxx index b6fd56fecee..c16991c267d 100644 --- a/panda/src/event/asyncTaskCollection.cxx +++ b/panda/src/event/asyncTaskCollection.cxx @@ -174,7 +174,7 @@ clear() { * if no task has that name. */ AsyncTask *AsyncTaskCollection:: -find_task(const std::string &name) const { +find_task(std::string_view name) const { size_t num_tasks = get_num_tasks(); for (size_t i = 0; i < num_tasks; ++i) { AsyncTask *task = get_task(i); diff --git a/panda/src/event/asyncTaskCollection.h b/panda/src/event/asyncTaskCollection.h index a2334df839f..4d71f93634d 100644 --- a/panda/src/event/asyncTaskCollection.h +++ b/panda/src/event/asyncTaskCollection.h @@ -39,7 +39,7 @@ class EXPCL_PANDA_EVENT AsyncTaskCollection { bool has_task(AsyncTask *task) const; void clear(); - AsyncTask *find_task(const std::string &name) const; + AsyncTask *find_task(std::string_view name) const; size_t get_num_tasks() const; AsyncTask *get_task(size_t index) const; diff --git a/panda/src/event/asyncTaskManager.I b/panda/src/event/asyncTaskManager.I index 5c413bb70cb..a82cf9d050d 100644 --- a/panda/src/event/asyncTaskManager.I +++ b/panda/src/event/asyncTaskManager.I @@ -47,10 +47,10 @@ get_clock() { */ template INLINE AsyncTask *AsyncTaskManager:: -add(Callable callable, const std::string &name, int sort, int priority) { +add(Callable callable, std::string name, int sort, int priority) { AsyncTaskChain *chain = make_task_chain("default"); nassertr(chain != nullptr, nullptr); - return chain->add(std::move(callable), name, sort, priority); + return chain->add(std::move(callable), std::move(name), sort, priority); } #endif diff --git a/panda/src/event/asyncTaskManager.cxx b/panda/src/event/asyncTaskManager.cxx index d02adf05011..3f5cb2abc68 100644 --- a/panda/src/event/asyncTaskManager.cxx +++ b/panda/src/event/asyncTaskManager.cxx @@ -32,8 +32,8 @@ TypeHandle AsyncTaskManager::_type_handle; * */ AsyncTaskManager:: -AsyncTaskManager(const string &name) : - Namable(name), +AsyncTaskManager(std::string name) : + Namable(std::move(name)), _lock("AsyncTaskManager::_lock"), _num_tasks(0), _clock(ClockObject::get_global_clock()), @@ -126,9 +126,9 @@ get_task_chain(int n) const { * it instead. */ AsyncTaskChain *AsyncTaskManager:: -make_task_chain(const string &name) { +make_task_chain(std::string name) { MutexHolder holder(_lock); - return do_make_task_chain(name); + return do_make_task_chain(std::move(name)); } /** @@ -137,9 +137,9 @@ make_task_chain(const string &name) { * returns it instead. */ AsyncTaskChain *AsyncTaskManager:: -make_task_chain(const string &name, int num_threads, ThreadPriority thread_priority) { +make_task_chain(std::string name, int num_threads, ThreadPriority thread_priority) { MutexHolder holder(_lock); - return do_make_task_chain(name, num_threads, thread_priority); + return do_make_task_chain(std::move(name), num_threads, thread_priority); } /** @@ -147,9 +147,9 @@ make_task_chain(const string &name, int num_threads, ThreadPriority thread_prior * exists, or NULL otherwise. */ AsyncTaskChain *AsyncTaskManager:: -find_task_chain(const string &name) { +find_task_chain(std::string name) { MutexHolder holder(_lock); - return do_find_task_chain(name); + return do_find_task_chain(std::move(name)); } /** @@ -159,10 +159,10 @@ find_task_chain(const string &name) { * Returns true if successful, or false if the chain did not exist. */ bool AsyncTaskManager:: -remove_task_chain(const string &name) { +remove_task_chain(std::string name) { MutexHolder holder(_lock); - PT(AsyncTaskChain) chain = new AsyncTaskChain(this, name); + PT(AsyncTaskChain) chain = new AsyncTaskChain(this, std::move(name)); TaskChains::iterator tci = _task_chains.find(chain); if (tci == _task_chains.end()) { // No chain. @@ -174,7 +174,7 @@ remove_task_chain(const string &name) { while (chain->_num_tasks != 0) { // Still has tasks. task_cat.info() - << "Waiting for tasks on chain " << name << " to finish.\n"; + << "Waiting for tasks on chain " << chain->get_name() << " to finish.\n"; chain->do_wait_for_tasks(); } @@ -261,12 +261,12 @@ has_task(AsyncTask *task) const { * arbitrarily. */ AsyncTask *AsyncTaskManager:: -find_task(const string &name) const { - AsyncTask sample_task(name); +find_task(std::string name) const { + AsyncTask sample_task(std::move(name)); sample_task.local_object(); TasksByName::const_iterator tbni = _tasks_by_name.lower_bound(&sample_task); - if (tbni != _tasks_by_name.end() && (*tbni)->get_name() == name) { + if (tbni != _tasks_by_name.end() && (*tbni)->get_name() == sample_task.get_name()) { return (*tbni); } @@ -277,13 +277,13 @@ find_task(const string &name) const { * Returns the list of tasks found with the indicated name. */ AsyncTaskCollection AsyncTaskManager:: -find_tasks(const string &name) const { - AsyncTask sample_task(name); +find_tasks(std::string name) const { + AsyncTask sample_task(std::move(name)); sample_task.local_object(); TasksByName::const_iterator tbni = _tasks_by_name.lower_bound(&sample_task); AsyncTaskCollection result; - while (tbni != _tasks_by_name.end() && (*tbni)->get_name() == name) { + while (tbni != _tasks_by_name.end() && (*tbni)->get_name() == sample_task.get_name()) { result.add_task(*tbni); ++tbni; } @@ -573,8 +573,8 @@ write(std::ostream &out, int indent_level) const { * Assumes the lock is held. */ AsyncTaskChain *AsyncTaskManager:: -do_make_task_chain(const string &name, int num_threads, ThreadPriority thread_priority) { - PT(AsyncTaskChain) chain = new AsyncTaskChain(this, name, num_threads, thread_priority); +do_make_task_chain(std::string name, int num_threads, ThreadPriority thread_priority) { + PT(AsyncTaskChain) chain = new AsyncTaskChain(this, std::move(name), num_threads, thread_priority); TaskChains::const_iterator tci = _task_chains.insert(chain).first; return (*tci); @@ -587,8 +587,8 @@ do_make_task_chain(const string &name, int num_threads, ThreadPriority thread_pr * Assumes the lock is held. */ AsyncTaskChain *AsyncTaskManager:: -do_find_task_chain(const string &name) { - PT(AsyncTaskChain) chain = new AsyncTaskChain(this, name); +do_find_task_chain(std::string name) { + PT(AsyncTaskChain) chain = new AsyncTaskChain(this, std::move(name)); TaskChains::const_iterator tci = _task_chains.find(chain); if (tci != _task_chains.end()) { diff --git a/panda/src/event/asyncTaskManager.h b/panda/src/event/asyncTaskManager.h index 62a2590aa51..61b6da6e8d0 100644 --- a/panda/src/event/asyncTaskManager.h +++ b/panda/src/event/asyncTaskManager.h @@ -47,7 +47,7 @@ */ class EXPCL_PANDA_EVENT AsyncTaskManager : public TypedReferenceCount, public Namable { PUBLISHED: - explicit AsyncTaskManager(const std::string &name); + explicit AsyncTaskManager(std::string name); BLOCKING virtual ~AsyncTaskManager(); BLOCKING void cleanup(); @@ -59,22 +59,22 @@ class EXPCL_PANDA_EVENT AsyncTaskManager : public TypedReferenceCount, public Na int get_num_task_chains() const; AsyncTaskChain *get_task_chain(int n) const; MAKE_SEQ(get_task_chains, get_num_task_chains, get_task_chain); - AsyncTaskChain *make_task_chain(const std::string &name); - AsyncTaskChain *make_task_chain(const std::string &name, int num_threads, + AsyncTaskChain *make_task_chain(std::string name); + AsyncTaskChain *make_task_chain(std::string name, int num_threads, ThreadPriority thread_priority); - AsyncTaskChain *find_task_chain(const std::string &name); - BLOCKING bool remove_task_chain(const std::string &name); + AsyncTaskChain *find_task_chain(std::string name); + BLOCKING bool remove_task_chain(std::string name); void add(AsyncTask *task); #ifndef CPPPARSER template - INLINE AsyncTask *add(Callable callable, const std::string &name, + INLINE AsyncTask *add(Callable callable, std::string name, int sort = 0, int priority = 0); #endif bool has_task(AsyncTask *task) const; - AsyncTask *find_task(const std::string &name) const; - AsyncTaskCollection find_tasks(const std::string &name) const; + AsyncTask *find_task(std::string name) const; + AsyncTaskCollection find_tasks(std::string name) const; AsyncTaskCollection find_tasks_matching(const GlobPattern &pattern) const; bool remove(AsyncTask *task); @@ -103,9 +103,9 @@ class EXPCL_PANDA_EVENT AsyncTaskManager : public TypedReferenceCount, public Na INLINE static AsyncTaskManager *get_global_ptr(); protected: - AsyncTaskChain *do_make_task_chain(const std::string &name, int num_threads=0, + AsyncTaskChain *do_make_task_chain(std::string name, int num_threads=0, ThreadPriority thread_priority=TP_normal); - AsyncTaskChain *do_find_task_chain(const std::string &name); + AsyncTaskChain *do_find_task_chain(std::string name); INLINE void add_task_by_name(AsyncTask *task); void remove_task_by_name(AsyncTask *task); diff --git a/panda/src/event/asyncTaskSequence.cxx b/panda/src/event/asyncTaskSequence.cxx index 82541ec8da5..0c2ba3ad264 100644 --- a/panda/src/event/asyncTaskSequence.cxx +++ b/panda/src/event/asyncTaskSequence.cxx @@ -20,8 +20,8 @@ TypeHandle AsyncTaskSequence::_type_handle; * */ AsyncTaskSequence:: -AsyncTaskSequence(const std::string &name) : - AsyncTask(name), +AsyncTaskSequence(std::string name) : + AsyncTask(std::move(name)), _repeat_count(0), _task_index(0) { diff --git a/panda/src/event/asyncTaskSequence.h b/panda/src/event/asyncTaskSequence.h index 096d1f6b88c..33da060af6f 100644 --- a/panda/src/event/asyncTaskSequence.h +++ b/panda/src/event/asyncTaskSequence.h @@ -32,7 +32,7 @@ class AsyncTaskManager; */ class EXPCL_PANDA_EVENT AsyncTaskSequence : public AsyncTask, public AsyncTaskCollection { PUBLISHED: - explicit AsyncTaskSequence(const std::string &name); + explicit AsyncTaskSequence(std::string name); virtual ~AsyncTaskSequence(); ALLOC_DELETED_CHAIN(AsyncTaskSequence); diff --git a/panda/src/event/buttonEvent.I b/panda/src/event/buttonEvent.I index 959f66dc477..4f52d855b41 100644 --- a/panda/src/event/buttonEvent.I +++ b/panda/src/event/buttonEvent.I @@ -55,11 +55,11 @@ ButtonEvent(int keycode, double time) : * */ INLINE ButtonEvent:: -ButtonEvent(const std::wstring &candidate_string, size_t highlight_start, +ButtonEvent(std::wstring candidate_string, size_t highlight_start, size_t highlight_end, size_t cursor_pos) : _button(ButtonHandle::none()), _keycode(0), - _candidate_string(candidate_string), + _candidate_string(std::move(candidate_string)), _highlight_start(highlight_start), _highlight_end(highlight_end), _cursor_pos(cursor_pos), diff --git a/panda/src/event/buttonEvent.h b/panda/src/event/buttonEvent.h index d80eabf7017..b8adccec6e3 100644 --- a/panda/src/event/buttonEvent.h +++ b/panda/src/event/buttonEvent.h @@ -92,7 +92,7 @@ class EXPCL_PANDA_EVENT ButtonEvent { INLINE ButtonEvent(); INLINE ButtonEvent(ButtonHandle button, Type type, double time = ClockObject::get_global_clock()->get_frame_time()); INLINE ButtonEvent(int keycode, double time = ClockObject::get_global_clock()->get_frame_time()); - INLINE ButtonEvent(const std::wstring &candidate_string, size_t highlight_start, + INLINE ButtonEvent(std::wstring candidate_string, size_t highlight_start, size_t highlight_end, size_t cursor_pos); INLINE ButtonEvent(const ButtonEvent ©); INLINE void operator = (const ButtonEvent ©); diff --git a/panda/src/event/event.I b/panda/src/event/event.I index fd60e3e10f5..de91f41bcbe 100644 --- a/panda/src/event/event.I +++ b/panda/src/event/event.I @@ -15,8 +15,8 @@ * */ INLINE void Event:: -set_name(const std::string &name) { - _name = name; +set_name(std::string name) { + _name = std::move(name); } /** diff --git a/panda/src/event/event.cxx b/panda/src/event/event.cxx index 8a46d2586f8..06e57374d7e 100644 --- a/panda/src/event/event.cxx +++ b/panda/src/event/event.cxx @@ -20,8 +20,8 @@ TypeHandle Event::_type_handle; * */ Event:: -Event(const std::string &event_name, EventReceiver *receiver) : - _name(event_name) +Event(std::string event_name, EventReceiver *receiver) : + _name(std::move(event_name)) { _receiver = receiver; } diff --git a/panda/src/event/event.h b/panda/src/event/event.h index 19550165dc3..90a736e2f43 100644 --- a/panda/src/event/event.h +++ b/panda/src/event/event.h @@ -33,12 +33,12 @@ class EventReceiver; */ class EXPCL_PANDA_EVENT Event : public TypedReferenceCount { PUBLISHED: - Event(const std::string &event_name, EventReceiver *receiver = nullptr); + Event(std::string event_name, EventReceiver *receiver = nullptr); Event(const Event ©); void operator = (const Event ©); ~Event(); - INLINE void set_name(const std::string &name); + INLINE void set_name(std::string name); INLINE void clear_name(); INLINE bool has_name() const; INLINE const std::string &get_name() const; diff --git a/panda/src/event/eventHandler.cxx b/panda/src/event/eventHandler.cxx index 2adb7b1e6c7..f66e5d0e558 100644 --- a/panda/src/event/eventHandler.cxx +++ b/panda/src/event/eventHandler.cxx @@ -34,7 +34,7 @@ EventHandler(EventQueue *ev_queue) : _queue(*ev_queue) { * fired. */ AsyncFuture *EventHandler:: -get_future(const string &event_name) { +get_future(std::string_view event_name) { Futures::iterator fi; fi = _futures.find(event_name); @@ -44,7 +44,7 @@ get_future(const string &event_name) { return fi->second; } else { AsyncFuture *fut = new AsyncFuture; - _futures[event_name] = fut; + _futures[std::string(event_name)] = fut; return fut; } } @@ -177,7 +177,7 @@ write(std::ostream &out) const { * added, false if it was already defined on the indicated event name. */ bool EventHandler:: -add_hook(const string &event_name, EventFunction *function) { +add_hook(std::string_view event_name, EventFunction *function) { if (event_cat.is_debug()) { event_cat.debug() << "adding hook for event '" << event_name @@ -185,7 +185,7 @@ add_hook(const string &event_name, EventFunction *function) { } assert(!event_name.empty()); assert(function); - return _hooks[event_name].insert(function).second; + return _hooks[std::string(event_name)].insert(function).second; } @@ -196,11 +196,11 @@ add_hook(const string &event_name, EventFunction *function) { * version records an untyped pointer to user callback data. */ bool EventHandler:: -add_hook(const string &event_name, EventCallbackFunction *function, +add_hook(std::string_view event_name, EventCallbackFunction *function, void *data) { assert(!event_name.empty()); assert(function); - return _cbhooks[event_name].insert(CallbackFunction(function, data)).second; + return _cbhooks[std::string(event_name)].insert(CallbackFunction(function, data)).second; } /** @@ -210,10 +210,10 @@ add_hook(const string &event_name, EventCallbackFunction *function, * version stores an arbitrary C++ lambda. */ void EventHandler:: -add_hook(const string &event_name, EventLambda function) { +add_hook(std::string_view event_name, EventLambda function) { assert(!event_name.empty()); assert(function); - _lambdahooks[event_name].push_back(function); + _lambdahooks[std::string(event_name)].push_back(function); } /** @@ -221,7 +221,7 @@ add_hook(const string &event_name, EventLambda function) { * otherwise. */ bool EventHandler:: -has_hook(const string &event_name) const { +has_hook(std::string_view event_name) const { assert(!event_name.empty()); Hooks::const_iterator hi; hi = _hooks.find(event_name); @@ -256,7 +256,7 @@ has_hook(const string &event_name) const { * function pointer, false otherwise. */ bool EventHandler:: -has_hook(const string &event_name, EventFunction *function) const { +has_hook(std::string_view event_name, EventFunction *function) const { assert(!event_name.empty()); Hooks::const_iterator hi; hi = _hooks.find(event_name); @@ -276,7 +276,7 @@ has_hook(const string &event_name, EventFunction *function) const { * function pointer and callback data, false otherwise. */ bool EventHandler:: -has_hook(const string &event_name, EventCallbackFunction *function, void *data) const { +has_hook(std::string_view event_name, EventCallbackFunction *function, void *data) const { assert(!event_name.empty()); CallbackHooks::const_iterator chi; chi = _cbhooks.find(event_name); @@ -296,10 +296,10 @@ has_hook(const string &event_name, EventCallbackFunction *function, void *data) * the hook was removed, false if it wasn't there in the first place. */ bool EventHandler:: -remove_hook(const string &event_name, EventFunction *function) { +remove_hook(std::string_view event_name, EventFunction *function) { assert(!event_name.empty()); assert(function); - return _hooks[event_name].erase(function) != 0; + return _hooks[std::string(event_name)].erase(function) != 0; } @@ -309,11 +309,11 @@ remove_hook(const string &event_name, EventFunction *function) { * version takes an untyped pointer to user callback data. */ bool EventHandler:: -remove_hook(const string &event_name, EventCallbackFunction *function, +remove_hook(std::string_view event_name, EventCallbackFunction *function, void *data) { assert(!event_name.empty()); assert(function); - return _cbhooks[event_name].erase(CallbackFunction(function, data)) != 0; + return _cbhooks[std::string(event_name)].erase(CallbackFunction(function, data)) != 0; } /** @@ -321,7 +321,7 @@ remove_hook(const string &event_name, EventCallbackFunction *function, * functions were removed, false if there were no functions added to the hook. */ bool EventHandler:: -remove_hooks(const string &event_name) { +remove_hooks(std::string_view event_name) { assert(!event_name.empty()); bool any_removed = false; diff --git a/panda/src/event/eventHandler.h b/panda/src/event/eventHandler.h index 481f7efbb41..31a3cd7084d 100644 --- a/panda/src/event/eventHandler.h +++ b/panda/src/event/eventHandler.h @@ -55,7 +55,7 @@ class EXPCL_PANDA_EVENT EventHandler : public TypedObject { explicit EventHandler(EventQueue *ev_queue); ~EventHandler() {} - AsyncFuture *get_future(const std::string &event_name); + AsyncFuture *get_future(std::string_view event_name); void process_events(); @@ -66,19 +66,19 @@ class EXPCL_PANDA_EVENT EventHandler : public TypedObject { INLINE static EventHandler *get_global_event_handler(EventQueue *queue = nullptr); public: - bool add_hook(const std::string &event_name, EventFunction *function); - bool add_hook(const std::string &event_name, EventCallbackFunction *function, + bool add_hook(std::string_view event_name, EventFunction *function); + bool add_hook(std::string_view event_name, EventCallbackFunction *function, void *data); - void add_hook(const std::string &event_name, EventLambda function); - bool has_hook(const std::string &event_name) const; - bool has_hook(const std::string &event_name, EventFunction *function) const; - bool has_hook(const std::string &event_name, EventCallbackFunction *function, + void add_hook(std::string_view event_name, EventLambda function); + bool has_hook(std::string_view event_name) const; + bool has_hook(std::string_view event_name, EventFunction *function) const; + bool has_hook(std::string_view event_name, EventCallbackFunction *function, void *data) const; - bool remove_hook(const std::string &event_name, EventFunction *function); - bool remove_hook(const std::string &event_name, EventCallbackFunction *function, + bool remove_hook(std::string_view event_name, EventFunction *function); + bool remove_hook(std::string_view event_name, EventCallbackFunction *function, void *data); - bool remove_hooks(const std::string &event_name); + bool remove_hooks(std::string_view event_name); bool remove_hooks_with(void *data); void remove_all_hooks(); @@ -86,13 +86,13 @@ class EXPCL_PANDA_EVENT EventHandler : public TypedObject { protected: typedef pset Functions; - typedef pmap Hooks; + typedef pmap> Hooks; typedef std::pair CallbackFunction; typedef pset CallbackFunctions; - typedef pmap CallbackHooks; + typedef pmap> CallbackHooks; typedef pvector LambdaFunctions; - typedef pmap LambdaHooks; - typedef pmap Futures; + typedef pmap> LambdaHooks; + typedef pmap> Futures; Hooks _hooks; CallbackHooks _cbhooks; diff --git a/panda/src/event/eventParameter.I b/panda/src/event/eventParameter.I index 61cbacb0b8e..48db810065b 100644 --- a/panda/src/event/eventParameter.I +++ b/panda/src/event/eventParameter.I @@ -55,13 +55,13 @@ EventParameter(double value) : _ptr(new EventStoreDouble(value)) { } * Defines an EventParameter that stores a string value. */ INLINE EventParameter:: -EventParameter(const std::string &value) : _ptr(new EventStoreString(value)) { } +EventParameter(std::string value) : _ptr(new EventStoreString(std::move(value))) { } /** * Defines an EventParameter that stores a wstring value. */ INLINE EventParameter:: -EventParameter(const std::wstring &value) : _ptr(new EventStoreWstring(value)) { } +EventParameter(std::wstring value) : _ptr(new EventStoreWstring(std::move(value))) { } /** * Defines an EventParameter that stores a bytes value. diff --git a/panda/src/event/eventParameter.h b/panda/src/event/eventParameter.h index 7994796b753..c201b636476 100644 --- a/panda/src/event/eventParameter.h +++ b/panda/src/event/eventParameter.h @@ -39,8 +39,8 @@ class EXPCL_PANDA_EVENT EventParameter { INLINE EventParameter(const TypedReferenceCount *ptr); INLINE EventParameter(int value); INLINE EventParameter(double value); - INLINE EventParameter(const std::string &value); - INLINE EventParameter(const std::wstring &value); + INLINE EventParameter(std::string value); + INLINE EventParameter(std::wstring value); INLINE EventParameter(const vector_uchar &value); INLINE EventParameter(const EventParameter ©); diff --git a/panda/src/event/genericAsyncTask.cxx b/panda/src/event/genericAsyncTask.cxx index f78fddecc30..e6bdf32deb5 100644 --- a/panda/src/event/genericAsyncTask.cxx +++ b/panda/src/event/genericAsyncTask.cxx @@ -20,8 +20,8 @@ TypeHandle GenericAsyncTask::_type_handle; * */ GenericAsyncTask:: -GenericAsyncTask(const std::string &name) : - AsyncTask(name) +GenericAsyncTask(std::string name) : + AsyncTask(std::move(name)) { _function = nullptr; _upon_birth = nullptr; @@ -33,8 +33,8 @@ GenericAsyncTask(const std::string &name) : * */ GenericAsyncTask:: -GenericAsyncTask(const std::string &name, GenericAsyncTask::TaskFunc *function, void *user_data) : - AsyncTask(name), +GenericAsyncTask(std::string name, GenericAsyncTask::TaskFunc *function, void *user_data) : + AsyncTask(std::move(name)), _function(function), _user_data(user_data) { diff --git a/panda/src/event/genericAsyncTask.h b/panda/src/event/genericAsyncTask.h index f35d780e3b6..060de375c99 100644 --- a/panda/src/event/genericAsyncTask.h +++ b/panda/src/event/genericAsyncTask.h @@ -29,8 +29,8 @@ class EXPCL_PANDA_EVENT GenericAsyncTask : public AsyncTask { typedef void BirthFunc(GenericAsyncTask *task, void *user_data); typedef void DeathFunc(GenericAsyncTask *task, bool clean_exit, void *user_data); - GenericAsyncTask(const std::string &name = std::string()); - GenericAsyncTask(const std::string &name, TaskFunc *function, void *user_data); + GenericAsyncTask(std::string name = std::string()); + GenericAsyncTask(std::string name, TaskFunc *function, void *user_data); ALLOC_DELETED_CHAIN(GenericAsyncTask); INLINE void set_function(TaskFunc *function); diff --git a/panda/src/event/pointerEventList.cxx b/panda/src/event/pointerEventList.cxx index ea160ea9b92..7b69fc76625 100644 --- a/panda/src/event/pointerEventList.cxx +++ b/panda/src/event/pointerEventList.cxx @@ -237,7 +237,7 @@ total_turns(double sec) const { * to be in order to be considered significant. */ double PointerEventList:: -match_pattern(const std::string &ascpat, double rot, double seglen) { +match_pattern(std::string_view ascpat, double rot, double seglen) { // Convert the pattern from ascii to a more usable form. vector_double pattern; parse_pattern(ascpat, pattern); @@ -254,7 +254,7 @@ match_pattern(const std::string &ascpat, double rot, double seglen) { * Parses a pattern as used by match_pattern. */ void PointerEventList:: -parse_pattern(const std::string &ascpat, vector_double &pattern) { +parse_pattern(std::string_view ascpat, vector_double &pattern) { int chars = 0; double dir = 180.0; for (size_t i=0; i Events; Events _events; diff --git a/panda/src/event/pythonTask.cxx b/panda/src/event/pythonTask.cxx index 264442d27e6..6fae536547c 100644 --- a/panda/src/event/pythonTask.cxx +++ b/panda/src/event/pythonTask.cxx @@ -34,8 +34,8 @@ extern struct Dtool_PyTypedObject Dtool_PythonTask; * */ PythonTask:: -PythonTask(PyObject *func_or_coro, const std::string &name) : - AsyncTask(name), +PythonTask(PyObject *func_or_coro, std::string name) : + AsyncTask(std::move(name)), _function(nullptr), _upon_death(nullptr), _owner(nullptr), @@ -865,7 +865,7 @@ do_python_task() { case DS_again: Py_XDECREF(_generator); _generator = nullptr; - // Fall through. + [[fallthrough]]; case DS_done: case DS_cont: diff --git a/panda/src/event/pythonTask.h b/panda/src/event/pythonTask.h index 67ae3ed17a6..93c64ad4b2f 100644 --- a/panda/src/event/pythonTask.h +++ b/panda/src/event/pythonTask.h @@ -28,7 +28,7 @@ */ class PythonTask final : public AsyncTask { PUBLISHED: - PythonTask(PyObject *function = Py_None, const std::string &name = std::string()); + PythonTask(PyObject *function = Py_None, std::string name = ""); virtual ~PythonTask(); ALLOC_DELETED_CHAIN(PythonTask); diff --git a/panda/src/event/test_task.cxx b/panda/src/event/test_task.cxx index e8cc5cb5efc..38419405449 100644 --- a/panda/src/event/test_task.cxx +++ b/panda/src/event/test_task.cxx @@ -20,8 +20,8 @@ using std::cerr; class MyTask : public AsyncTask { public: - MyTask(const std::string &name, double length, int repeat_count) : - AsyncTask(name), + MyTask(std::string name, double length, int repeat_count) : + AsyncTask(std::move(name)), _length(length), _repeat_count(repeat_count) { diff --git a/panda/src/event/throw_event.I b/panda/src/event/throw_event.I index bf3618d38ae..72cb6725924 100644 --- a/panda/src/event/throw_event.I +++ b/panda/src/event/throw_event.I @@ -17,34 +17,34 @@ throw_event(const CPT_Event &event) { } INLINE void -throw_event(const std::string &event_name) { - EventQueue::get_global_event_queue()->queue_event(new Event(event_name)); +throw_event(std::string event_name) { + EventQueue::get_global_event_queue()->queue_event(new Event(std::move(event_name))); } INLINE void -throw_event(const std::string &event_name, +throw_event(std::string event_name, const EventParameter &p1) { - Event *event = new Event(event_name); + Event *event = new Event(std::move(event_name)); event->add_parameter(p1); EventQueue::get_global_event_queue()->queue_event(event); } INLINE void -throw_event(const std::string &event_name, +throw_event(std::string event_name, const EventParameter &p1, const EventParameter &p2) { - Event *event = new Event(event_name); + Event *event = new Event(std::move(event_name)); event->add_parameter(p1); event->add_parameter(p2); EventQueue::get_global_event_queue()->queue_event(event); } INLINE void -throw_event(const std::string &event_name, +throw_event(std::string event_name, const EventParameter &p1, const EventParameter &p2, const EventParameter &p3) { - Event *event = new Event(event_name); + Event *event = new Event(std::move(event_name)); event->add_parameter(p1); event->add_parameter(p2); event->add_parameter(p3); @@ -52,12 +52,12 @@ throw_event(const std::string &event_name, } INLINE void -throw_event(const std::string &event_name, +throw_event(std::string event_name, const EventParameter &p1, const EventParameter &p2, const EventParameter &p3, const EventParameter &p4) { - Event *event = new Event(event_name); + Event *event = new Event(std::move(event_name)); event->add_parameter(p1); event->add_parameter(p2); event->add_parameter(p3); @@ -74,25 +74,25 @@ throw_event_directly(EventHandler& handler, INLINE void throw_event_directly(EventHandler& handler, - const std::string &event_name) { - handler.dispatch_event(new Event(event_name)); + std::string event_name) { + handler.dispatch_event(new Event(std::move(event_name))); } INLINE void throw_event_directly(EventHandler& handler, - const std::string &event_name, + std::string event_name, const EventParameter &p1) { - Event *event = new Event(event_name); + Event *event = new Event(std::move(event_name)); event->add_parameter(p1); handler.dispatch_event(event); } INLINE void throw_event_directly(EventHandler& handler, - const std::string &event_name, + std::string event_name, const EventParameter &p1, const EventParameter &p2) { - Event *event = new Event(event_name); + Event *event = new Event(std::move(event_name)); event->add_parameter(p1); event->add_parameter(p2); handler.dispatch_event(event); @@ -100,11 +100,11 @@ throw_event_directly(EventHandler& handler, INLINE void throw_event_directly(EventHandler& handler, - const std::string &event_name, + std::string event_name, const EventParameter &p1, const EventParameter &p2, const EventParameter &p3) { - Event *event = new Event(event_name); + Event *event = new Event(std::move(event_name)); event->add_parameter(p1); event->add_parameter(p2); event->add_parameter(p3); diff --git a/panda/src/event/throw_event.h b/panda/src/event/throw_event.h index 435a959d649..409318c85e7 100644 --- a/panda/src/event/throw_event.h +++ b/panda/src/event/throw_event.h @@ -22,17 +22,17 @@ // A handful of convenience functions to throw events. INLINE void throw_event(const CPT_Event &event); -INLINE void throw_event(const std::string &event_name); -INLINE void throw_event(const std::string &event_name, +INLINE void throw_event(std::string event_name); +INLINE void throw_event(std::string event_name, const EventParameter &p1); -INLINE void throw_event(const std::string &event_name, +INLINE void throw_event(std::string event_name, const EventParameter &p1, const EventParameter &p2); -INLINE void throw_event(const std::string &event_name, +INLINE void throw_event(std::string event_name, const EventParameter &p1, const EventParameter &p2, const EventParameter &p3); -INLINE void throw_event(const std::string &event_name, +INLINE void throw_event(std::string event_name, const EventParameter &p1, const EventParameter &p2, const EventParameter &p3, @@ -43,16 +43,16 @@ INLINE void throw_event(const std::string &event_name, INLINE void throw_event_directly(EventHandler& handler, const CPT_Event &event); INLINE void throw_event_directly(EventHandler& handler, - const std::string &event_name); + std::string event_name); INLINE void throw_event_directly(EventHandler& handler, - const std::string &event_name, + std::string event_name, const EventParameter &p1); INLINE void throw_event_directly(EventHandler& handler, - const std::string &event_name, + std::string event_name, const EventParameter &p1, const EventParameter &p2); INLINE void throw_event_directly(EventHandler& handler, - const std::string &event_name, + std::string event_name, const EventParameter &p1, const EventParameter &p2, const EventParameter &p3); diff --git a/panda/src/express/checksumHashGenerator.cxx b/panda/src/express/checksumHashGenerator.cxx index 0de99789fdb..48775641b12 100644 --- a/panda/src/express/checksumHashGenerator.cxx +++ b/panda/src/express/checksumHashGenerator.cxx @@ -17,10 +17,9 @@ * Adds a string to the hash, by breaking it down into a sequence of integers. */ void ChecksumHashGenerator:: -add_string(const std::string &str) { +add_string(std::string_view str) { add_int(str.length()); - std::string::const_iterator si; - for (si = str.begin(); si != str.end(); ++si) { - add_int(*si); + for (char ch : str) { + add_int(ch); } } diff --git a/panda/src/express/checksumHashGenerator.h b/panda/src/express/checksumHashGenerator.h index 0a7ae110007..6d5d9fbd947 100644 --- a/panda/src/express/checksumHashGenerator.h +++ b/panda/src/express/checksumHashGenerator.h @@ -29,7 +29,7 @@ class EXPCL_PANDA_EXPRESS ChecksumHashGenerator : public HashGeneratorBase { INLINE void add_fp(float num, float threshold); INLINE void add_fp(double num, double threshold); INLINE void add_pointer(void *ptr); - void add_string(const std::string &str); + void add_string(std::string_view str); }; #include "checksumHashGenerator.I" diff --git a/panda/src/express/compress_string.cxx b/panda/src/express/compress_string.cxx index d4c08ddb396..a6944853dbc 100644 --- a/panda/src/express/compress_string.cxx +++ b/panda/src/express/compress_string.cxx @@ -29,7 +29,7 @@ using std::string; * through 9). Returns the compressed string. */ string -compress_string(const string &source, int compression_level) { +compress_string(std::string_view source, int compression_level) { ostringstream dest; { @@ -53,7 +53,8 @@ compress_string(const string &source, int compression_level) { * value may simply be a garbage or truncated string. */ string -decompress_string(const string &source) { +decompress_string(const std::string &source) { + //NB: C++17 has no move-from-string yet. Change in C++20. istringstream source_stream(source); ostringstream dest_stream; diff --git a/panda/src/express/compress_string.h b/panda/src/express/compress_string.h index 7513dbaddd0..b4d9cd0398c 100644 --- a/panda/src/express/compress_string.h +++ b/panda/src/express/compress_string.h @@ -23,7 +23,7 @@ BEGIN_PUBLISH EXPCL_PANDA_EXPRESS std::string -compress_string(const std::string &source, int compression_level); +compress_string(std::string_view source, int compression_level); EXPCL_PANDA_EXPRESS std::string decompress_string(const std::string &source); diff --git a/panda/src/express/datagram.I b/panda/src/express/datagram.I index 42cc6b9cf13..81ca7257ad2 100644 --- a/panda/src/express/datagram.I +++ b/panda/src/express/datagram.I @@ -216,7 +216,7 @@ add_be_float64(PN_float64 value) { * followed by n bytes. */ INLINE void Datagram:: -add_string(const std::string &str) { +add_string(std::string_view str) { // The max sendable length for a string is 2^16. nassertv(str.length() <= (uint16_t)0xffff); @@ -232,7 +232,7 @@ add_string(const std::string &str) { * to allow very long strings. */ INLINE void Datagram:: -add_string32(const std::string &str) { +add_string32(std::string_view str) { // Strings always are preceded by their length add_uint32((uint32_t)str.length()); @@ -244,7 +244,7 @@ add_string32(const std::string &str) { * Adds a variable-length string to the datagram, as a NULL-terminated string. */ INLINE void Datagram:: -add_z_string(const std::string &str) { +add_z_string(std::string_view str) { // We must not have any nested null characters in the string. size_t null_pos = str.find('\0'); // Add the string (sans the null character). @@ -260,7 +260,7 @@ add_z_string(const std::string &str) { * greater than the requested size, this will silently truncate the string. */ INLINE void Datagram:: -add_fixed_string(const std::string &str, size_t size) { +add_fixed_string(std::string_view str, size_t size) { if (str.length() < size) { append_data(str.data(), str.length()); pad_bytes(size - str.length()); @@ -466,12 +466,12 @@ generic_write_datagram(Datagram &dest, double value) { } INLINE void -generic_write_datagram(Datagram &dest, const std::string &value) { +generic_write_datagram(Datagram &dest, std::string_view value) { dest.add_string(value); } INLINE void -generic_write_datagram(Datagram &dest, const std::wstring &value) { +generic_write_datagram(Datagram &dest, std::wstring_view value) { dest.add_wstring(value); } diff --git a/panda/src/express/datagram.cxx b/panda/src/express/datagram.cxx index 9ba36b8add0..ae74c8cac98 100644 --- a/panda/src/express/datagram.cxx +++ b/panda/src/express/datagram.cxx @@ -80,15 +80,14 @@ dump_hex(std::ostream &out, unsigned int indent) const { * Adds a variable-length wstring to the datagram. */ void Datagram:: -add_wstring(const std::wstring &str) { +add_wstring(std::wstring_view str) { // By convention, wstrings are marked with 32-bit lengths. add_uint32((uint32_t)str.length()); // Now append each character in the string. We store each code little- // endian, for no real good reason. - std::wstring::const_iterator ci; - for (ci = str.begin(); ci != str.end(); ++ci) { - add_uint16((uint16_t)*ci); + for (wchar_t ch : str) { + add_uint16((uint16_t)ch); } } diff --git a/panda/src/express/datagram.h b/panda/src/express/datagram.h index 4cf074cdeea..9e127c4eaff 100644 --- a/panda/src/express/datagram.h +++ b/panda/src/express/datagram.h @@ -75,11 +75,11 @@ class EXPCL_PANDA_EXPRESS Datagram : public TypedObject { INLINE void add_be_float32(PN_float32 value); INLINE void add_be_float64(PN_float64 value); - INLINE void add_string(const std::string &str); - INLINE void add_string32(const std::string &str); - INLINE void add_z_string(const std::string &str); - INLINE void add_fixed_string(const std::string &str, size_t size); - void add_wstring(const std::wstring &str); + INLINE void add_string(std::string_view str); + INLINE void add_string32(std::string_view str); + INLINE void add_z_string(std::string_view str); + INLINE void add_fixed_string(std::string_view str, size_t size); + void add_wstring(std::wstring_view str); INLINE void add_blob(const vector_uchar &); INLINE void add_blob32(const vector_uchar &); @@ -159,9 +159,9 @@ generic_write_datagram(Datagram &dest, float value); INLINE void generic_write_datagram(Datagram &dest, double value); INLINE void -generic_write_datagram(Datagram &dest, const std::string &value); +generic_write_datagram(Datagram &dest, std::string_view value); INLINE void -generic_write_datagram(Datagram &dest, const std::wstring &value); +generic_write_datagram(Datagram &dest, std::wstring_view value); INLINE void generic_write_datagram(Datagram &dest, const vector_uchar &value); diff --git a/panda/src/express/encrypt_string.cxx b/panda/src/express/encrypt_string.cxx index 8c21d986fa7..1ff4128fa54 100644 --- a/panda/src/express/encrypt_string.cxx +++ b/panda/src/express/encrypt_string.cxx @@ -30,14 +30,14 @@ using std::string; * algorithm specified by encryption-algorithm. Returns the encrypted data. */ vector_uchar -encrypt_string(const string &source, const string &password, - const string &algorithm, int key_length, int iteration_count) { +encrypt_string(std::string_view source, std::string_view password, + std::string algorithm, int key_length, int iteration_count) { StringStream dest; { OEncryptStream encrypt; if (!algorithm.empty()) { - encrypt.set_algorithm(algorithm); + encrypt.set_algorithm(std::move(algorithm)); } if (key_length > 0) { encrypt.set_key_length(key_length); @@ -67,7 +67,7 @@ encrypt_string(const string &source, const string &password, * easily be detected, and the return value may simply be a garbage string. */ string -decrypt_string(const vector_uchar &source, const string &password) { +decrypt_string(const vector_uchar &source, std::string_view password) { StringStream source_stream(source); ostringstream dest_stream; @@ -85,8 +85,8 @@ decrypt_string(const vector_uchar &source, const string &password) { * success, or false on failure. */ EXPCL_PANDA_EXPRESS bool -encrypt_file(const Filename &source, const Filename &dest, const string &password, - const string &algorithm, int key_length, int iteration_count) { +encrypt_file(const Filename &source, const Filename &dest, std::string_view password, + std::string algorithm, int key_length, int iteration_count) { VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); Filename source_filename = source; if (!source_filename.is_binary_or_text()) { @@ -108,7 +108,7 @@ encrypt_file(const Filename &source, const Filename &dest, const string &passwor } bool result = encrypt_stream(*source_stream, *dest_stream, password, - algorithm, key_length, iteration_count); + std::move(algorithm), key_length, iteration_count); vfs->close_read_file(source_stream); vfs->close_write_file(dest_stream); return result; @@ -125,7 +125,7 @@ encrypt_file(const Filename &source, const Filename &dest, const string &passwor * easily be detected, and the output may simply be a garbage string. */ EXPCL_PANDA_EXPRESS bool -decrypt_file(const Filename &source, const Filename &dest, const string &password) { +decrypt_file(const Filename &source, const Filename &dest, std::string_view password) { Filename source_filename = Filename::binary_filename(source); VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); istream *source_stream = vfs->open_read_file(source_filename, false); @@ -159,11 +159,11 @@ decrypt_file(const Filename &source, const Filename &dest, const string &passwor * on success, or false on failure. */ bool -encrypt_stream(istream &source, ostream &dest, const string &password, - const string &algorithm, int key_length, int iteration_count) { +encrypt_stream(istream &source, ostream &dest, std::string_view password, + std::string algorithm, int key_length, int iteration_count) { OEncryptStream encrypt; if (!algorithm.empty()) { - encrypt.set_algorithm(algorithm); + encrypt.set_algorithm(std::move(algorithm)); } if (key_length > 0) { encrypt.set_key_length(key_length); @@ -199,7 +199,7 @@ encrypt_stream(istream &source, ostream &dest, const string &password, * easily be detected, and the output may simply be a garbage string. */ bool -decrypt_stream(istream &source, ostream &dest, const string &password) { +decrypt_stream(istream &source, ostream &dest, std::string_view password) { IDecryptStream decrypt(&source, false, password); static const size_t buffer_size = 4096; diff --git a/panda/src/express/encrypt_string.h b/panda/src/express/encrypt_string.h index caf7f144665..345eeea8824 100644 --- a/panda/src/express/encrypt_string.h +++ b/panda/src/express/encrypt_string.h @@ -24,25 +24,25 @@ BEGIN_PUBLISH EXPCL_PANDA_EXPRESS vector_uchar -encrypt_string(const std::string &source, const std::string &password, - const std::string &algorithm = std::string(), int key_length = -1, +encrypt_string(std::string_view source, std::string_view password, + std::string algorithm = std::string(), int key_length = -1, int iteration_count = -1); EXPCL_PANDA_EXPRESS std::string -decrypt_string(const vector_uchar &source, const std::string &password); +decrypt_string(const vector_uchar &source, std::string_view password); EXPCL_PANDA_EXPRESS bool -encrypt_file(const Filename &source, const Filename &dest, const std::string &password, - const std::string &algorithm = std::string(), int key_length = -1, +encrypt_file(const Filename &source, const Filename &dest, std::string_view password, + std::string algorithm = std::string(), int key_length = -1, int iteration_count = -1); EXPCL_PANDA_EXPRESS bool -decrypt_file(const Filename &source, const Filename &dest, const std::string &password); +decrypt_file(const Filename &source, const Filename &dest, std::string_view password); EXPCL_PANDA_EXPRESS bool -encrypt_stream(std::istream &source, std::ostream &dest, const std::string &password, - const std::string &algorithm = std::string(), int key_length = -1, +encrypt_stream(std::istream &source, std::ostream &dest, std::string_view password, + std::string algorithm = std::string(), int key_length = -1, int iteration_count = -1); EXPCL_PANDA_EXPRESS bool -decrypt_stream(std::istream &source, std::ostream &dest, const std::string &password); +decrypt_stream(std::istream &source, std::ostream &dest, std::string_view password); END_PUBLISH diff --git a/panda/src/express/hashVal.I b/panda/src/express/hashVal.I index 0adc0d70408..8c575a98045 100644 --- a/panda/src/express/hashVal.I +++ b/panda/src/express/hashVal.I @@ -176,7 +176,7 @@ hash_ramfile(const Ramfile &ramfile) { * Generates the hash value by hashing the indicated data. */ INLINE void HashVal:: -hash_string(const std::string &data) { +hash_string(std::string_view data) { hash_buffer(data.data(), data.length()); } diff --git a/panda/src/express/hashVal.cxx b/panda/src/express/hashVal.cxx index ed1b60b530d..e0adf2a61b5 100644 --- a/panda/src/express/hashVal.cxx +++ b/panda/src/express/hashVal.cxx @@ -110,7 +110,8 @@ as_dec() const { * valid, false otherwise. */ bool HashVal:: -set_from_dec(const string &text) { +set_from_dec(const std::string &text) { + //NB: C++17 has no move-from-string yet. Change in C++20. istringstream strm(text); input_dec(strm); return !strm.fail(); @@ -134,7 +135,8 @@ as_hex() const { * successful, false otherwise. */ bool HashVal:: -set_from_hex(const string &text) { +set_from_hex(const std::string &text) { + //NB: C++17 has no move-from-string yet. Change in C++20. istringstream strm(text); input_hex(strm); return !strm.fail(); diff --git a/panda/src/express/hashVal.h b/panda/src/express/hashVal.h index 0d2d8fc6b3c..d46ab1a941e 100644 --- a/panda/src/express/hashVal.h +++ b/panda/src/express/hashVal.h @@ -66,7 +66,7 @@ class EXPCL_PANDA_EXPRESS HashVal { bool hash_file(const Filename &filename); bool hash_stream(std::istream &stream); INLINE void hash_ramfile(const Ramfile &ramfile); - INLINE void hash_string(const std::string &data); + INLINE void hash_string(std::string_view data); INLINE void hash_bytes(const vector_uchar &data); void hash_buffer(const char *buffer, size_t length); diff --git a/panda/src/express/multifile.I b/panda/src/express/multifile.I index 266670b0775..ff9e2b72364 100644 --- a/panda/src/express/multifile.I +++ b/panda/src/express/multifile.I @@ -154,12 +154,12 @@ get_encryption_flag() const { * implicit call to flush(). */ INLINE void Multifile:: -set_encryption_password(const std::string &encryption_password) { +set_encryption_password(std::string encryption_password) { if (_encryption_password != encryption_password) { if (!_new_subfiles.empty()) { flush(); } - _encryption_password = encryption_password; + _encryption_password = std::move(encryption_password); } } @@ -187,12 +187,12 @@ get_encryption_password() const { * flush(). */ INLINE void Multifile:: -set_encryption_algorithm(const std::string &encryption_algorithm) { +set_encryption_algorithm(std::string encryption_algorithm) { if (_encryption_algorithm != encryption_algorithm) { if (!_new_subfiles.empty()) { flush(); } - _encryption_algorithm = encryption_algorithm; + _encryption_algorithm = std::move(encryption_algorithm); } } @@ -279,7 +279,7 @@ get_encryption_iteration_count() const { * reduced in size after this operation, until the next call to repack(). */ INLINE bool Multifile:: -remove_subfile(const std::string &subfile_name) { +remove_subfile(std::string_view subfile_name) { int index = find_subfile(subfile_name); if (index >= 0) { remove_subfile(index); diff --git a/panda/src/express/multifile.cxx b/panda/src/express/multifile.cxx index a54e76cac70..fd08a79b666 100644 --- a/panda/src/express/multifile.cxx +++ b/panda/src/express/multifile.cxx @@ -414,7 +414,7 @@ set_scale_factor(size_t scale_factor) { * or empty string on failure. */ string Multifile:: -add_subfile(const string &subfile_name, const Filename &filename, +add_subfile(std::string_view subfile_name, const Filename &filename, int compression_level) { nassertr(is_write_valid(), string()); @@ -462,7 +462,7 @@ add_subfile(const string &subfile_name, const Filename &filename, * or empty string on failure. */ string Multifile:: -add_subfile(const string &subfile_name, istream *subfile_data, +add_subfile(std::string_view subfile_name, istream *subfile_data, int compression_level) { nassertr(is_write_valid(), string()); @@ -488,7 +488,7 @@ add_subfile(const string &subfile_name, istream *subfile_data, * called, the text flag will be set on the subfile. */ string Multifile:: -update_subfile(const string &subfile_name, const Filename &filename, +update_subfile(std::string_view subfile_name, const Filename &filename, int compression_level) { nassertr(is_write_valid(), string()); @@ -1364,7 +1364,7 @@ get_num_subfiles() const { * named subfile is not within the Multifile. */ int Multifile:: -find_subfile(const string &subfile_name) const { +find_subfile(std::string_view subfile_name) const { Subfile find_subfile; find_subfile._name = standardize_subfile_name(subfile_name); Subfiles::const_iterator fi; @@ -1382,8 +1382,8 @@ find_subfile(const string &subfile_name) const { * least one file named "subfile_name/...". */ bool Multifile:: -has_directory(const string &subfile_name) const { - string prefix = subfile_name; +has_directory(std::string subfile_name) const { + string prefix = std::move(subfile_name); if (!prefix.empty()) { prefix += '/'; } @@ -1414,8 +1414,8 @@ has_directory(const string &subfile_name) const { * Returns true if successful, false otherwise. */ bool Multifile:: -scan_directory(vector_string &contents, const string &subfile_name) const { - string prefix = subfile_name; +scan_directory(vector_string &contents, std::string subfile_name) const { + string prefix = std::move(subfile_name); if (!prefix.empty()) { prefix += '/'; } @@ -1837,8 +1837,8 @@ ls(ostream &out) const { * because the header prefix violates the above rules). */ void Multifile:: -set_header_prefix(const string &header_prefix) { - string new_header_prefix = header_prefix; +set_header_prefix(std::string header_prefix) { + string new_header_prefix = std::move(header_prefix); if (!new_header_prefix.empty()) { // It must begin with a hash mark. @@ -2104,8 +2104,8 @@ open_read_subfile(Subfile *subfile) { * Returns the standard form of the subfile name. */ string Multifile:: -standardize_subfile_name(const string &subfile_name) const { - Filename name = subfile_name; +standardize_subfile_name(std::string_view subfile_name) const { + Filename name(subfile_name); name.standardize(); if (name.empty() || name == "/") { // Invalid empty name. diff --git a/panda/src/express/multifile.h b/panda/src/express/multifile.h index 41e9159c645..fb57e19d344 100644 --- a/panda/src/express/multifile.h +++ b/panda/src/express/multifile.h @@ -70,18 +70,18 @@ class EXPCL_PANDA_EXPRESS Multifile : public ReferenceCount { INLINE void set_encryption_flag(bool flag); INLINE bool get_encryption_flag() const; - INLINE void set_encryption_algorithm(const std::string &encryption_algorithm); + INLINE void set_encryption_algorithm(std::string encryption_algorithm); INLINE const std::string &get_encryption_algorithm() const; INLINE void set_encryption_key_length(int encryption_key_length); INLINE int get_encryption_key_length() const; INLINE void set_encryption_iteration_count(int encryption_iteration_count); INLINE int get_encryption_iteration_count() const; - std::string add_subfile(const std::string &subfile_name, const Filename &filename, + std::string add_subfile(std::string_view subfile_name, const Filename &filename, int compression_level); - std::string add_subfile(const std::string &subfile_name, std::istream *subfile_data, + std::string add_subfile(std::string_view subfile_name, std::istream *subfile_data, int compression_level); - std::string update_subfile(const std::string &subfile_name, const Filename &filename, + std::string update_subfile(std::string_view subfile_name, const Filename &filename, int compression_level); PY_EXTENSION(INLINE PyObject *set_encryption_password(PyObject *encryption_password) const); @@ -109,12 +109,11 @@ class EXPCL_PANDA_EXPRESS Multifile : public ReferenceCount { BLOCKING bool repack(); int get_num_subfiles() const; - int find_subfile(const std::string &subfile_name) const; - bool has_directory(const std::string &subfile_name) const; - bool scan_directory(vector_string &contents, - const std::string &subfile_name) const; + int find_subfile(std::string_view subfile_name) const; + bool has_directory(std::string subfile_name) const; + bool scan_directory(vector_string &contents, std::string subfile_name) const; void remove_subfile(int index); - INLINE bool remove_subfile(const std::string &subfile_name); + INLINE bool remove_subfile(std::string_view subfile_name); const std::string &get_subfile_name(int index) const; MAKE_SEQ(get_subfile_names, get_num_subfiles, get_subfile_name); size_t get_subfile_length(int index) const; @@ -128,7 +127,7 @@ class EXPCL_PANDA_EXPRESS Multifile : public ReferenceCount { size_t get_subfile_internal_length(int index) const; BLOCKING INLINE vector_uchar read_subfile(int index); - BLOCKING std::istream *open_read_subfile(int index); + [[nodiscard]] BLOCKING std::istream *open_read_subfile(int index); BLOCKING static void close_read_subfile(std::istream *stream); BLOCKING bool extract_subfile(int index, const Filename &filename); BLOCKING bool extract_subfile_to(int index, std::ostream &out); @@ -140,11 +139,11 @@ class EXPCL_PANDA_EXPRESS Multifile : public ReferenceCount { static INLINE std::string get_magic_number(); MAKE_PROPERTY(magic_number, get_magic_number); - void set_header_prefix(const std::string &header_prefix); + void set_header_prefix(std::string header_prefix); INLINE const std::string &get_header_prefix() const; public: - INLINE void set_encryption_password(const std::string &encryption_password); + INLINE void set_encryption_password(std::string encryption_password); INLINE const std::string &get_encryption_password() const; #ifdef HAVE_OPENSSL @@ -218,7 +217,7 @@ class EXPCL_PANDA_EXPRESS Multifile : public ReferenceCount { void add_new_subfile(Subfile *subfile, int compression_level); std::istream *open_read_subfile(Subfile *subfile); - std::string standardize_subfile_name(const std::string &subfile_name) const; + std::string standardize_subfile_name(std::string_view subfile_name) const; void clear_subfiles(); bool read_index(); diff --git a/panda/src/express/namable.I b/panda/src/express/namable.I index d7060ce1c9f..76d1c37c9d8 100644 --- a/panda/src/express/namable.I +++ b/panda/src/express/namable.I @@ -15,8 +15,8 @@ * */ INLINE Namable:: -Namable(const std::string &initial_name) : - _name(initial_name) +Namable(std::string initial_name) : + _name(std::move(initial_name)) { } @@ -24,8 +24,8 @@ Namable(const std::string &initial_name) : * */ INLINE void Namable:: -set_name(const std::string &name) { - _name = name; +set_name(std::string name) { + _name = std::move(name); } /** diff --git a/panda/src/express/namable.h b/panda/src/express/namable.h index eb8c0c6e797..80ed2d7d9d0 100644 --- a/panda/src/express/namable.h +++ b/panda/src/express/namable.h @@ -25,9 +25,9 @@ */ class EXPCL_PANDA_EXPRESS Namable : public MemoryBase { PUBLISHED: - INLINE explicit Namable(const std::string &initial_name = ""); + INLINE explicit Namable(std::string initial_name = ""); - INLINE void set_name(const std::string &name); + INLINE void set_name(std::string name); INLINE void clear_name(); INLINE bool has_name() const; INLINE const std::string &get_name() const; diff --git a/panda/src/express/openSSLWrapper.I b/panda/src/express/openSSLWrapper.I index a8b8e396a6e..34917e89d7c 100644 --- a/panda/src/express/openSSLWrapper.I +++ b/panda/src/express/openSSLWrapper.I @@ -21,7 +21,7 @@ * with certificates received from an untrusted source. */ INLINE int OpenSSLWrapper:: -load_certificates_from_pem_ram(const std::string &data) { +load_certificates_from_pem_ram(std::string_view data) { return load_certificates_from_pem_ram(data.data(), data.size()); } @@ -35,6 +35,6 @@ load_certificates_from_pem_ram(const std::string &data) { * with certificates received from an untrusted source. */ INLINE int OpenSSLWrapper:: -load_certificates_from_der_ram(const std::string &data) { +load_certificates_from_der_ram(std::string_view data) { return load_certificates_from_der_ram(data.data(), data.size()); } diff --git a/panda/src/express/openSSLWrapper.h b/panda/src/express/openSSLWrapper.h index 5baabc24c50..ef847ff33a5 100644 --- a/panda/src/express/openSSLWrapper.h +++ b/panda/src/express/openSSLWrapper.h @@ -54,8 +54,8 @@ class EXPCL_PANDA_EXPRESS OpenSSLWrapper { int load_certificates_from_pem_ram(const char *data, size_t data_size); int load_certificates_from_der_ram(const char *data, size_t data_size); - INLINE int load_certificates_from_pem_ram(const std::string &data); - INLINE int load_certificates_from_der_ram(const std::string &data); + INLINE int load_certificates_from_pem_ram(std::string_view data); + INLINE int load_certificates_from_der_ram(std::string_view data); X509_STORE *get_x509_store(); diff --git a/panda/src/express/password_hash.cxx b/panda/src/express/password_hash.cxx index 06c75713402..7a14c6cc9df 100644 --- a/panda/src/express/password_hash.cxx +++ b/panda/src/express/password_hash.cxx @@ -48,7 +48,7 @@ using std::string; * keylen is the length in bytes of the required key hash. */ string -password_hash(const string &password, const string &salt, +password_hash(std::string_view password, std::string_view salt, int iters, int keylen) { nassertr(iters > 0 && keylen > 0, string()); unsigned char *dk = (unsigned char *)PANDA_MALLOC_ARRAY(keylen); diff --git a/panda/src/express/password_hash.h b/panda/src/express/password_hash.h index f6091b8103a..bec7ce26046 100644 --- a/panda/src/express/password_hash.h +++ b/panda/src/express/password_hash.h @@ -22,8 +22,8 @@ BEGIN_PUBLISH -EXPCL_PANDA_EXPRESS std::string password_hash(const std::string &password, - const std::string &salt, +EXPCL_PANDA_EXPRESS std::string password_hash(std::string_view password, + std::string_view salt, int iters, int keylen); END_PUBLISH diff --git a/panda/src/express/pointerToArray.I b/panda/src/express/pointerToArray.I index 43d81f4ff20..5544ccd7a22 100644 --- a/panda/src/express/pointerToArray.I +++ b/panda/src/express/pointerToArray.I @@ -457,7 +457,7 @@ get_data() const { */ template INLINE void PointerToArray:: -set_data(const std::string &data) { +set_data(std::string_view data) { set_subdata(0, size(), data); } @@ -489,7 +489,7 @@ get_subdata(size_type n, size_type count) const { */ template INLINE void PointerToArray:: -set_subdata(size_type n, size_type count, const std::string &data) { +set_subdata(size_type n, size_type count, std::string_view data) { nassertv((data.length() % sizeof(Element)) == 0); nassertv(n <= size() && n + count <= size()); if ((this->_void_ptr) == nullptr) { diff --git a/panda/src/express/pointerToArray.h b/panda/src/express/pointerToArray.h index 12174a02ac3..fbd8425ee6e 100644 --- a/panda/src/express/pointerToArray.h +++ b/panda/src/express/pointerToArray.h @@ -110,7 +110,7 @@ class PointerToArray : public PointerToArrayBase { PY_EXTENSION(PyObject *get_data() const); PY_EXTENSION(void set_data(PyObject *data)); PY_EXTENSION(PyObject *get_subdata(size_type n, size_type count) const); - INLINE void set_subdata(size_type n, size_type count, const std::string &data); + INLINE void set_subdata(size_type n, size_type count, std::string_view data); INLINE int get_ref_count() const; INLINE int get_node_ref_count() const; @@ -199,9 +199,9 @@ class PointerToArray : public PointerToArrayBase { INLINE const Element &get_element(size_type n) const; INLINE void set_element(size_type n, const Element &value); INLINE std::string get_data() const; - INLINE void set_data(const std::string &data); + INLINE void set_data(std::string_view data); INLINE std::string get_subdata(size_type n, size_type count) const; - INLINE void set_subdata(size_type n, size_type count, const std::string &data); + INLINE void set_subdata(size_type n, size_type count, std::string_view data); // These functions are only to be used in Reading through BamReader. They // are designed to work in pairs, so that you register what is returned by diff --git a/panda/src/express/stringStream.I b/panda/src/express/stringStream.I index f5720dd2bb3..673002775f3 100644 --- a/panda/src/express/stringStream.I +++ b/panda/src/express/stringStream.I @@ -23,7 +23,7 @@ StringStream() : std::iostream(&_buf) { * data. */ INLINE StringStream:: -StringStream(const std::string &source) : std::iostream(&_buf) { +StringStream(std::string_view source) : std::iostream(&_buf) { set_data(source); } @@ -70,7 +70,7 @@ get_data() { * Replaces the contents of the data stream. This implicitly reseeks to 0. */ INLINE void StringStream:: -set_data(const std::string &data) { +set_data(std::string_view data) { _buf.clear(); if (!data.empty()) { set_data((const unsigned char *)data.data(), data.size()); diff --git a/panda/src/express/stringStream.h b/panda/src/express/stringStream.h index 5453d2f7cea..5aca146fa73 100644 --- a/panda/src/express/stringStream.h +++ b/panda/src/express/stringStream.h @@ -26,7 +26,7 @@ */ class EXPCL_PANDA_EXPRESS StringStream : public std::iostream { public: - INLINE StringStream(const std::string &source); + INLINE StringStream(std::string_view source); INLINE StringStream(vector_uchar source); PUBLISHED: @@ -48,7 +48,7 @@ class EXPCL_PANDA_EXPRESS StringStream : public std::iostream { public: #ifndef CPPPARSER INLINE std::string get_data(); - INLINE void set_data(const std::string &data); + INLINE void set_data(std::string_view data); void set_data(const unsigned char *data, size_t size); #endif // !CPPPARSER diff --git a/panda/src/express/stringStreamBuf.cxx b/panda/src/express/stringStreamBuf.cxx index f9a6cc99f99..128ed548915 100644 --- a/panda/src/express/stringStreamBuf.cxx +++ b/panda/src/express/stringStreamBuf.cxx @@ -24,24 +24,12 @@ using std::streampos; */ StringStreamBuf:: StringStreamBuf() { -#ifdef PHAVE_IOSTREAM _buffer = (char *)PANDA_MALLOC_ARRAY(2048); char *ebuf = _buffer + 2048; char *mbuf = _buffer + 1024; setg(_buffer, mbuf, mbuf); setp(mbuf, ebuf); -#else - allocate(); - // Chop the buffer in half. The bottom half goes to the get buffer; the top - // half goes to the put buffer. - char *b = base(); - char *t = ebuf(); - char *m = b + (t - b) / 2; - setg(b, m, m); - setp(b, m); -#endif - _gpos = 0; _ppos = 0; } @@ -51,9 +39,7 @@ StringStreamBuf() { */ StringStreamBuf:: ~StringStreamBuf() { -#ifdef PHAVE_IOSTREAM PANDA_FREE_ARRAY(_buffer); -#endif } /** diff --git a/panda/src/express/subStreamBuf.cxx b/panda/src/express/subStreamBuf.cxx index 14a05f1bfba..80c4bd25cef 100644 --- a/panda/src/express/subStreamBuf.cxx +++ b/panda/src/express/subStreamBuf.cxx @@ -46,23 +46,11 @@ SubStreamBuf() { _gpos = 0; _ppos = 0; -#ifdef PHAVE_IOSTREAM _buffer = (char *)PANDA_MALLOC_ARRAY(substream_buffer_size * 2); char *ebuf = _buffer + substream_buffer_size * 2; char *mbuf = _buffer + substream_buffer_size; setg(_buffer, mbuf, mbuf); setp(mbuf, ebuf); - -#else - allocate(); - // Chop the buffer in half. The bottom half goes to the get buffer; the top - // half goes to the put buffer. - char *b = base(); - char *t = ebuf(); - char *m = b + (t - b) / 2; - setg(b, m, m); - setp(b, m); -#endif } /** @@ -71,9 +59,7 @@ SubStreamBuf() { SubStreamBuf:: ~SubStreamBuf() { close(); -#ifdef PHAVE_IOSTREAM PANDA_FREE_ARRAY(_buffer); -#endif } /** diff --git a/panda/src/express/test_types.cxx b/panda/src/express/test_types.cxx index 1bc9bfefd7b..8f7dedc63ae 100644 --- a/panda/src/express/test_types.cxx +++ b/panda/src/express/test_types.cxx @@ -24,7 +24,7 @@ using std::string; class ThatThingie : public TypedObject, public ReferenceCount { public: - ThatThingie(const string &name) : _name(name) { + ThatThingie(std::string name) : _name(std::move(name)) { nout << "Constructing ThatThingie " << _name << "\n"; } virtual ~ThatThingie() { @@ -56,7 +56,7 @@ class ThatThingie : public TypedObject, public ReferenceCount { class ThisThingie : public ThatThingie { public: - ThisThingie(const string &name) : ThatThingie(name) { + ThisThingie(std::string name) : ThatThingie(std::move(name)) { nout << "Constructing ThisThingie " << _name << "\n"; } virtual ~ThisThingie() { @@ -87,7 +87,7 @@ class ThisThingie : public ThatThingie { class TheOtherThingie { public: - TheOtherThingie(const string &name) : _name(name) { + TheOtherThingie(std::string name) : _name(std::move(name)) { nout << "Constructing TheOtherThingie " << _name << "\n"; } virtual ~TheOtherThingie() { @@ -116,7 +116,7 @@ class TheOtherThingie { class WhatAThingie : public ThatThingie, public TheOtherThingie { public: - WhatAThingie(const string &name) : ThatThingie(name), TheOtherThingie(name) { + WhatAThingie(const std::string &name) : ThatThingie(name), TheOtherThingie(name) { nout << "Constructing WhatAThingie " << ThatThingie::_name << "\n"; } virtual ~WhatAThingie() { diff --git a/panda/src/express/virtualFile.I b/panda/src/express/virtualFile.I index 64fa9f7d00c..2e5418311e5 100644 --- a/panda/src/express/virtualFile.I +++ b/panda/src/express/virtualFile.I @@ -42,7 +42,7 @@ read_file(bool auto_unwrap) const { * Writes the entire contents of the file as a string, if it is writable. */ INLINE bool VirtualFile:: -write_file(const std::string &data, bool auto_wrap) { +write_file(std::string_view data, bool auto_wrap) { return write_file((const unsigned char *)data.data(), data.size(), auto_wrap); } diff --git a/panda/src/express/virtualFile.cxx b/panda/src/express/virtualFile.cxx index e388d7c704e..f13b41faa99 100644 --- a/panda/src/express/virtualFile.cxx +++ b/panda/src/express/virtualFile.cxx @@ -335,8 +335,8 @@ get_system_info(SubfileInfo &info) { */ bool VirtualFile:: atomic_compare_and_exchange_contents(string &orig_contents, - const string &old_contents, - const string &new_contents) { + std::string_view old_contents, + std::string_view new_contents) { return false; } diff --git a/panda/src/express/virtualFile.h b/panda/src/express/virtualFile.h index acefe65d83c..069ffacfa50 100644 --- a/panda/src/express/virtualFile.h +++ b/panda/src/express/virtualFile.h @@ -57,17 +57,17 @@ class EXPCL_PANDA_EXPRESS VirtualFile : public TypedReferenceCount { BLOCKING void ls_all(std::ostream &out = std::cout) const; PY_EXTENSION(PyObject *read_file(bool auto_unwrap) const); - BLOCKING virtual std::istream *open_read_file(bool auto_unwrap) const; + [[nodiscard]] BLOCKING virtual std::istream *open_read_file(bool auto_unwrap) const; BLOCKING virtual void close_read_file(std::istream *stream) const; virtual bool was_read_successful() const; PY_EXTENSION(PyObject *write_file(PyObject *data, bool auto_wrap)); - BLOCKING virtual std::ostream *open_write_file(bool auto_wrap, bool truncate); - BLOCKING virtual std::ostream *open_append_file(); + [[nodiscard]] BLOCKING virtual std::ostream *open_write_file(bool auto_wrap, bool truncate); + [[nodiscard]] BLOCKING virtual std::ostream *open_append_file(); BLOCKING virtual void close_write_file(std::ostream *stream); - BLOCKING virtual std::iostream *open_read_write_file(bool truncate); - BLOCKING virtual std::iostream *open_read_append_file(); + [[nodiscard]] BLOCKING virtual std::iostream *open_read_write_file(bool truncate); + [[nodiscard]] BLOCKING virtual std::iostream *open_read_append_file(); BLOCKING virtual void close_read_write_file(std::iostream *stream); BLOCKING virtual std::streamsize get_file_size(std::istream *stream) const; @@ -77,11 +77,11 @@ class EXPCL_PANDA_EXPRESS VirtualFile : public TypedReferenceCount { virtual bool get_system_info(SubfileInfo &info); public: - virtual bool atomic_compare_and_exchange_contents(std::string &orig_contents, const std::string &old_contents, const std::string &new_contents); + virtual bool atomic_compare_and_exchange_contents(std::string &orig_contents, std::string_view old_contents, std::string_view new_contents); virtual bool atomic_read_contents(std::string &contents) const; INLINE std::string read_file(bool auto_unwrap) const; - INLINE bool write_file(const std::string &data, bool auto_wrap); + INLINE bool write_file(std::string_view data, bool auto_wrap); INLINE void set_original_filename(const Filename &filename); virtual bool read_file(std::string &result, bool auto_unwrap) const; diff --git a/panda/src/express/virtualFileMount.cxx b/panda/src/express/virtualFileMount.cxx index 0bfc9fc3e3f..260e0fece37 100644 --- a/panda/src/express/virtualFileMount.cxx +++ b/panda/src/express/virtualFileMount.cxx @@ -315,8 +315,8 @@ get_system_info(const Filename &file, SubfileInfo &info) { */ bool VirtualFileMount:: atomic_compare_and_exchange_contents(const Filename &file, string &orig_contents, - const string &old_contents, - const string &new_contents) { + std::string_view old_contents, + std::string_view new_contents) { return false; } diff --git a/panda/src/express/virtualFileMount.h b/panda/src/express/virtualFileMount.h index 137400b1c0b..0b4598139ca 100644 --- a/panda/src/express/virtualFileMount.h +++ b/panda/src/express/virtualFileMount.h @@ -79,7 +79,7 @@ class EXPCL_PANDA_EXPRESS VirtualFileMount : public TypedReferenceCount { virtual bool scan_directory(vector_string &contents, const Filename &dir) const=0; - virtual bool atomic_compare_and_exchange_contents(const Filename &file, std::string &orig_contents, const std::string &old_contents, const std::string &new_contents); + virtual bool atomic_compare_and_exchange_contents(const Filename &file, std::string &orig_contents, std::string_view old_contents, std::string_view new_contents); virtual bool atomic_read_contents(const Filename &file, std::string &contents) const; PUBLISHED: diff --git a/panda/src/express/virtualFileMountAndroidAsset.I b/panda/src/express/virtualFileMountAndroidAsset.I index c3079e04ee7..5e45cdb735f 100644 --- a/panda/src/express/virtualFileMountAndroidAsset.I +++ b/panda/src/express/virtualFileMountAndroidAsset.I @@ -15,8 +15,8 @@ * */ VirtualFileMountAndroidAsset:: -VirtualFileMountAndroidAsset(AAssetManager *mgr, const std::string &apk_path) : - _asset_mgr(mgr), _apk_path(apk_path) +VirtualFileMountAndroidAsset(AAssetManager *mgr, std::string apk_path) : + _asset_mgr(mgr), _apk_path(std::move(apk_path)) { } diff --git a/panda/src/express/virtualFileMountAndroidAsset.cxx b/panda/src/express/virtualFileMountAndroidAsset.cxx index c9074fe97a4..81c5d0d7638 100644 --- a/panda/src/express/virtualFileMountAndroidAsset.cxx +++ b/panda/src/express/virtualFileMountAndroidAsset.cxx @@ -266,15 +266,9 @@ VirtualFileMountAndroidAsset::AssetStreamBuf:: AssetStreamBuf(AAsset *asset) : _asset(asset) { -#ifdef PHAVE_IOSTREAM char *buf = new char[4096]; char *ebuf = buf + 4096; setg(buf, ebuf, ebuf); - -#else - allocate(); - setg(base(), ebuf(), ebuf()); -#endif } /** diff --git a/panda/src/express/virtualFileMountAndroidAsset.h b/panda/src/express/virtualFileMountAndroidAsset.h index d640e8612e7..5a1a9178c9d 100644 --- a/panda/src/express/virtualFileMountAndroidAsset.h +++ b/panda/src/express/virtualFileMountAndroidAsset.h @@ -29,7 +29,7 @@ */ class EXPCL_PANDA_EXPRESS VirtualFileMountAndroidAsset : public VirtualFileMount { PUBLISHED: - INLINE VirtualFileMountAndroidAsset(AAssetManager *mgr, const std::string &apk_path); + INLINE VirtualFileMountAndroidAsset(AAssetManager *mgr, std::string apk_path); virtual ~VirtualFileMountAndroidAsset(); public: diff --git a/panda/src/express/virtualFileMountRamdisk.I b/panda/src/express/virtualFileMountRamdisk.I index 27c07c4dce8..ecaaf339f27 100644 --- a/panda/src/express/virtualFileMountRamdisk.I +++ b/panda/src/express/virtualFileMountRamdisk.I @@ -15,7 +15,7 @@ * */ INLINE VirtualFileMountRamdisk::FileBase:: -FileBase(const std::string &basename) : _basename(basename), _timestamp(time(nullptr)) { +FileBase(std::string basename) : _basename(std::move(basename)), _timestamp(time(nullptr)) { } /** @@ -30,8 +30,8 @@ operator < (const FileBase &other) const { * */ INLINE VirtualFileMountRamdisk::File:: -File(const std::string &basename) : - FileBase(basename), +File(std::string basename) : + FileBase(std::move(basename)), _wrapper(&_data, false, true) { } @@ -40,5 +40,5 @@ File(const std::string &basename) : * */ INLINE VirtualFileMountRamdisk::Directory:: -Directory(const std::string &basename) : FileBase(basename) { +Directory(std::string basename) : FileBase(std::move(basename)) { } diff --git a/panda/src/express/virtualFileMountRamdisk.cxx b/panda/src/express/virtualFileMountRamdisk.cxx index 2d0449d41dd..660b7ca0baa 100644 --- a/panda/src/express/virtualFileMountRamdisk.cxx +++ b/panda/src/express/virtualFileMountRamdisk.cxx @@ -397,8 +397,8 @@ scan_directory(vector_string &contents, const Filename &dir) const { */ bool VirtualFileMountRamdisk:: atomic_compare_and_exchange_contents(const Filename &file, string &orig_contents, - const string &old_contents, - const string &new_contents) { + std::string_view old_contents, + std::string_view new_contents) { _lock.lock(); PT(FileBase) f = _root.do_find_file(file); if (f == nullptr || f->is_directory()) { @@ -410,7 +410,7 @@ atomic_compare_and_exchange_contents(const Filename &file, string &orig_contents File *f2 = DCAST(File, f); orig_contents = f2->_data.str(); if (orig_contents == old_contents) { - f2->_data.str(new_contents); + f2->_data.str(std::string(new_contents)); f2->_timestamp = time(nullptr); retval = true; } @@ -475,15 +475,15 @@ is_directory() const { * hierarchy. */ PT(VirtualFileMountRamdisk::FileBase) VirtualFileMountRamdisk::Directory:: -do_find_file(const string &filename) const { +do_find_file(std::string_view filename) const { size_t slash = filename.find('/'); - if (slash == string::npos) { + if (slash == std::string_view::npos) { if (filename.empty()) { return (FileBase *)this; } // Search for a file within the local directory. - FileBase tfile(filename); + FileBase tfile{std::string(filename)}; tfile.local_object(); Files::const_iterator fi = _files.find(&tfile); if (fi != _files.end()) { @@ -493,9 +493,9 @@ do_find_file(const string &filename) const { } // A nested directory. Search for the directory name, then recurse. - string dirname = filename.substr(0, slash); - string remainder = filename.substr(slash + 1); - FileBase tfile(dirname); + std::string dirname(filename.substr(0, slash)); + std::string_view remainder = filename.substr(slash + 1); + FileBase tfile(std::move(dirname)); tfile.local_object(); Files::const_iterator fi = _files.find(&tfile); if (fi != _files.end()) { @@ -513,11 +513,11 @@ do_find_file(const string &filename) const { * hierarchy. If not found, creates a new file. */ PT(VirtualFileMountRamdisk::File) VirtualFileMountRamdisk::Directory:: -do_create_file(const string &filename) { +do_create_file(std::string_view filename) { size_t slash = filename.find('/'); - if (slash == string::npos) { + if (slash == std::string_view::npos) { // Search for a file within the local directory. - FileBase tfile(filename); + FileBase tfile{std::string(filename)}; tfile.local_object(); Files::iterator fi = _files.find(&tfile); if (fi != _files.end()) { @@ -534,16 +534,16 @@ do_create_file(const string &filename) { express_cat.debug() << "Making ramdisk file " << filename << "\n"; } - PT(File) file = new File(filename); + PT(File) file = new File(std::string(filename)); _files.insert(file.p()); _timestamp = time(nullptr); return file; } // A nested directory. Search for the directory name, then recurse. - string dirname = filename.substr(0, slash); - string remainder = filename.substr(slash + 1); - FileBase tfile(dirname); + std::string dirname(filename.substr(0, slash)); + std::string_view remainder = filename.substr(slash + 1); + FileBase tfile(std::move(dirname)); tfile.local_object(); Files::iterator fi = _files.find(&tfile); if (fi != _files.end()) { @@ -561,11 +561,11 @@ do_create_file(const string &filename) { * hierarchy. If not found, creates a new directory. */ PT(VirtualFileMountRamdisk::Directory) VirtualFileMountRamdisk::Directory:: -do_make_directory(const string &filename) { +do_make_directory(std::string_view filename) { size_t slash = filename.find('/'); - if (slash == string::npos) { + if (slash == std::string_view::npos) { // Search for a file within the local directory. - FileBase tfile(filename); + FileBase tfile{std::string(filename)}; tfile.local_object(); Files::iterator fi = _files.find(&tfile); if (fi != _files.end()) { @@ -582,16 +582,16 @@ do_make_directory(const string &filename) { express_cat.debug() << "Making ramdisk directory " << filename << "\n"; } - PT(Directory) file = new Directory(filename); + PT(Directory) file = new Directory(std::string(filename)); _files.insert(file.p()); _timestamp = time(nullptr); return file; } // A nested directory. Search for the directory name, then recurse. - string dirname = filename.substr(0, slash); - string remainder = filename.substr(slash + 1); - FileBase tfile(dirname); + std::string dirname(filename.substr(0, slash)); + std::string_view remainder = filename.substr(slash + 1); + FileBase tfile(std::move(dirname)); tfile.local_object(); Files::iterator fi = _files.find(&tfile); if (fi != _files.end()) { @@ -609,11 +609,11 @@ do_make_directory(const string &filename) { * hierarchy, and removes it. Returns the removed FileBase object. */ PT(VirtualFileMountRamdisk::FileBase) VirtualFileMountRamdisk::Directory:: -do_delete_file(const string &filename) { +do_delete_file(std::string_view filename) { size_t slash = filename.find('/'); - if (slash == string::npos) { + if (slash == std::string_view::npos) { // Search for a file within the local directory. - FileBase tfile(filename); + FileBase tfile{std::string(filename)}; tfile.local_object(); Files::iterator fi = _files.find(&tfile); if (fi != _files.end()) { @@ -633,9 +633,9 @@ do_delete_file(const string &filename) { } // A nested directory. Search for the directory name, then recurse. - string dirname = filename.substr(0, slash); - string remainder = filename.substr(slash + 1); - FileBase tfile(dirname); + std::string dirname(filename.substr(0, slash)); + std::string_view remainder = filename.substr(slash + 1); + FileBase tfile(std::move(dirname)); tfile.local_object(); Files::iterator fi = _files.find(&tfile); if (fi != _files.end()) { diff --git a/panda/src/express/virtualFileMountRamdisk.h b/panda/src/express/virtualFileMountRamdisk.h index ad51e2da982..233bf085da9 100644 --- a/panda/src/express/virtualFileMountRamdisk.h +++ b/panda/src/express/virtualFileMountRamdisk.h @@ -55,7 +55,7 @@ class EXPCL_PANDA_EXPRESS VirtualFileMountRamdisk : public VirtualFileMount { virtual bool scan_directory(vector_string &contents, const Filename &dir) const; - virtual bool atomic_compare_and_exchange_contents(const Filename &file, std::string &orig_contents, const std::string &old_contents, const std::string &new_contents); + virtual bool atomic_compare_and_exchange_contents(const Filename &file, std::string &orig_contents, std::string_view old_contents, std::string_view new_contents); virtual bool atomic_read_contents(const Filename &file, std::string &contents) const; virtual void output(std::ostream &out) const; @@ -67,7 +67,7 @@ class EXPCL_PANDA_EXPRESS VirtualFileMountRamdisk : public VirtualFileMount { class EXPCL_PANDA_EXPRESS FileBase : public TypedReferenceCount { public: - INLINE FileBase(const std::string &basename); + INLINE FileBase(std::string basename); virtual ~FileBase(); INLINE bool operator < (const FileBase &other) const; @@ -96,7 +96,7 @@ class EXPCL_PANDA_EXPRESS VirtualFileMountRamdisk : public VirtualFileMount { class EXPCL_PANDA_EXPRESS File : public FileBase { public: - INLINE File(const std::string &basename); + INLINE File(std::string basename); std::stringstream _data; StreamWrapper _wrapper; @@ -123,14 +123,14 @@ class EXPCL_PANDA_EXPRESS VirtualFileMountRamdisk : public VirtualFileMount { class EXPCL_PANDA_EXPRESS Directory : public FileBase { public: - INLINE Directory(const std::string &basename); + INLINE Directory(std::string basename); virtual bool is_directory() const; - PT(FileBase) do_find_file(const std::string &filename) const; - PT(File) do_create_file(const std::string &filename); - PT(Directory) do_make_directory(const std::string &filename); - PT(FileBase) do_delete_file(const std::string &filename); + PT(FileBase) do_find_file(std::string_view filename) const; + PT(File) do_create_file(std::string_view filename); + PT(Directory) do_make_directory(std::string_view filename); + PT(FileBase) do_delete_file(std::string_view filename); bool do_scan_directory(vector_string &contents) const; Files _files; diff --git a/panda/src/express/virtualFileMountSystem.cxx b/panda/src/express/virtualFileMountSystem.cxx index 2420cb6f88c..fead714c7da 100644 --- a/panda/src/express/virtualFileMountSystem.cxx +++ b/panda/src/express/virtualFileMountSystem.cxx @@ -386,8 +386,8 @@ scan_directory(vector_string &contents, const Filename &dir) const { */ bool VirtualFileMountSystem:: atomic_compare_and_exchange_contents(const Filename &file, string &orig_contents, - const string &old_contents, - const string &new_contents) { + std::string_view old_contents, + std::string_view new_contents) { #ifdef _WIN32 // First ensure that the file exists to validate its case. if (VirtualFileSystem::get_global_ptr()->vfs_case_sensitive) { diff --git a/panda/src/express/virtualFileMountSystem.h b/panda/src/express/virtualFileMountSystem.h index f812b533650..6a413051716 100644 --- a/panda/src/express/virtualFileMountSystem.h +++ b/panda/src/express/virtualFileMountSystem.h @@ -52,7 +52,7 @@ class EXPCL_PANDA_EXPRESS VirtualFileMountSystem : public VirtualFileMount { virtual bool scan_directory(vector_string &contents, const Filename &dir) const; - virtual bool atomic_compare_and_exchange_contents(const Filename &file, std::string &orig_contents, const std::string &old_contents, const std::string &new_contents); + virtual bool atomic_compare_and_exchange_contents(const Filename &file, std::string &orig_contents, std::string_view old_contents, std::string_view new_contents); virtual bool atomic_read_contents(const Filename &file, std::string &contents) const; virtual void output(std::ostream &out) const; diff --git a/panda/src/express/virtualFileSimple.cxx b/panda/src/express/virtualFileSimple.cxx index 11ee94cce9e..feb580272fe 100644 --- a/panda/src/express/virtualFileSimple.cxx +++ b/panda/src/express/virtualFileSimple.cxx @@ -359,8 +359,8 @@ get_system_info(SubfileInfo &info) { */ bool VirtualFileSimple:: atomic_compare_and_exchange_contents(string &orig_contents, - const string &old_contents, - const string &new_contents) { + std::string_view old_contents, + std::string_view new_contents) { return _mount->atomic_compare_and_exchange_contents(_local_filename, orig_contents, old_contents, new_contents); } diff --git a/panda/src/express/virtualFileSimple.h b/panda/src/express/virtualFileSimple.h index 1f8608a2ec4..33e58a3cbec 100644 --- a/panda/src/express/virtualFileSimple.h +++ b/panda/src/express/virtualFileSimple.h @@ -60,7 +60,7 @@ class EXPCL_PANDA_EXPRESS VirtualFileSimple : public VirtualFile { virtual bool get_system_info(SubfileInfo &info); public: - virtual bool atomic_compare_and_exchange_contents(std::string &orig_contents, const std::string &old_contents, const std::string &new_contents); + virtual bool atomic_compare_and_exchange_contents(std::string &orig_contents, std::string_view old_contents, std::string_view new_contents); virtual bool atomic_read_contents(std::string &contents) const; virtual bool read_file(vector_uchar &result, bool auto_unwrap) const; diff --git a/panda/src/express/virtualFileSystem.I b/panda/src/express/virtualFileSystem.I index 713b9921470..d695bb77b47 100644 --- a/panda/src/express/virtualFileSystem.I +++ b/panda/src/express/virtualFileSystem.I @@ -110,7 +110,7 @@ read_file(const Filename &filename, bool auto_unwrap) const { * compressed while writing. */ INLINE bool VirtualFileSystem:: -write_file(const Filename &filename, const std::string &data, bool auto_wrap) { +write_file(const Filename &filename, std::string_view data, bool auto_wrap) { return write_file(filename, (const unsigned char *)data.data(), data.size(), auto_wrap); } diff --git a/panda/src/express/virtualFileSystem.cxx b/panda/src/express/virtualFileSystem.cxx index 1f67b98840a..f90b54c41d8 100644 --- a/panda/src/express/virtualFileSystem.cxx +++ b/panda/src/express/virtualFileSystem.cxx @@ -130,7 +130,7 @@ mount(ZipArchive *archive, const Filename &mount_point, int flags) { */ bool VirtualFileSystem:: mount(const Filename &physical_filename, const Filename &mount_point, - int flags, const string &password) { + int flags, std::string password) { if (!physical_filename.exists()) { express_cat->warning() << "Attempt to mount " << physical_filename << ", not found.\n"; @@ -184,7 +184,7 @@ mount(const Filename &physical_filename, const Filename &mount_point, close_read_file(stream); PT(Multifile) multifile = new Multifile; - multifile->set_encryption_password(password); + multifile->set_encryption_password(std::move(password)); if (!multifile->open_read(physical_filename)) { return false; @@ -221,7 +221,7 @@ mount(const Filename &physical_filename, const Filename &mount_point, */ bool VirtualFileSystem:: mount_loop(const Filename &virtual_filename, const Filename &mount_point, - int flags, const string &password) { + int flags, std::string password) { PT(VirtualFile) file = get_file(virtual_filename, false); if (file == nullptr) { express_cat->warning() @@ -237,7 +237,7 @@ mount_loop(const Filename &virtual_filename, const Filename &mount_point, } else { // It's not a directory; it must be a Multifile. PT(Multifile) multifile = new Multifile; - multifile->set_encryption_password(password); + multifile->set_encryption_password(std::move(password)); // For now these are always opened read only. Maybe later we'll support // read-write on Multifiles. @@ -750,7 +750,7 @@ copy_file(const Filename &orig_filename, const Filename &new_filename) { bool VirtualFileSystem:: resolve_filename(Filename &filename, const DSearchPath &searchpath, - const string &default_extension) const { + std::string_view default_extension) const { PT(VirtualFile) found; if (filename.is_local()) { @@ -1153,8 +1153,8 @@ close_read_write_file(iostream *stream) { */ bool VirtualFileSystem:: atomic_compare_and_exchange_contents(const Filename &filename, string &orig_contents, - const string &old_contents, - const string &new_contents) { + std::string_view old_contents, + std::string_view new_contents) { PT(VirtualFile) file = create_file(filename); if (file == nullptr) { return false; @@ -1222,14 +1222,14 @@ scan_mount_points(vector_string &names, const Filename &path) const { * Config.prc line. */ void VirtualFileSystem:: -parse_options(const string &options, int &flags, string &password) { +parse_options(std::string_view options, int &flags, string &password) { flags = 0; password = string(); // Split the options up by commas. size_t p = 0; size_t q = options.find(',', p); - while (q != string::npos) { + while (q != std::string_view::npos) { parse_option(options.substr(p, q - p), flags, password); p = q + 1; @@ -1243,7 +1243,7 @@ parse_options(const string &options, int &flags, string &password) { * Config.prc line. */ void VirtualFileSystem:: -parse_option(const string &option, int &flags, string &password) { +parse_option(std::string_view option, int &flags, string &password) { if (option == "0" || option.empty()) { // 0 is the null option. } else if (option == "ro") { diff --git a/panda/src/express/virtualFileSystem.h b/panda/src/express/virtualFileSystem.h index 0eb78bc85ce..5de540270f9 100644 --- a/panda/src/express/virtualFileSystem.h +++ b/panda/src/express/virtualFileSystem.h @@ -50,9 +50,9 @@ class EXPCL_PANDA_EXPRESS VirtualFileSystem { BLOCKING bool mount(Multifile *multifile, const Filename &mount_point, int flags); BLOCKING bool mount(ZipArchive *archive, const Filename &mount_point, int flags); BLOCKING bool mount(const Filename &physical_filename, const Filename &mount_point, - int flags, const std::string &password = ""); + int flags, std::string password = ""); BLOCKING bool mount_loop(const Filename &virtual_filename, const Filename &mount_point, - int flags, const std::string &password = ""); + int flags, std::string password = ""); bool mount(VirtualFileMount *mount, const Filename &mount_point, int flags); BLOCKING int unmount(Multifile *multifile); BLOCKING int unmount(ZipArchive *archive); @@ -81,7 +81,7 @@ class EXPCL_PANDA_EXPRESS VirtualFileSystem { BLOCKING bool copy_file(const Filename &orig_filename, const Filename &new_filename); BLOCKING bool resolve_filename(Filename &filename, const DSearchPath &searchpath, - const std::string &default_extension = std::string()) const; + std::string_view default_extension = std::string_view()) const; BLOCKING int find_all_files(const Filename &filename, const DSearchPath &searchpath, DSearchPath::Results &results) const; @@ -99,25 +99,25 @@ class EXPCL_PANDA_EXPRESS VirtualFileSystem { static VirtualFileSystem *get_global_ptr(); PY_EXTENSION(PyObject *read_file(const Filename &filename, bool auto_unwrap) const); - BLOCKING std::istream *open_read_file(const Filename &filename, bool auto_unwrap) const; + [[nodiscard]] BLOCKING std::istream *open_read_file(const Filename &filename, bool auto_unwrap) const; BLOCKING static void close_read_file(std::istream *stream); PY_EXTENSION(PyObject *write_file(const Filename &filename, PyObject *data, bool auto_wrap)); - BLOCKING std::ostream *open_write_file(const Filename &filename, bool auto_wrap, bool truncate); - BLOCKING std::ostream *open_append_file(const Filename &filename); + [[nodiscard]] BLOCKING std::ostream *open_write_file(const Filename &filename, bool auto_wrap, bool truncate); + [[nodiscard]] BLOCKING std::ostream *open_append_file(const Filename &filename); BLOCKING static void close_write_file(std::ostream *stream); - BLOCKING std::iostream *open_read_write_file(const Filename &filename, bool truncate); - BLOCKING std::iostream *open_read_append_file(const Filename &filename); + [[nodiscard]] BLOCKING std::iostream *open_read_write_file(const Filename &filename, bool truncate); + [[nodiscard]] BLOCKING std::iostream *open_read_append_file(const Filename &filename); BLOCKING static void close_read_write_file(std::iostream *stream); public: // We provide Python versions of these as efficient extension methods, // above. BLOCKING INLINE std::string read_file(const Filename &filename, bool auto_unwrap) const; - BLOCKING INLINE bool write_file(const Filename &filename, const std::string &data, bool auto_wrap); + BLOCKING INLINE bool write_file(const Filename &filename, std::string_view data, bool auto_wrap); - bool atomic_compare_and_exchange_contents(const Filename &filename, std::string &orig_contents, const std::string &old_contents, const std::string &new_contents); + bool atomic_compare_and_exchange_contents(const Filename &filename, std::string &orig_contents, std::string_view old_contents, std::string_view new_contents); bool atomic_read_contents(const Filename &filename, std::string &contents) const; INLINE bool read_file(const Filename &filename, std::string &result, bool auto_unwrap) const; @@ -126,9 +126,9 @@ class EXPCL_PANDA_EXPRESS VirtualFileSystem { void scan_mount_points(vector_string &names, const Filename &path) const; - static void parse_options(const std::string &options, + static void parse_options(std::string_view options, int &flags, std::string &password); - static void parse_option(const std::string &option, + static void parse_option(std::string_view option, int &flags, std::string &password); public: diff --git a/panda/src/express/windowsRegistry.cxx b/panda/src/express/windowsRegistry.cxx index 4461f1694a6..dcd56a9a671 100644 --- a/panda/src/express/windowsRegistry.cxx +++ b/panda/src/express/windowsRegistry.cxx @@ -30,7 +30,7 @@ using std::string; * registry key must already exist prior to calling this function. */ bool WindowsRegistry:: -set_string_value(const string &key, const string &name, const string &value, +set_string_value(const string &key, const string &name, std::string_view value, WindowsRegistry::RegLevel rl) { TextEncoder encoder; @@ -116,19 +116,19 @@ get_key_type(const string &key, const string &name, */ string WindowsRegistry:: get_string_value(const string &key, const string &name, - const string &default_value, + std::string_view default_value, WindowsRegistry::RegLevel rl) { int data_type; string data; if (!do_get(key, name, data_type, data, rl)) { - return default_value; + return std::string(default_value); } if (data_type != REG_SZ) { express_cat.warning() << "Registry key " << key << " does not contain a string value.\n"; - return default_value; + return std::string(default_value); } // Now we have to decode the MultiByte string to Unicode, and re-encode it diff --git a/panda/src/express/windowsRegistry.h b/panda/src/express/windowsRegistry.h index 9176f940a48..06a8b5ad0a5 100644 --- a/panda/src/express/windowsRegistry.h +++ b/panda/src/express/windowsRegistry.h @@ -34,7 +34,7 @@ class EXPCL_PANDA_EXPRESS WindowsRegistry }; static bool set_string_value(const std::string &key, const std::string &name, - const std::string &value, RegLevel rl = rl_machine); + std::string_view value, RegLevel rl = rl_machine); static bool set_int_value(const std::string &key, const std::string &name, int value, RegLevel rl = rl_machine); enum Type { @@ -44,7 +44,7 @@ class EXPCL_PANDA_EXPRESS WindowsRegistry }; static Type get_key_type(const std::string &key, const std::string &name, RegLevel rl = rl_machine); static std::string get_string_value(const std::string &key, const std::string &name, - const std::string &default_value, RegLevel rl = rl_machine); + std::string_view default_value, RegLevel rl = rl_machine); static int get_int_value(const std::string &key, const std::string &name, int default_value, RegLevel rl = rl_machine); diff --git a/panda/src/express/zStreamBuf.cxx b/panda/src/express/zStreamBuf.cxx index be2b68fda8d..0ef35134f60 100644 --- a/panda/src/express/zStreamBuf.cxx +++ b/panda/src/express/zStreamBuf.cxx @@ -44,17 +44,10 @@ ZStreamBuf() { _dest = nullptr; _owns_dest = false; -#ifdef PHAVE_IOSTREAM _buffer = (char *)PANDA_MALLOC_ARRAY(4096); char *ebuf = _buffer + 4096; setg(_buffer, ebuf, ebuf); setp(_buffer, ebuf); - -#else - allocate(); - setg(base(), ebuf(), ebuf()); - setp(base(), ebuf()); -#endif } /** @@ -64,9 +57,7 @@ ZStreamBuf:: ~ZStreamBuf() { close_read(); close_write(); -#ifdef PHAVE_IOSTREAM PANDA_FREE_ARRAY(_buffer); -#endif } /** diff --git a/panda/src/express/zipArchive.I b/panda/src/express/zipArchive.I index ae8c25a85ad..b989a72b156 100644 --- a/panda/src/express/zipArchive.I +++ b/panda/src/express/zipArchive.I @@ -92,7 +92,7 @@ get_record_timestamp() const { * reduced in size after this operation, until the next call to repack(). */ INLINE bool ZipArchive:: -remove_subfile(const std::string &subfile_name) { +remove_subfile(std::string_view subfile_name) { int index = find_subfile(subfile_name); if (index >= 0) { remove_subfile(index); diff --git a/panda/src/express/zipArchive.cxx b/panda/src/express/zipArchive.cxx index 9008143159a..652e5ba6e9b 100644 --- a/panda/src/express/zipArchive.cxx +++ b/panda/src/express/zipArchive.cxx @@ -316,7 +316,7 @@ close() { * or empty string on failure. */ std::string ZipArchive:: -add_subfile(const std::string &subfile_name, const Filename &filename, +add_subfile(std::string_view subfile_name, const Filename &filename, int compression_level, size_t data_alignment) { nassertr(is_write_valid(), std::string()); @@ -355,7 +355,7 @@ add_subfile(const std::string &subfile_name, const Filename &filename, * or empty string on failure. */ std::string ZipArchive:: -add_subfile(const std::string &subfile_name, std::istream *subfile_data, +add_subfile(std::string_view subfile_name, std::istream *subfile_data, int compression_level, size_t data_alignment) { nassertr(is_write_valid(), string()); @@ -367,7 +367,7 @@ add_subfile(const std::string &subfile_name, std::istream *subfile_data, std::string name = standardize_subfile_name(subfile_name); if (!name.empty()) { - Subfile *subfile = new Subfile(subfile_name, compression_level, data_alignment); + Subfile *subfile = new Subfile(name, compression_level, data_alignment); // Write it straight away, overwriting the index at the end of the file. // This index will be rewritten at the next call to flush() or close(). @@ -405,7 +405,7 @@ add_subfile(const std::string &subfile_name, std::istream *subfile_data, * called, the text flag will be set on the subfile. */ string ZipArchive:: -update_subfile(const std::string &subfile_name, const Filename &filename, +update_subfile(std::string_view subfile_name, const Filename &filename, int compression_level, size_t data_alignment) { nassertr(is_write_valid(), string()); @@ -460,7 +460,7 @@ update_subfile(const std::string &subfile_name, const Filename &filename, */ bool ZipArchive:: add_jar_signature(const Filename &certificate, const Filename &pkey, - const string &password, const string &alias) { + const string &password, std::string_view alias) { VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); // Read the certificate file from VFS. First, read the complete file into @@ -528,7 +528,7 @@ add_jar_signature(const Filename &certificate, const Filename &pkey, * The private key is expected to match the first certificate in the chain. */ bool ZipArchive:: -add_jar_signature(X509 *cert, EVP_PKEY *pkey, const std::string &alias) { +add_jar_signature(X509 *cert, EVP_PKEY *pkey, std::string_view alias) { nassertr(is_write_valid() && is_read_valid(), false); nassertr(cert != nullptr, false); nassertr(pkey != nullptr, false); @@ -835,7 +835,7 @@ get_num_subfiles() const { * named subfile is not within the ZipArchive. */ int ZipArchive:: -find_subfile(const std::string &subfile_name) const { +find_subfile(std::string_view subfile_name) const { Subfile find_subfile; find_subfile._name = standardize_subfile_name(subfile_name); Subfiles::const_iterator fi; @@ -853,8 +853,8 @@ find_subfile(const std::string &subfile_name) const { * least one file named "subfile_name/...". */ bool ZipArchive:: -has_directory(const std::string &subfile_name) const { - string prefix = subfile_name; +has_directory(std::string subfile_name) const { + string prefix = std::move(subfile_name); if (!prefix.empty()) { prefix += '/'; } @@ -885,8 +885,8 @@ has_directory(const std::string &subfile_name) const { * Returns true if successful, false otherwise. */ bool ZipArchive:: -scan_directory(vector_string &contents, const std::string &subfile_name) const { - string prefix = subfile_name; +scan_directory(vector_string &contents, std::string subfile_name) const { + string prefix = std::move(subfile_name); if (!prefix.empty()) { prefix += '/'; } @@ -1221,11 +1221,11 @@ ls(std::ostream &out) const { * This string may not be longer than 65535 characters. */ void ZipArchive:: -set_comment(const std::string &comment) { +set_comment(std::string comment) { nassertv(comment.size() <= 65535); if (_comment != comment) { - _comment = comment; + _comment = std::move(comment); _index_changed = true; } } @@ -1401,8 +1401,8 @@ open_read_subfile(Subfile *subfile) { * Returns the standard form of the subfile name. */ string ZipArchive:: -standardize_subfile_name(const std::string &subfile_name) const { - Filename name = subfile_name; +standardize_subfile_name(std::string_view subfile_name) const { + Filename name(subfile_name); name.standardize(); if (name.empty() || name == "/") { // Invalid empty name. @@ -1669,14 +1669,14 @@ write_index(std::ostream &write, std::streampos &fpos) { * Creates a new subfile record. */ ZipArchive::Subfile:: -Subfile(const std::string &name, int compression_level, size_t data_alignment) : - _name(name), +Subfile(std::string name, int compression_level, size_t data_alignment) : + _name(std::move(name)), _timestamp(dos_epoch), _compression_method((compression_level > 0) ? CM_deflate : CM_store), _data_alignment(data_alignment) { // If the name contains any non-ASCII characters, we set the UTF-8 flag. - for (char c : name) { + for (char c : _name) { if (c & ~0x7f) { _flags |= SF_utf8_encoding; break; diff --git a/panda/src/express/zipArchive.h b/panda/src/express/zipArchive.h index 23a17594c66..7b5c40d42e3 100644 --- a/panda/src/express/zipArchive.h +++ b/panda/src/express/zipArchive.h @@ -65,29 +65,28 @@ class EXPCL_PANDA_EXPRESS ZipArchive : public ReferenceCount { INLINE void set_record_timestamp(bool record_timestamp); INLINE bool get_record_timestamp() const; - std::string add_subfile(const std::string &subfile_name, const Filename &filename, + std::string add_subfile(std::string_view subfile_name, const Filename &filename, int compression_level, size_t data_alignment=0); - std::string add_subfile(const std::string &subfile_name, std::istream *subfile_data, + std::string add_subfile(std::string_view subfile_name, std::istream *subfile_data, int compression_level, size_t data_alignment=0); - std::string update_subfile(const std::string &subfile_name, const Filename &filename, + std::string update_subfile(std::string_view subfile_name, const Filename &filename, int compression_level, size_t data_alignment=0); #ifdef HAVE_OPENSSL bool add_jar_signature(const Filename &certificate, const Filename &pkey, const std::string &password = "", - const std::string &alias = "cert"); + std::string_view alias = "cert"); #endif BLOCKING bool flush(); BLOCKING bool repack(); int get_num_subfiles() const; - int find_subfile(const std::string &subfile_name) const; - bool has_directory(const std::string &subfile_name) const; - bool scan_directory(vector_string &contents, - const std::string &subfile_name) const; + int find_subfile(std::string_view subfile_name) const; + bool has_directory(std::string subfile_name) const; + bool scan_directory(vector_string &contents, std::string subfile_name) const; void remove_subfile(int index); - INLINE bool remove_subfile(const std::string &subfile_name); + INLINE bool remove_subfile(std::string_view subfile_name); const std::string &get_subfile_name(int index) const; MAKE_SEQ(get_subfile_names, get_num_subfiles, get_subfile_name); size_t get_subfile_length(int index) const; @@ -108,12 +107,12 @@ class EXPCL_PANDA_EXPRESS ZipArchive : public ReferenceCount { void output(std::ostream &out) const; void ls(std::ostream &out = std::cout) const; - void set_comment(const std::string &comment); + void set_comment(std::string comment); INLINE const std::string &get_comment() const; public: #ifdef HAVE_OPENSSL - bool add_jar_signature(X509 *cert, EVP_PKEY *pkey, const std::string &alias); + bool add_jar_signature(X509 *cert, EVP_PKEY *pkey, std::string_view alias); #endif // HAVE_OPENSSL bool read_subfile(int index, std::string &result); @@ -152,7 +151,7 @@ class EXPCL_PANDA_EXPRESS ZipArchive : public ReferenceCount { class Subfile { public: Subfile() = default; - Subfile(const std::string &name, int compression_level, + Subfile(std::string name, int compression_level, size_t data_alignment=0); INLINE bool operator < (const Subfile &other) const; @@ -186,7 +185,7 @@ class EXPCL_PANDA_EXPRESS ZipArchive : public ReferenceCount { void add_new_subfile(Subfile *subfile, int compression_level); std::istream *open_read_subfile(Subfile *subfile); - std::string standardize_subfile_name(const std::string &subfile_name) const; + std::string standardize_subfile_name(std::string_view subfile_name) const; void clear_subfiles(); bool read_index(); diff --git a/panda/src/framework/pandaFramework.I b/panda/src/framework/pandaFramework.I index 24e6bc3644c..ab9c6177a9a 100644 --- a/panda/src/framework/pandaFramework.I +++ b/panda/src/framework/pandaFramework.I @@ -57,8 +57,8 @@ get_task_mgr() { * Specifies the title that is set for all subsequently created windows. */ INLINE void PandaFramework:: -set_window_title(const std::string &title) { - _window_title = title; +set_window_title(std::string title) { + _window_title = std::move(title); } /** diff --git a/panda/src/framework/pandaFramework.cxx b/panda/src/framework/pandaFramework.cxx index 32de3dda768..0361f8018ec 100644 --- a/panda/src/framework/pandaFramework.cxx +++ b/panda/src/framework/pandaFramework.cxx @@ -299,7 +299,7 @@ remove_mouse(const GraphicsOutput *window) { * description of the function of the key, for display to the user. */ void PandaFramework:: -define_key(const string &event_name, const string &description, +define_key(std::string_view event_name, std::string description, EventHandler::EventCallbackFunction *function, void *data) { if (_event_handler.has_hook(event_name)) { @@ -322,8 +322,8 @@ define_key(const string &event_name, const string &description, if (!description.empty()) { KeyDefinition keydef; keydef._event_name = event_name; - keydef._description = description; - _key_definitions.push_back(keydef); + keydef._description = std::move(description); + _key_definitions.push_back(std::move(keydef)); } } @@ -333,7 +333,7 @@ define_key(const string &event_name, const string &description, * description of the function of the key, for display to the user. */ void PandaFramework:: -define_key(const string &event_name, const string &description, +define_key(std::string_view event_name, std::string description, EventHandler::EventLambda function) { if (_event_handler.has_hook(event_name)) { // If there is already a hook for the indicated keyname, we're most likely @@ -355,8 +355,8 @@ define_key(const string &event_name, const string &description, if (!description.empty()) { KeyDefinition keydef; keydef._event_name = event_name; - keydef._description = description; - _key_definitions.push_back(keydef); + keydef._description = std::move(description); + _key_definitions.push_back(std::move(keydef)); } } diff --git a/panda/src/framework/pandaFramework.h b/panda/src/framework/pandaFramework.h index 80f1d1e2151..f4f499773f7 100644 --- a/panda/src/framework/pandaFramework.h +++ b/panda/src/framework/pandaFramework.h @@ -53,15 +53,15 @@ class EXPCL_FRAMEWORK PandaFramework { NodePath get_mouse(GraphicsOutput *window); void remove_mouse(const GraphicsOutput *window); - void define_key(const std::string &event_name, - const std::string &description, + void define_key(std::string_view event_name, + std::string description, EventHandler::EventCallbackFunction *function, void *data); - void define_key(const std::string &event_name, - const std::string &description, + void define_key(std::string_view event_name, + std::string description, EventHandler::EventLambda function); - INLINE void set_window_title(const std::string &title); + INLINE void set_window_title(std::string title); virtual void get_default_window_props(WindowProperties &props); WindowFramework *open_window(); diff --git a/panda/src/framework/windowFramework.cxx b/panda/src/framework/windowFramework.cxx index 69a84db74c8..34fe286ad12 100644 --- a/panda/src/framework/windowFramework.cxx +++ b/panda/src/framework/windowFramework.cxx @@ -1547,9 +1547,9 @@ update_anim_controls() { * etc.). */ void WindowFramework:: -setup_shuttle_button(const string &label, int index, +setup_shuttle_button(std::string_view label, int index, EventHandler::EventCallbackFunction *func) { - PT(PGButton) button = new PGButton(label); + PT(PGButton) button = new PGButton(std::string(label)); button->set_frame(-0.05f, 0.05f, 0.0f, 0.07f); PN_stdfloat bevel = 0.005f; diff --git a/panda/src/framework/windowFramework.h b/panda/src/framework/windowFramework.h index 84f7e163c7d..b9304956715 100644 --- a/panda/src/framework/windowFramework.h +++ b/panda/src/framework/windowFramework.h @@ -157,7 +157,7 @@ class EXPCL_FRAMEWORK WindowFramework : public TypedWritableReferenceCount { void destroy_anim_controls(); void update_anim_controls(); - void setup_shuttle_button(const std::string &label, int index, + void setup_shuttle_button(std::string_view label, int index, EventHandler::EventCallbackFunction *func); void back_button(); void pause_button(); diff --git a/panda/src/glstuff/glGraphicsBuffer_src.cxx b/panda/src/glstuff/glGraphicsBuffer_src.cxx index 9a38590b8b7..bba45754bf6 100644 --- a/panda/src/glstuff/glGraphicsBuffer_src.cxx +++ b/panda/src/glstuff/glGraphicsBuffer_src.cxx @@ -35,13 +35,13 @@ TypeHandle CLP(GraphicsBuffer)::_type_handle; */ CLP(GraphicsBuffer):: CLP(GraphicsBuffer)(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsBuffer(engine, pipe, name, without_back_buffers(fb_prop), win_prop, flags, gsg, host), + GraphicsBuffer(engine, pipe, std::move(name), without_back_buffers(fb_prop), win_prop, flags, gsg, host), _requested_multisamples(0), _requested_coverage_samples(0), _rb_context(nullptr), @@ -1570,7 +1570,7 @@ attach_tex(GLenum attachpoint, CLP(TextureContext) *gtc, int view, int layer) { #endif case GL_TEXTURE_CUBE_MAP: target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + layer; - // fall through + [[fallthrough]]; default: glgsg->_glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, attachpoint, target, index, 0); diff --git a/panda/src/glstuff/glGraphicsBuffer_src.h b/panda/src/glstuff/glGraphicsBuffer_src.h index f718e134f85..e1fbf942551 100644 --- a/panda/src/glstuff/glGraphicsBuffer_src.h +++ b/panda/src/glstuff/glGraphicsBuffer_src.h @@ -52,7 +52,7 @@ class EXPCL_GL CLP(GraphicsBuffer) : public GraphicsBuffer { public: CLP(GraphicsBuffer)(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.I b/panda/src/glstuff/glGraphicsStateGuardian_src.I index dd0afb1ce3d..cac7475e9bb 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.I +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.I @@ -15,7 +15,7 @@ * If debug markers are enabled, pushes the beginning of a group marker. */ INLINE void CLP(GraphicsStateGuardian):: -push_group_marker(const std::string &marker) { +push_group_marker(std::string_view marker) { #if !defined(NDEBUG) && !defined(OPENGLES_1) if (_glPushGroupMarker != nullptr) { _glPushGroupMarker(marker.size(), marker.data()); @@ -214,7 +214,7 @@ maybe_gl_finish() const { * otherwise. The extension name is case-sensitive. */ INLINE bool CLP(GraphicsStateGuardian):: -has_extension(const std::string &extension) const { +has_extension(std::string_view extension) const { bool has_ext = (_extensions.find(extension) != _extensions.end()); #ifndef NDEBUG if (GLCAT.is_debug()) { diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index c015abd4f0e..d7b9b47f033 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -9311,7 +9311,7 @@ do_issue_material() { call_glMaterialfv(face, GL_SPECULAR, material->get_specular()); call_glMaterialfv(face, GL_EMISSION, material->get_emission()); - glMaterialf(face, GL_SHININESS, max(min(material->get_shininess(), (PN_stdfloat)128), (PN_stdfloat)0)); + glMaterialf(face, GL_SHININESS, std::clamp(material->get_shininess(), (PN_stdfloat)0, (PN_stdfloat)128)); if ((material->has_ambient() && material->has_diffuse()) || material->has_base_color()) { // The material has both an ambient and diffuse specified. This means we @@ -9732,7 +9732,7 @@ bind_light(Spotlight *light_obj, const NodePath &light, int light_id) { call_glLightfv(id, GL_POSITION, fpos); call_glLightfv(id, GL_SPOT_DIRECTION, dir); - glLightf(id, GL_SPOT_EXPONENT, max(min(light_obj->get_exponent(), (PN_stdfloat)128), (PN_stdfloat)0)); + glLightf(id, GL_SPOT_EXPONENT, std::clamp(light_obj->get_exponent(), (PN_stdfloat)0, (PN_stdfloat)128)); glLightf(id, GL_SPOT_CUTOFF, lens->get_hfov() * 0.5f); const LVecBase3 &att = light_obj->get_attenuation(); @@ -9938,7 +9938,7 @@ get_error_string(GLenum error_code) { * string is returned. */ string CLP(GraphicsStateGuardian):: -show_gl_string(const string &name, GLenum id) { +show_gl_string(std::string_view name, GLenum id) { string result; const GLubyte *text = glGetString(id); @@ -10141,14 +10141,13 @@ report_extensions() const { std::ostream &out = GLCAT.debug(); out << "GL Extensions:\n"; - pset::const_iterator ei; - for (ei = _extensions.begin(); ei != _extensions.end(); ++ei) { + for (auto ei = _extensions.cbegin(); ei != _extensions.cend(); ++ei) { size_t len = (*ei).size(); out << " " << (*ei); // Display a second column. if (len <= 38) { - if (++ei != _extensions.end()) { + if (++ei != _extensions.cend()) { for (int i = len; i < 38; ++i) { out.put(' '); } @@ -10945,7 +10944,8 @@ get_external_image_format(Texture *tex) const { #ifdef OPENGLES return GL_ETC1_RGB8_OES; #endif - // Fall through - ETC2 is backward compatible + // ETC2 is backward compatible. + [[fallthrough]]; case Texture::CM_etc2: if (format == Texture::F_rgbm) { return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; @@ -11460,7 +11460,8 @@ get_internal_image_format(Texture *tex, bool force_sized) const { #ifdef OPENGLES return GL_ETC1_RGB8_OES; #endif - // Fall through - ETC2 is backward compatible + // ETC2 is backward compatible. + [[fallthrough]]; case Texture::CM_etc2: if (format == Texture::F_rgbm) { return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2; @@ -11524,7 +11525,7 @@ get_internal_image_format(Texture *tex, bool force_sized) const { return force_sized ? GL_DEPTH24_STENCIL8 : GL_DEPTH_STENCIL; } } - // Fall through. + [[fallthrough]]; case Texture::F_depth_component: #ifndef OPENGLES @@ -12020,7 +12021,7 @@ GLint CLP(GraphicsStateGuardian):: get_texture_combine_type(TextureStage::CombineMode cm) { #ifdef SUPPORT_FIXED_FUNCTION switch (cm) { - case TextureStage::CM_undefined: // fall through + case TextureStage::CM_undefined: [[fallthrough]]; case TextureStage::CM_replace: return GL_REPLACE; case TextureStage::CM_modulate: return GL_MODULATE; case TextureStage::CM_add: return GL_ADD; @@ -12046,7 +12047,7 @@ get_texture_src_type(TextureStage::CombineSource cs, int this_stage) const { #ifdef SUPPORT_FIXED_FUNCTION switch (cs) { - case TextureStage::CS_undefined: // fall through + case TextureStage::CS_undefined: [[fallthrough]]; case TextureStage::CS_texture: return GL_TEXTURE; case TextureStage::CS_constant: return GL_CONSTANT; case TextureStage::CS_primary_color: return GL_PRIMARY_COLOR; @@ -12092,7 +12093,7 @@ get_texture_src_type(TextureStage::CombineSource cs, GLint CLP(GraphicsStateGuardian):: get_texture_operand_type(TextureStage::CombineOperand co) { switch (co) { - case TextureStage::CO_undefined: // fall through + case TextureStage::CO_undefined: [[fallthrough]]; case TextureStage::CO_src_alpha: return GL_SRC_ALPHA; case TextureStage::CO_one_minus_src_alpha: return GL_ONE_MINUS_SRC_ALPHA; case TextureStage::CO_src_color: return GL_SRC_COLOR; @@ -13332,7 +13333,7 @@ update_standard_texture_bindings() { last_stage, last_saved_result, i)); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, get_texture_operand_type(stage->get_combine_rgb_operand2())); - // fall through + [[fallthrough]]; case 2: glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, @@ -13340,7 +13341,7 @@ update_standard_texture_bindings() { last_stage, last_saved_result, i)); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, get_texture_operand_type(stage->get_combine_rgb_operand1())); - // fall through + [[fallthrough]]; case 1: glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, @@ -13348,7 +13349,7 @@ update_standard_texture_bindings() { last_stage, last_saved_result, i)); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, get_texture_operand_type(stage->get_combine_rgb_operand0())); - // fall through + [[fallthrough]]; default: break; @@ -13363,7 +13364,7 @@ update_standard_texture_bindings() { last_stage, last_saved_result, i)); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, get_texture_operand_type(stage->get_combine_alpha_operand2())); - // fall through + [[fallthrough]]; case 2: glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, @@ -13371,7 +13372,7 @@ update_standard_texture_bindings() { last_stage, last_saved_result, i)); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, get_texture_operand_type(stage->get_combine_alpha_operand1())); - // fall through + [[fallthrough]]; case 1: glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, @@ -13379,7 +13380,7 @@ update_standard_texture_bindings() { last_stage, last_saved_result, i)); glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, get_texture_operand_type(stage->get_combine_alpha_operand0())); - // fall through + [[fallthrough]]; default: break; diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index 844648f8d53..1d05424d951 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -290,7 +290,7 @@ class EXPCL_GL CLP(GraphicsStateGuardian) : public GraphicsStateGuardian { static void APIENTRY debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, GLvoid *userParam); - INLINE virtual void push_group_marker(const std::string &marker) final; + INLINE virtual void push_group_marker(std::string_view marker) final; INLINE virtual void pop_group_marker() final; virtual void reset(); @@ -514,13 +514,13 @@ class EXPCL_GL CLP(GraphicsStateGuardian) : public GraphicsStateGuardian { static bool report_errors_loop(int line, const char *source_file, GLenum error_code, int &error_count); static std::string get_error_string(GLenum error_code); - std::string show_gl_string(const std::string &name, GLenum id); + std::string show_gl_string(std::string_view name, GLenum id); virtual void query_gl_version(); void query_glsl_version(); void save_extensions(const char *extensions); virtual void get_extra_extensions(); void report_extensions() const; - INLINE virtual bool has_extension(const std::string &extension) const; + INLINE virtual bool has_extension(std::string_view extension) const; INLINE bool is_at_least_gl_version(int major_version, int minor_version) const; INLINE bool is_at_least_gles_version(int major_version, int minor_version) const; void *get_extension_func(const char *name); @@ -823,7 +823,7 @@ class EXPCL_GL CLP(GraphicsStateGuardian) : public GraphicsStateGuardian { // #--- Zhao Nov2011 int _gl_shadlang_ver_major, _gl_shadlang_ver_minor; - pset _extensions; + pset> _extensions; #ifndef OPENGLES // True for non-compatibility GL 3.2+ contexts. diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index 5312956fe12..54ce8fc2dae 100644 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -1695,7 +1695,8 @@ reflect_uniform(int i, char *name_buffer, GLsizei name_buflen) { bind._arg[1] = nullptr; _shader->cp_add_mat_spec(bind); return; - } // else fall through + } + [[fallthrough]]; } case GL_BOOL: case GL_BOOL_VEC2: @@ -2023,7 +2024,7 @@ get_sampler_texture_type(int &out, GLenum param_type) { << "GLSL shader uses shadow sampler, which is unsupported by the driver.\n"; return false; } - // Fall through + [[fallthrough]]; case GL_INT_SAMPLER_1D: case GL_UNSIGNED_INT_SAMPLER_1D: case GL_SAMPLER_1D: @@ -2070,7 +2071,7 @@ get_sampler_texture_type(int &out, GLenum param_type) { << "GLSL shader uses shadow sampler, which is unsupported by the driver.\n"; return false; } - // Fall through + [[fallthrough]]; case GL_INT_SAMPLER_CUBE: case GL_UNSIGNED_INT_SAMPLER_CUBE: case GL_SAMPLER_CUBE: @@ -2088,7 +2089,7 @@ get_sampler_texture_type(int &out, GLenum param_type) { << "GLSL shader uses shadow sampler, which is unsupported by the driver.\n"; return false; } - // Fall through + [[fallthrough]]; case GL_INT_SAMPLER_2D_ARRAY: case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: case GL_SAMPLER_2D_ARRAY: @@ -2107,7 +2108,7 @@ get_sampler_texture_type(int &out, GLenum param_type) { << "GLSL shader uses shadow sampler, which is unsupported by the driver.\n"; return false; } - // Fall through + [[fallthrough]]; case GL_INT_SAMPLER_CUBE_MAP_ARRAY: case GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY: case GL_SAMPLER_CUBE_MAP_ARRAY: diff --git a/panda/src/glstuff/glTextureContext_src.I b/panda/src/glstuff/glTextureContext_src.I index a0a986e80f9..4032d9abd51 100644 --- a/panda/src/glstuff/glTextureContext_src.I +++ b/panda/src/glstuff/glTextureContext_src.I @@ -45,7 +45,7 @@ CLP(TextureContext)(CLP(GraphicsStateGuardian) *glgsg, */ INLINE GLuint CLP(TextureContext):: get_view_index(int view) const { - return _indices[std::min(std::max(view, 0), _num_views - 1)]; + return _indices[std::clamp(view, 0, _num_views - 1)]; } /** @@ -54,7 +54,7 @@ get_view_index(int view) const { INLINE GLuint CLP(TextureContext):: get_view_buffer(int view) const { if (_buffers != nullptr) { - return _buffers[std::min(std::max(view, 0), _num_views - 1)]; + return _buffers[std::clamp(view, 0, _num_views - 1)]; } else { return 0; } diff --git a/panda/src/glxdisplay/glxGraphicsBuffer.cxx b/panda/src/glxdisplay/glxGraphicsBuffer.cxx index 7a29be94f62..92325af3cdc 100644 --- a/panda/src/glxdisplay/glxGraphicsBuffer.cxx +++ b/panda/src/glxdisplay/glxGraphicsBuffer.cxx @@ -27,13 +27,13 @@ TypeHandle glxGraphicsBuffer::_type_handle; */ glxGraphicsBuffer:: glxGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + GraphicsBuffer(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { glxGraphicsPipe *glx_pipe; DCAST_INTO_V(glx_pipe, _pipe); diff --git a/panda/src/glxdisplay/glxGraphicsBuffer.h b/panda/src/glxdisplay/glxGraphicsBuffer.h index 0ccbd6007bd..632e91c40f7 100644 --- a/panda/src/glxdisplay/glxGraphicsBuffer.h +++ b/panda/src/glxdisplay/glxGraphicsBuffer.h @@ -25,7 +25,7 @@ class glxGraphicsBuffer : public GraphicsBuffer { public: glxGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/glxdisplay/glxGraphicsPipe.cxx b/panda/src/glxdisplay/glxGraphicsPipe.cxx index 9e1bfee7fe9..dd680491ca4 100644 --- a/panda/src/glxdisplay/glxGraphicsPipe.cxx +++ b/panda/src/glxdisplay/glxGraphicsPipe.cxx @@ -28,7 +28,7 @@ TypeHandle glxGraphicsPipe::_type_handle; * */ glxGraphicsPipe:: -glxGraphicsPipe(const string &display) : x11GraphicsPipe(display) { +glxGraphicsPipe(std::string display) : x11GraphicsPipe(std::move(display)) { if (_display == None) { // Some error must have occurred. return; @@ -69,7 +69,7 @@ pipe_constructor() { * Creates a new window on the pipe, if possible. */ PT(GraphicsOutput) glxGraphicsPipe:: -make_output(const string &name, +make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -119,7 +119,7 @@ make_output(const string &name, ((flags&BF_can_bind_layered)!=0)) { return nullptr; } - return new glxGraphicsWindow(engine, this, name, fb_prop, win_prop, + return new glxGraphicsWindow(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } @@ -152,7 +152,7 @@ make_output(const string &name, precertify = true; } } - return new GLGraphicsBuffer(engine, this, name, fb_prop, win_prop, + return new GLGraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } @@ -180,7 +180,7 @@ make_output(const string &name, } } - return new glxGraphicsBuffer(engine, this, name, fb_prop, win_prop, + return new glxGraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } } @@ -204,7 +204,7 @@ make_output(const string &name, return nullptr; } - return new glxGraphicsPixmap(engine, this, name, fb_prop, win_prop, + return new glxGraphicsPixmap(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } diff --git a/panda/src/glxdisplay/glxGraphicsPipe.h b/panda/src/glxdisplay/glxGraphicsPipe.h index 482cb9f8d0e..1de8195e037 100644 --- a/panda/src/glxdisplay/glxGraphicsPipe.h +++ b/panda/src/glxdisplay/glxGraphicsPipe.h @@ -75,14 +75,14 @@ class FrameBufferProperties; */ class glxGraphicsPipe : public x11GraphicsPipe { public: - glxGraphicsPipe(const std::string &display = std::string()); + glxGraphicsPipe(std::string display = std::string()); virtual ~glxGraphicsPipe() {}; virtual std::string get_interface_name() const; static PT(GraphicsPipe) pipe_constructor(); protected: - virtual PT(GraphicsOutput) make_output(const std::string &name, + virtual PT(GraphicsOutput) make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/glxdisplay/glxGraphicsPixmap.cxx b/panda/src/glxdisplay/glxGraphicsPixmap.cxx index 770a7d3d266..7181d9a4cba 100644 --- a/panda/src/glxdisplay/glxGraphicsPixmap.cxx +++ b/panda/src/glxdisplay/glxGraphicsPixmap.cxx @@ -28,13 +28,13 @@ TypeHandle glxGraphicsPixmap::_type_handle; */ glxGraphicsPixmap:: glxGraphicsPixmap(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + GraphicsBuffer(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { glxGraphicsPipe *glx_pipe; DCAST_INTO_V(glx_pipe, _pipe); diff --git a/panda/src/glxdisplay/glxGraphicsPixmap.h b/panda/src/glxdisplay/glxGraphicsPixmap.h index 9cc542fbcc0..fcb00702c39 100644 --- a/panda/src/glxdisplay/glxGraphicsPixmap.h +++ b/panda/src/glxdisplay/glxGraphicsPixmap.h @@ -28,7 +28,7 @@ class glxGraphicsPixmap : public GraphicsBuffer { public: glxGraphicsPixmap(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx b/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx index f32c9984958..7042753b6bd 100644 --- a/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx +++ b/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx @@ -745,7 +745,7 @@ query_glx_extensions() { * Outputs the result of glxGetClientString() on the indicated tag. */ void glxGraphicsStateGuardian:: -show_glx_client_string(const string &name, int id) { +show_glx_client_string(std::string_view name, int id) { if (glgsg_cat.is_debug()) { const char *text = glXGetClientString(_display, id); if (text == nullptr) { @@ -762,7 +762,7 @@ show_glx_client_string(const string &name, int id) { * Outputs the result of glxQueryServerString() on the indicated tag. */ void glxGraphicsStateGuardian:: -show_glx_server_string(const string &name, int id) { +show_glx_server_string(std::string_view name, int id) { if (glgsg_cat.is_debug()) { const char *text = glXQueryServerString(_display, _screen, id); if (text == nullptr) { diff --git a/panda/src/glxdisplay/glxGraphicsStateGuardian.h b/panda/src/glxdisplay/glxGraphicsStateGuardian.h index 1c3fd80dd60..0a4b3caf598 100644 --- a/panda/src/glxdisplay/glxGraphicsStateGuardian.h +++ b/panda/src/glxdisplay/glxGraphicsStateGuardian.h @@ -134,8 +134,8 @@ class glxGraphicsStateGuardian : public PosixGraphicsStateGuardian { private: void query_glx_extensions(); - void show_glx_client_string(const std::string &name, int id); - void show_glx_server_string(const std::string &name, int id); + void show_glx_client_string(std::string_view name, int id); + void show_glx_server_string(std::string_view name, int id); void choose_temp_visual(const FrameBufferProperties &properties); void init_temp_context(); void destroy_temp_xwindow(); diff --git a/panda/src/glxdisplay/glxGraphicsWindow.cxx b/panda/src/glxdisplay/glxGraphicsWindow.cxx index e882bc98fbe..17a062d8f5f 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.cxx +++ b/panda/src/glxdisplay/glxGraphicsWindow.cxx @@ -36,13 +36,13 @@ TypeHandle glxGraphicsWindow::_type_handle; */ glxGraphicsWindow:: glxGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - x11GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + x11GraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { } diff --git a/panda/src/glxdisplay/glxGraphicsWindow.h b/panda/src/glxdisplay/glxGraphicsWindow.h index 53ebc9133c9..efa871dcbd4 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.h +++ b/panda/src/glxdisplay/glxGraphicsWindow.h @@ -27,7 +27,7 @@ class glxGraphicsWindow : public x11GraphicsWindow { public: glxGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/gobj/adaptiveLru.cxx b/panda/src/gobj/adaptiveLru.cxx index 20132cc7a4d..59417752851 100644 --- a/panda/src/gobj/adaptiveLru.cxx +++ b/panda/src/gobj/adaptiveLru.cxx @@ -26,8 +26,8 @@ static const int LOW_PRIORITY_RANGE = 25; * */ AdaptiveLru:: -AdaptiveLru(const std::string &name, size_t max_size) : - Namable(name) +AdaptiveLru(std::string name, size_t max_size) : + Namable(std::move(name)) { _total_size = 0; _max_size = max_size; @@ -158,7 +158,7 @@ update_page(AdaptiveLruPage *page) { } if (target_priority != page->_priority) { - page->_priority = std::min(std::max(target_priority, 0), LPP_TotalPriorities - 1); + page->_priority = std::clamp(target_priority, 0, LPP_TotalPriorities - 1); ((AdaptiveLruPageDynamicList *)page)->remove_from_list(); ((AdaptiveLruPageDynamicList *)page)->insert_before(&_page_array[page->_priority]); } diff --git a/panda/src/gobj/adaptiveLru.h b/panda/src/gobj/adaptiveLru.h index e01fa02bfb0..5077c13943e 100644 --- a/panda/src/gobj/adaptiveLru.h +++ b/panda/src/gobj/adaptiveLru.h @@ -44,7 +44,7 @@ class EXPCL_PANDA_GOBJ AdaptiveLruPageStaticList : public LinkedListNode { */ class EXPCL_PANDA_GOBJ AdaptiveLru : public Namable { PUBLISHED: - explicit AdaptiveLru(const std::string &name, size_t max_size); + explicit AdaptiveLru(std::string name, size_t max_size); ~AdaptiveLru(); INLINE size_t get_total_size() const; diff --git a/panda/src/gobj/bufferResidencyTracker.cxx b/panda/src/gobj/bufferResidencyTracker.cxx index 3d05fbee835..402e904bba8 100644 --- a/panda/src/gobj/bufferResidencyTracker.cxx +++ b/panda/src/gobj/bufferResidencyTracker.cxx @@ -22,7 +22,7 @@ PStatCollector BufferResidencyTracker::_gmem_collector("Graphics memory"); * */ BufferResidencyTracker:: -BufferResidencyTracker(const std::string &pgo_name, const std::string &type_name) : +BufferResidencyTracker(std::string_view pgo_name, std::string_view type_name) : _pgo_collector(_gmem_collector, pgo_name), _active_resident_collector(PStatCollector(_pgo_collector, "Active"), type_name), _active_nonresident_collector(PStatCollector(_pgo_collector, "Thrashing"), type_name), diff --git a/panda/src/gobj/bufferResidencyTracker.h b/panda/src/gobj/bufferResidencyTracker.h index d3714cd2328..0f15b798677 100644 --- a/panda/src/gobj/bufferResidencyTracker.h +++ b/panda/src/gobj/bufferResidencyTracker.h @@ -31,7 +31,7 @@ class BufferContext; */ class EXPCL_PANDA_GOBJ BufferResidencyTracker { public: - BufferResidencyTracker(const std::string &pgo_name, const std::string &type_name); + BufferResidencyTracker(std::string_view pgo_name, std::string_view type_name); ~BufferResidencyTracker(); void begin_frame(Thread *current_thread); diff --git a/panda/src/gobj/geom.cxx b/panda/src/gobj/geom.cxx index 1a80ab5d1a6..ca258c738d9 100644 --- a/panda/src/gobj/geom.cxx +++ b/panda/src/gobj/geom.cxx @@ -1390,7 +1390,7 @@ compute_internal_bounds(Geom::CData *cdata, Thread *current_thread) const { pmax[2] - pmin[2])); avg_box_area = ((min_extent * min_extent) + (max_extent * max_extent)) / 2; } - // Fall through + [[fallthrough]]; case BoundingVolume::BT_sphere: { // Determine the best radius for a bounding sphere. @@ -1444,7 +1444,7 @@ compute_internal_bounds(Geom::CData *cdata, Thread *current_thread) const { break; } } - // Fall through. + [[fallthrough]]; case BoundingVolume::BT_box: cdata->_internal_bounds = new BoundingBox(pmin, pmax); diff --git a/panda/src/gobj/geom.h b/panda/src/gobj/geom.h index 986ca5a827a..32892c73334 100644 --- a/panda/src/gobj/geom.h +++ b/panda/src/gobj/geom.h @@ -67,7 +67,7 @@ class EXPCL_PANDA_GOBJ Geom : public CopyOnWriteObject, public GeomEnums { void operator = (const Geom ©) = delete; - virtual Geom *make_copy() const; + [[nodiscard]] virtual Geom *make_copy() const; INLINE PrimitiveType get_primitive_type() const; INLINE ShadeModel get_shade_model() const; diff --git a/panda/src/gobj/geomVertexColumn.cxx b/panda/src/gobj/geomVertexColumn.cxx index 577146a9dda..61a1a1cda3b 100644 --- a/panda/src/gobj/geomVertexColumn.cxx +++ b/panda/src/gobj/geomVertexColumn.cxx @@ -4494,10 +4494,10 @@ set_data4f(unsigned char *pointer, const LVecBase4f &data) { // when packing an argb, we want to make sure we cap the input values at 1 // since going above one will cause the value to be truncated. *(uint32_t *)pointer = GeomVertexData::pack_abcd - ((unsigned int)(min(max(data[3], 0.0f), 1.0f) * 255.0f), - (unsigned int)(min(max(data[0], 0.0f), 1.0f) * 255.0f), - (unsigned int)(min(max(data[1], 0.0f), 1.0f) * 255.0f), - (unsigned int)(min(max(data[2], 0.0f), 1.0f) * 255.0f)); + ((unsigned int)(std::clamp(data[3], 0.0f, 1.0f) * 255.0f), + (unsigned int)(std::clamp(data[0], 0.0f, 1.0f) * 255.0f), + (unsigned int)(std::clamp(data[1], 0.0f, 1.0f) * 255.0f), + (unsigned int)(std::clamp(data[2], 0.0f, 1.0f) * 255.0f)); } /** @@ -4508,10 +4508,10 @@ set_data4d(unsigned char *pointer, const LVecBase4d &data) { // when packing an argb, we want to make sure we cap the input values at 1 // since going above one will cause the value to be truncated. *(uint32_t *)pointer = GeomVertexData::pack_abcd - ((unsigned int)(min(max(data[3], 0.0), 1.0) * 255.0), - (unsigned int)(min(max(data[0], 0.0), 1.0) * 255.0), - (unsigned int)(min(max(data[1], 0.0), 1.0) * 255.0), - (unsigned int)(min(max(data[2], 0.0), 1.0) * 255.0)); + ((unsigned int)(std::clamp(data[3], 0.0, 1.0) * 255.0), + (unsigned int)(std::clamp(data[0], 0.0, 1.0) * 255.0), + (unsigned int)(std::clamp(data[1], 0.0, 1.0) * 255.0), + (unsigned int)(std::clamp(data[2], 0.0, 1.0) * 255.0)); } /** @@ -4541,10 +4541,10 @@ get_data4d(const unsigned char *pointer) { */ void GeomVertexColumn::Packer_rgba_uint8_4:: set_data4f(unsigned char *pointer, const LVecBase4f &data) { - pointer[0] = (unsigned int)(min(max(data[0], 0.0f), 1.0f) * 255.0f); - pointer[1] = (unsigned int)(min(max(data[1], 0.0f), 1.0f) * 255.0f); - pointer[2] = (unsigned int)(min(max(data[2], 0.0f), 1.0f) * 255.0f); - pointer[3] = (unsigned int)(min(max(data[3], 0.0f), 1.0f) * 255.0f); + pointer[0] = (unsigned int)(std::clamp(data[0], 0.0f, 1.0f) * 255.0f); + pointer[1] = (unsigned int)(std::clamp(data[1], 0.0f, 1.0f) * 255.0f); + pointer[2] = (unsigned int)(std::clamp(data[2], 0.0f, 1.0f) * 255.0f); + pointer[3] = (unsigned int)(std::clamp(data[3], 0.0f, 1.0f) * 255.0f); } /** @@ -4552,10 +4552,10 @@ set_data4f(unsigned char *pointer, const LVecBase4f &data) { */ void GeomVertexColumn::Packer_rgba_uint8_4:: set_data4d(unsigned char *pointer, const LVecBase4d &data) { - pointer[0] = (unsigned int)(min(max(data[0], 0.0), 1.0) * 255.0); - pointer[1] = (unsigned int)(min(max(data[1], 0.0), 1.0) * 255.0); - pointer[2] = (unsigned int)(min(max(data[2], 0.0), 1.0) * 255.0); - pointer[3] = (unsigned int)(min(max(data[3], 0.0), 1.0) * 255.0); + pointer[0] = (unsigned int)(std::clamp(data[0], 0.0, 1.0) * 255.0); + pointer[1] = (unsigned int)(std::clamp(data[1], 0.0, 1.0) * 255.0); + pointer[2] = (unsigned int)(std::clamp(data[2], 0.0, 1.0) * 255.0); + pointer[3] = (unsigned int)(std::clamp(data[3], 0.0, 1.0) * 255.0); } /** diff --git a/panda/src/gobj/geomVertexData.cxx b/panda/src/gobj/geomVertexData.cxx index 2345fbef6ff..f3e48d82cdd 100644 --- a/panda/src/gobj/geomVertexData.cxx +++ b/panda/src/gobj/geomVertexData.cxx @@ -62,12 +62,12 @@ make_cow_copy() { * */ GeomVertexData:: -GeomVertexData(const std::string &name, +GeomVertexData(std::string name, const GeomVertexFormat *format, GeomVertexData::UsageHint usage_hint) : - _name(name), + _name(std::move(name)), _cycler(GeomVertexData::CData(format, usage_hint)), - _char_pcollector(PStatCollector(_animation_pcollector, name)), + _char_pcollector(PStatCollector(_animation_pcollector, _name)), _skinning_pcollector(_char_pcollector, "Skinning"), _morphs_pcollector(_char_pcollector, "Morphs"), _blends_pcollector(_char_pcollector, "Calc blends") @@ -185,9 +185,9 @@ compare_to(const GeomVertexData &other) const { * graph for vertex computations. */ void GeomVertexData:: -set_name(const std::string &name) { - _name = name; - _char_pcollector = PStatCollector(_animation_pcollector, name); +set_name(std::string name) { + _name = std::move(name); + _char_pcollector = PStatCollector(_animation_pcollector, _name); _skinning_pcollector = PStatCollector(_char_pcollector, "Skinning"); _morphs_pcollector = PStatCollector(_char_pcollector, "Morphs"); _blends_pcollector = PStatCollector(_char_pcollector, "Calc blends"); diff --git a/panda/src/gobj/geomVertexData.h b/panda/src/gobj/geomVertexData.h index 63a90241900..391bbe52262 100644 --- a/panda/src/gobj/geomVertexData.h +++ b/panda/src/gobj/geomVertexData.h @@ -72,7 +72,7 @@ class EXPCL_PANDA_GOBJ GeomVertexData : public CopyOnWriteObject, public GeomEnu virtual PT(CopyOnWriteObject) make_cow_copy(); PUBLISHED: - explicit GeomVertexData(const std::string &name, + explicit GeomVertexData(std::string name, const GeomVertexFormat *format, UsageHint usage_hint); GeomVertexData(const GeomVertexData ©); @@ -86,7 +86,7 @@ class EXPCL_PANDA_GOBJ GeomVertexData : public CopyOnWriteObject, public GeomEnu int compare_to(const GeomVertexData &other) const; INLINE const std::string &get_name() const; - void set_name(const std::string &name); + void set_name(std::string name); MAKE_PROPERTY(name, get_name, set_name); INLINE UsageHint get_usage_hint() const; diff --git a/panda/src/gobj/internalName.I b/panda/src/gobj/internalName.I index 308426f5ed7..5a0a0a09c06 100644 --- a/panda/src/gobj/internalName.I +++ b/panda/src/gobj/internalName.I @@ -22,7 +22,7 @@ * handled transparently. */ INLINE PT(InternalName) InternalName:: -make(const std::string &name) { +make(std::string_view name) { return get_root()->append(name); } @@ -136,7 +136,7 @@ get_tangent() { * coordinate set. */ INLINE PT(InternalName) InternalName:: -get_tangent_name(const std::string &name) { +get_tangent_name(std::string_view name) { return get_tangent()->append(name); } @@ -161,7 +161,7 @@ get_binormal() { * named texture coordinate set. */ INLINE PT(InternalName) InternalName:: -get_binormal_name(const std::string &name) { +get_binormal_name(std::string_view name) { return get_binormal()->append(name); } @@ -185,7 +185,7 @@ get_texcoord() { * set in a TextureStage. */ INLINE PT(InternalName) InternalName:: -get_texcoord_name(const std::string &name) { +get_texcoord_name(std::string_view name) { return get_texcoord()->append(name); } @@ -298,7 +298,7 @@ get_transform_index() { * column it applies to. */ INLINE PT(InternalName) InternalName:: -get_morph(InternalName *column, const std::string &slider) { +get_morph(InternalName *column, std::string_view slider) { // This actually returns "column.morph.slider", although that's just an // implementation detail--as long as it returns a consistent, unique name // for each combination of column and slider, everything is good. @@ -423,6 +423,15 @@ CPT_InternalName(const std::string &name) : { } +/** + * + */ +INLINE CPT_InternalName:: +CPT_InternalName(std::string_view name) : + ConstPointerTo(InternalName::make(name)) +{ +} + /** * */ diff --git a/panda/src/gobj/internalName.cxx b/panda/src/gobj/internalName.cxx index d6ad51d2a4e..64d9ebd0763 100644 --- a/panda/src/gobj/internalName.cxx +++ b/panda/src/gobj/internalName.cxx @@ -56,7 +56,7 @@ LightMutex InternalName::_literal_table_lock; * Use make() to make a new InternalName instance. */ InternalName:: -InternalName(InternalName *parent, const string &basename) : +InternalName(InternalName *parent, std::string basename) : _parent(parent), _basename(basename) { @@ -110,7 +110,7 @@ unref() const { * InternalName::make(parent->get_name() + ".basename"). */ PT(InternalName) InternalName:: -append(const string &name) { +append(std::string_view name) { test_ref_count_integrity(); if (name.empty()) { @@ -118,7 +118,7 @@ append(const string &name) { } size_t dot = name.rfind('.'); - if (dot != string::npos) { + if (dot != std::string_view::npos) { return append(name.substr(0, dot))->append(name.substr(dot + 1)); } @@ -129,8 +129,8 @@ append(const string &name) { return (*ni).second; } - InternalName *internal_name = new InternalName(this, name); - _name_table[name] = internal_name; + InternalName *internal_name = new InternalName(this, std::string(name)); + _name_table[internal_name->_basename] = internal_name; return internal_name; } @@ -155,7 +155,7 @@ get_name() const { * Like get_name, but uses a custom separator instead of ".". */ string InternalName:: -join(const string &sep) const { +join(std::string_view sep) const { if (_parent == get_root()) { return _basename; @@ -163,7 +163,10 @@ join(const string &sep) const { return string(); } else { - return _parent->join(sep) + sep + _basename; + std::string result = _parent->join(sep); + result += sep; + result += _basename; + return result; } } @@ -175,7 +178,7 @@ join(const string &sep) const { * retrieve more information about the indicated name. */ int InternalName:: -find_ancestor(const string &basename) const { +find_ancestor(std::string_view basename) const { test_ref_count_integrity(); if (_basename == basename) { @@ -295,7 +298,7 @@ finalize(BamReader *) { * Make using a string and an integer. Concatenates the two. */ PT(InternalName) InternalName:: -make(const string &name, int index) { +make(std::string_view name, int index) { std::ostringstream full; full << name << index; return make(full.str()); diff --git a/panda/src/gobj/internalName.h b/panda/src/gobj/internalName.h index 5a48bee8242..239995c3e68 100644 --- a/panda/src/gobj/internalName.h +++ b/panda/src/gobj/internalName.h @@ -37,10 +37,10 @@ class FactoryParams; */ class EXPCL_PANDA_GOBJ InternalName final : public TypedWritableReferenceCount { private: - InternalName(InternalName *parent, const std::string &basename); + InternalName(InternalName *parent, std::string basename); public: - INLINE static PT(InternalName) make(const std::string &name); + INLINE static PT(InternalName) make(std::string_view name); template INLINE static PT(InternalName) make(const char (&literal)[N]); @@ -49,19 +49,19 @@ class EXPCL_PANDA_GOBJ InternalName final : public TypedWritableReferenceCount { virtual ~InternalName(); virtual bool unref() const; - static PT(InternalName) make(const std::string &name, int index); - PT(InternalName) append(const std::string &basename); + static PT(InternalName) make(std::string_view name, int index); + PT(InternalName) append(std::string_view basename); INLINE InternalName *get_parent() const; std::string get_name() const; - std::string join(const std::string &sep) const; + std::string join(std::string_view sep) const; INLINE const std::string &get_basename() const; MAKE_PROPERTY(parent, get_parent); MAKE_PROPERTY(name, get_name); MAKE_PROPERTY(basename, get_basename); - int find_ancestor(const std::string &basename) const; + int find_ancestor(std::string_view basename) const; const InternalName *get_ancestor(int n) const; const InternalName *get_top() const; std::string get_net_basename(int n) const; @@ -74,11 +74,11 @@ class EXPCL_PANDA_GOBJ InternalName final : public TypedWritableReferenceCount { INLINE static PT(InternalName) get_vertex(); INLINE static PT(InternalName) get_normal(); INLINE static PT(InternalName) get_tangent(); - INLINE static PT(InternalName) get_tangent_name(const std::string &name); + INLINE static PT(InternalName) get_tangent_name(std::string_view name); INLINE static PT(InternalName) get_binormal(); - INLINE static PT(InternalName) get_binormal_name(const std::string &name); + INLINE static PT(InternalName) get_binormal_name(std::string_view name); INLINE static PT(InternalName) get_texcoord(); - INLINE static PT(InternalName) get_texcoord_name(const std::string &name); + INLINE static PT(InternalName) get_texcoord_name(std::string_view name); INLINE static PT(InternalName) get_color(); INLINE static PT(InternalName) get_rotate(); INLINE static PT(InternalName) get_size(); @@ -86,7 +86,7 @@ class EXPCL_PANDA_GOBJ InternalName final : public TypedWritableReferenceCount { INLINE static PT(InternalName) get_transform_blend(); INLINE static PT(InternalName) get_transform_weight(); INLINE static PT(InternalName) get_transform_index(); - INLINE static PT(InternalName) get_morph(InternalName *column, const std::string &slider); + INLINE static PT(InternalName) get_morph(InternalName *column, std::string_view slider); INLINE static PT(InternalName) get_index(); INLINE static PT(InternalName) get_world(); INLINE static PT(InternalName) get_camera(); @@ -200,6 +200,7 @@ class CPT_InternalName : public ConstPointerTo { INLINE CPT_InternalName(const ConstPointerTo ©); INLINE CPT_InternalName(ConstPointerTo &&from) noexcept; INLINE CPT_InternalName(const std::string &name); + INLINE CPT_InternalName(std::string_view name); template INLINE CPT_InternalName(const char (&literal)[N]); diff --git a/panda/src/gobj/lens.I b/panda/src/gobj/lens.I index d20d53bfd74..e03330cc02a 100644 --- a/panda/src/gobj/lens.I +++ b/panda/src/gobj/lens.I @@ -142,9 +142,9 @@ project(const LPoint3 &point3d, LPoint3 &point2d) const { * to automatically track changes to camera fov, etc. in the application. */ INLINE void Lens:: -set_change_event(const std::string &event) { +set_change_event(std::string event) { CDWriter cdata(_cycler, true); - cdata->_change_event = event; + cdata->_change_event = std::move(event); } /** diff --git a/panda/src/gobj/lens.h b/panda/src/gobj/lens.h index 22b7fece233..afa80e0ff4e 100644 --- a/panda/src/gobj/lens.h +++ b/panda/src/gobj/lens.h @@ -64,7 +64,7 @@ class EXPCL_PANDA_GOBJ Lens : public TypedWritableReferenceCount { INLINE bool project(const LPoint3 &point3d, LPoint3 &point2d) const; INLINE bool project(const LPoint3 &point3d, LPoint2 &point2d) const; - INLINE void set_change_event(const std::string &event); + INLINE void set_change_event(std::string event); INLINE const std::string &get_change_event() const; MAKE_PROPERTY(change_event, get_change_event, set_change_event); diff --git a/panda/src/gobj/material.I b/panda/src/gobj/material.I index bd717f835c1..c298076faf1 100644 --- a/panda/src/gobj/material.I +++ b/panda/src/gobj/material.I @@ -15,7 +15,7 @@ * */ INLINE Material:: -Material(const std::string &name) : Namable(name) { +Material(std::string name) : Namable(std::move(name)) { _base_color.set(1.0f, 1.0f, 1.0f, 1.0f); _ambient.set(1.0f, 1.0f, 1.0f, 1.0f); _diffuse.set(1.0f, 1.0f, 1.0f, 1.0f); diff --git a/panda/src/gobj/material.h b/panda/src/gobj/material.h index b0c25de57bc..10d3a8aca51 100644 --- a/panda/src/gobj/material.h +++ b/panda/src/gobj/material.h @@ -42,7 +42,7 @@ class FactoryParams; */ class EXPCL_PANDA_GOBJ Material : public TypedWritableReferenceCount, public Namable { PUBLISHED: - INLINE explicit Material(const std::string &name = ""); + INLINE explicit Material(std::string name = ""); INLINE Material(const Material ©); void operator = (const Material ©); INLINE ~Material(); diff --git a/panda/src/gobj/samplerState.cxx b/panda/src/gobj/samplerState.cxx index 9f1a5766bcc..3afc48b562a 100644 --- a/panda/src/gobj/samplerState.cxx +++ b/panda/src/gobj/samplerState.cxx @@ -119,7 +119,7 @@ format_filter_type(FilterType ft) { * FilterType value. */ SamplerState::FilterType SamplerState:: -string_filter_type(const string &string) { +string_filter_type(std::string_view string) { if (cmp_nocase_uh(string, "nearest") == 0) { return FT_nearest; } else if (cmp_nocase_uh(string, "linear") == 0) { @@ -172,7 +172,7 @@ format_wrap_mode(WrapMode wm) { * or WM_invalid if the string does not match any known WrapMode value. */ SamplerState::WrapMode SamplerState:: -string_wrap_mode(const string &string) { +string_wrap_mode(std::string_view string) { if (cmp_nocase_uh(string, "repeat") == 0 || cmp_nocase_uh(string, "wrap") == 0) { return WM_repeat; diff --git a/panda/src/gobj/samplerState.h b/panda/src/gobj/samplerState.h index d15aa5758fb..02cc5d760d5 100644 --- a/panda/src/gobj/samplerState.h +++ b/panda/src/gobj/samplerState.h @@ -126,10 +126,10 @@ class EXPCL_PANDA_GOBJ SamplerState : public MemoryBase { INLINE static bool is_mipmap(FilterType type); static std::string format_filter_type(FilterType ft); - static FilterType string_filter_type(const std::string &str); + static FilterType string_filter_type(std::string_view str); static std::string format_wrap_mode(WrapMode wm); - static WrapMode string_wrap_mode(const std::string &str); + static WrapMode string_wrap_mode(std::string_view str); INLINE bool operator == (const SamplerState &other) const; INLINE bool operator != (const SamplerState &other) const; diff --git a/panda/src/gobj/shader.cxx b/panda/src/gobj/shader.cxx index 8cea76df6c1..215046b5143 100644 --- a/panda/src/gobj/shader.cxx +++ b/panda/src/gobj/shader.cxx @@ -47,7 +47,7 @@ CGcontext Shader::_cg_context = 0; * parameter. */ void Shader:: -cp_report_error(ShaderArgInfo &p, const string &msg) { +cp_report_error(ShaderArgInfo &p, std::string_view msg) { string vstr; if (p._varying) { @@ -812,7 +812,7 @@ cg_recurse_parameters(CGparameter parameter, const ShaderType &type, arg_dim[0] = cgGetArraySize(parameter, 0); - // Fall through + [[fallthrough]]; default: { arg_dim[1] = cgGetParameterRows(parameter); arg_dim[2] = cgGetParameterColumns(parameter); diff --git a/panda/src/gobj/shader.h b/panda/src/gobj/shader.h index 88021d24036..6588a9c7559 100644 --- a/panda/src/gobj/shader.h +++ b/panda/src/gobj/shader.h @@ -562,7 +562,7 @@ class EXPCL_PANDA_GOBJ Shader : public TypedWritableReferenceCount { void parse_rest(std::string &result); bool parse_eof(); - void cp_report_error(ShaderArgInfo &arg, const std::string &msg); + void cp_report_error(ShaderArgInfo &arg, std::string_view msg); bool cp_errchk_parameter_words(ShaderArgInfo &arg, int len); bool cp_errchk_parameter_in(ShaderArgInfo &arg); bool cp_errchk_parameter_ptr(ShaderArgInfo &p); diff --git a/panda/src/gobj/shaderBuffer.I b/panda/src/gobj/shaderBuffer.I index ccbd160521c..46f5828ab0c 100644 --- a/panda/src/gobj/shaderBuffer.I +++ b/panda/src/gobj/shaderBuffer.I @@ -16,8 +16,8 @@ * parameters cannot be modified, but this may change in the future. */ INLINE ShaderBuffer:: -ShaderBuffer(const std::string &name, uint64_t size, UsageHint usage_hint) : - Namable(name), +ShaderBuffer(std::string name, uint64_t size, UsageHint usage_hint) : + Namable(std::move(name)), _data_size_bytes(size), _usage_hint(usage_hint) { } @@ -27,8 +27,8 @@ ShaderBuffer(const std::string &name, uint64_t size, UsageHint usage_hint) : * parameters cannot be modified, but this may change in the future. */ INLINE ShaderBuffer:: -ShaderBuffer(const std::string &name, vector_uchar initial_data, UsageHint usage_hint) : - Namable(name), +ShaderBuffer(std::string name, vector_uchar initial_data, UsageHint usage_hint) : + Namable(std::move(name)), _data_size_bytes(initial_data.size()), _usage_hint(usage_hint), _initial_data(std::move(initial_data)) { diff --git a/panda/src/gobj/shaderBuffer.h b/panda/src/gobj/shaderBuffer.h index 8cc9eedf900..80328e1e259 100644 --- a/panda/src/gobj/shaderBuffer.h +++ b/panda/src/gobj/shaderBuffer.h @@ -38,8 +38,8 @@ class EXPCL_PANDA_GOBJ ShaderBuffer : public TypedWritableReferenceCount, public PUBLISHED: ~ShaderBuffer(); - INLINE explicit ShaderBuffer(const std::string &name, uint64_t size, UsageHint usage_hint); - INLINE explicit ShaderBuffer(const std::string &name, vector_uchar initial_data, UsageHint usage_hint); + INLINE explicit ShaderBuffer(std::string name, uint64_t size, UsageHint usage_hint); + INLINE explicit ShaderBuffer(std::string name, vector_uchar initial_data, UsageHint usage_hint); public: INLINE uint64_t get_data_size_bytes() const; diff --git a/panda/src/gobj/simpleLru.cxx b/panda/src/gobj/simpleLru.cxx index dfdb9113daf..efff2254672 100644 --- a/panda/src/gobj/simpleLru.cxx +++ b/panda/src/gobj/simpleLru.cxx @@ -26,9 +26,9 @@ LightMutex &SimpleLru::_global_lock = *new LightMutex; * */ SimpleLru:: -SimpleLru(const std::string &name, size_t max_size) : +SimpleLru(std::string name, size_t max_size) : LinkedListNode(true), - Namable(name) + Namable(std::move(name)) { _total_size = 0; _max_size = max_size; diff --git a/panda/src/gobj/simpleLru.h b/panda/src/gobj/simpleLru.h index 5a712d8ffc0..7963d9840e0 100644 --- a/panda/src/gobj/simpleLru.h +++ b/panda/src/gobj/simpleLru.h @@ -27,7 +27,7 @@ class SimpleLruPage; */ class EXPCL_PANDA_GOBJ SimpleLru : public LinkedListNode, public Namable { PUBLISHED: - explicit SimpleLru(const std::string &name, size_t max_size); + explicit SimpleLru(std::string name, size_t max_size); ~SimpleLru(); INLINE size_t get_total_size() const; diff --git a/panda/src/gobj/texture.I b/panda/src/gobj/texture.I index de82e7580c1..01c3f7d452a 100644 --- a/panda/src/gobj/texture.I +++ b/panda/src/gobj/texture.I @@ -2153,7 +2153,7 @@ get_num_async_transfer_buffers() const { * power-2. */ INLINE bool Texture:: -adjust_this_size(int &x_size, int &y_size, const std::string &name, +adjust_this_size(int &x_size, int &y_size, std::string_view name, bool for_padding) const { CDReader cdata(_cycler); return do_adjust_this_size(cdata, x_size, y_size, name, for_padding); diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index eb89d1d9b43..a0fdc628798 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -374,9 +374,9 @@ enum KTXCompressedFormat { * this is not what you want. */ Texture:: -Texture(const string &name) : - Namable(name), - _lock(name), +Texture(std::string name) : + Namable(std::move(name)), + _lock(get_name()), _cvar(_lock) { _reloading = false; @@ -809,18 +809,21 @@ estimate_texture_memory() const { * These data objects are not recorded to a bam or txo file. */ void Texture:: -set_aux_data(const string &key, TypedReferenceCount *aux_data) { +set_aux_data(std::string key, TypedReferenceCount *aux_data) { MutexHolder holder(_lock); - _aux_data[key] = aux_data; + _aux_data[std::move(key)] = aux_data; } /** * Removes a record previously recorded via set_aux_data(). */ void Texture:: -clear_aux_data(const string &key) { +clear_aux_data(std::string_view key) { MutexHolder holder(_lock); - _aux_data.erase(key); + AuxData::iterator di = _aux_data.find(key); + if (di != _aux_data.end()) { + _aux_data.erase(di); + } } /** @@ -828,7 +831,7 @@ clear_aux_data(const string &key) { * there was no record associated with the indicated key. */ TypedReferenceCount *Texture:: -get_aux_data(const string &key) const { +get_aux_data(std::string_view key) const { MutexHolder holder(_lock); AuxData::const_iterator di; di = _aux_data.find(key); @@ -847,7 +850,7 @@ get_aux_data(const string &key) const { * Pass a real filename if it is available, or empty string if it is not. */ bool Texture:: -read_txo(istream &in, const string &filename) { +read_txo(istream &in, std::string_view filename) { CDWriter cdata(_cycler, true); cdata->inc_properties_modified(); cdata->inc_image_modified(); @@ -862,7 +865,7 @@ read_txo(istream &in, const string &filename) { * Pass a real filename if it is available, or empty string if it is not. */ PT(Texture) Texture:: -make_from_txo(istream &in, const string &filename) { +make_from_txo(istream &in, std::string_view filename) { DatagramInputFile din; if (!din.open(in, filename)) { @@ -930,7 +933,7 @@ make_from_txo(istream &in, const string &filename) { * The filename is just for reference. */ bool Texture:: -write_txo(ostream &out, const string &filename) const { +write_txo(ostream &out, std::string_view filename) const { CDReader cdata(_cycler); return do_write_txo(cdata, out, filename); } @@ -945,7 +948,7 @@ write_txo(ostream &out, const string &filename) const { * As with read_txo, the filename is just for reference. */ bool Texture:: -read_dds(istream &in, const string &filename, bool header_only) { +read_dds(istream &in, std::string_view filename, bool header_only) { CDWriter cdata(_cycler, true); cdata->inc_properties_modified(); cdata->inc_image_modified(); @@ -962,7 +965,7 @@ read_dds(istream &in, const string &filename, bool header_only) { * As with read_dds, the filename is just for reference. */ bool Texture:: -read_ktx(istream &in, const string &filename, bool header_only) { +read_ktx(istream &in, std::string_view filename, bool header_only) { CDWriter cdata(_cycler, true); cdata->inc_properties_modified(); cdata->inc_image_modified(); @@ -1094,7 +1097,7 @@ async_ensure_ram_image(bool allow_compression, int priority) { * support compressed image data or sub-pages; use set_ram_image() for that. */ void Texture:: -set_ram_image_as(CPTA_uchar image, const string &supplied_format) { +set_ram_image_as(CPTA_uchar image, std::string_view supplied_format) { CDWriter cdata(_cycler, true); string format = upcase(supplied_format); @@ -2165,7 +2168,7 @@ consider_rescale(PNMImage &pnmimage) { * see rescale_texture(). */ void Texture:: -consider_rescale(PNMImage &pnmimage, const string &name, AutoTextureScale auto_texture_scale) { +consider_rescale(PNMImage &pnmimage, std::string_view name, AutoTextureScale auto_texture_scale) { int new_x_size = pnmimage.get_x_size(); int new_y_size = pnmimage.get_y_size(); if (adjust_size(new_x_size, new_y_size, name, false, auto_texture_scale)) { @@ -2214,7 +2217,7 @@ format_texture_type(TextureType tt) { * Returns the TextureType corresponding to the indicated string word. */ Texture::TextureType Texture:: -string_texture_type(const string &str) { +string_texture_type(std::string_view str) { if (cmp_nocase(str, "1d_texture") == 0) { return TT_1d_texture; } else if (cmp_nocase(str, "2d_texture") == 0) { @@ -2269,7 +2272,7 @@ format_component_type(ComponentType ct) { * Returns the ComponentType corresponding to the indicated string word. */ Texture::ComponentType Texture:: -string_component_type(const string &str) { +string_component_type(std::string_view str) { if (cmp_nocase(str, "unsigned_byte") == 0) { return T_unsigned_byte; } else if (cmp_nocase(str, "unsigned_short") == 0) { @@ -2413,7 +2416,7 @@ format_format(Format format) { * Returns the Format corresponding to the indicated string word. */ Texture::Format Texture:: -string_format(const string &str) { +string_format(std::string_view str) { if (cmp_nocase(str, "depth_stencil") == 0) { return F_depth_stencil; } else if (cmp_nocase(str, "depth_component") == 0) { @@ -2573,7 +2576,7 @@ format_compression_mode(CompressionMode cm) { * representation. */ Texture::CompressionMode Texture:: -string_compression_mode(const string &str) { +string_compression_mode(std::string_view str) { if (cmp_nocase_uh(str, "default") == 0) { return CM_default; } else if (cmp_nocase_uh(str, "off") == 0) { @@ -2636,7 +2639,7 @@ format_quality_level(QualityLevel ql) { * representation. */ Texture::QualityLevel Texture:: -string_quality_level(const string &str) { +string_quality_level(std::string_view str) { if (cmp_nocase(str, "default") == 0) { return QL_default; } else if (cmp_nocase(str, "fastest") == 0) { @@ -2837,7 +2840,7 @@ is_integer(Format format) { * false if it is the same. */ bool Texture:: -adjust_size(int &x_size, int &y_size, const string &name, +adjust_size(int &x_size, int &y_size, std::string_view name, bool for_padding, AutoTextureScale auto_texture_scale) { bool exclude = false; int num_excludes = exclude_texture_scale.get_num_unique_values(); @@ -2965,7 +2968,7 @@ reconsider_dirty() { * power-2. */ bool Texture:: -do_adjust_this_size(const CData *cdata, int &x_size, int &y_size, const string &name, +do_adjust_this_size(const CData *cdata, int &x_size, int &y_size, std::string_view name, bool for_padding) const { return adjust_size(x_size, y_size, name, for_padding, cdata->_auto_texture_scale); } @@ -3498,7 +3501,7 @@ do_read_one(CData *cdata, const Filename &fullpath, const Filename &alpha_fullpa * Internal method to load a single page or mipmap level. */ bool Texture:: -do_load_one(CData *cdata, const PNMImage &pnmimage, const string &name, int z, int n, +do_load_one(CData *cdata, const PNMImage &pnmimage, std::string_view name, int z, int n, const LoaderOptions &options) { if (cdata->_ram_images.size() <= 1 && n == 0) { // A special case for mipmap level 0. When we load mipmap level 0, unless @@ -3572,7 +3575,7 @@ do_load_one(CData *cdata, const PNMImage &pnmimage, const string &name, int z, i * Internal method to load a single page or mipmap level. */ bool Texture:: -do_load_one(CData *cdata, const PfmFile &pfm, const string &name, int z, int n, +do_load_one(CData *cdata, const PfmFile &pfm, std::string_view name, int z, int n, const LoaderOptions &options) { if (cdata->_ram_images.size() <= 1 && n == 0) { // A special case for mipmap level 0. When we load mipmap level 0, unless @@ -3708,7 +3711,7 @@ do_read_txo_file(CData *cdata, const Filename &fullpath) { * */ bool Texture:: -do_read_txo(CData *cdata, istream &in, const string &filename) { +do_read_txo(CData *cdata, istream &in, std::string_view filename) { PT(Texture) other = make_from_txo(in, filename); if (other == nullptr) { return false; @@ -3773,7 +3776,7 @@ do_read_dds_file(CData *cdata, const Filename &fullpath, bool header_only) { * */ bool Texture:: -do_read_dds(CData *cdata, istream &in, const string &filename, bool header_only) { +do_read_dds(CData *cdata, istream &in, std::string_view filename, bool header_only) { StreamReader dds(in); // DDS header (19 words) @@ -4459,7 +4462,7 @@ do_read_ktx_file(CData *cdata, const Filename &fullpath, bool header_only) { * */ bool Texture:: -do_read_ktx(CData *cdata, istream &in, const string &filename, bool header_only) { +do_read_ktx(CData *cdata, istream &in, std::string_view filename, bool header_only) { StreamReader ktx(in); unsigned char magic[12]; @@ -5436,7 +5439,7 @@ do_write_txo_file(const CData *cdata, const Filename &fullpath) const { * */ bool Texture:: -do_write_txo(const CData *cdata, ostream &out, const string &filename) const { +do_write_txo(const CData *cdata, ostream &out, std::string_view filename) const { DatagramOutputFile dout; if (!dout.open(out, filename)) { @@ -5935,7 +5938,7 @@ do_get_clear_data(const CData *cdata, unsigned char *into) const { nassertr(num_components == 1, 0); *((unsigned int *)into) = ((unsigned int)(clear_value[0] * 16777215) << 8) + - (unsigned int)max(min(clear_value[1], (PN_stdfloat)255), (PN_stdfloat)0); + (unsigned int)std::clamp(clear_value[1], (PN_stdfloat)0, (PN_stdfloat)255); break; case T_int: @@ -5975,7 +5978,7 @@ do_get_clear_data(const CData *cdata, unsigned char *into) const { v.uf = clear_value[i]; uint16_t sign = ((v.ui & 0x80000000u) >> 16u); uint32_t mantissa = (v.ui & 0x007fffffu); - uint16_t exponent = (uint16_t)std::min(std::max((int)((v.ui & 0x7f800000u) >> 23u) - 112, 0), 31); + uint16_t exponent = (uint16_t)std::clamp((int)((v.ui & 0x7f800000u) >> 23u) - 112, 0, 31); mantissa += (mantissa & 0x00001000u) << 1u; ((uint16_t *)into)[i] = (uint16_t)(sign | ((exponent << 10u) | (mantissa >> 13u))); } @@ -7527,7 +7530,7 @@ do_get_uncompressed_ram_image(CData *cdata) { * will return NULL. */ CPTA_uchar Texture:: -get_ram_image_as(const string &requested_format) { +get_ram_image_as(std::string_view requested_format) { CDWriter cdata(_cycler, false); string format = upcase(requested_format); @@ -9309,7 +9312,7 @@ clear_prepared(PreparedGraphicsObjects *prepared_objects) { * num_channels. */ void Texture:: -consider_downgrade(PNMImage &pnmimage, int num_channels, const string &name) { +consider_downgrade(PNMImage &pnmimage, int num_channels, std::string_view name) { if (num_channels != 0 && num_channels != pnmimage.get_num_channels()) { gobj_cat.info() << (num_channels < pnmimage.get_num_channels() ? "Down" : "Up") diff --git a/panda/src/gobj/texture.h b/panda/src/gobj/texture.h index 4ba2b58169b..2b337584d24 100644 --- a/panda/src/gobj/texture.h +++ b/panda/src/gobj/texture.h @@ -232,7 +232,7 @@ class EXPCL_PANDA_GOBJ Texture : public TypedWritableReferenceCount, public Nama }; PUBLISHED: - explicit Texture(const std::string &name = std::string()); + explicit Texture(std::string name = ""); protected: Texture(const Texture ©); @@ -296,11 +296,11 @@ class EXPCL_PANDA_GOBJ Texture : public TypedWritableReferenceCount, public Nama BLOCKING INLINE bool write(const Filename &fullpath, int z, int n, bool write_pages, bool write_mipmaps); - BLOCKING bool read_txo(std::istream &in, const std::string &filename = ""); - BLOCKING static PT(Texture) make_from_txo(std::istream &in, const std::string &filename = ""); - BLOCKING bool write_txo(std::ostream &out, const std::string &filename = "") const; - BLOCKING bool read_dds(std::istream &in, const std::string &filename = "", bool header_only = false); - BLOCKING bool read_ktx(std::istream &in, const std::string &filename = "", bool header_only = false); + BLOCKING bool read_txo(std::istream &in, std::string_view filename = std::string_view()); + BLOCKING static PT(Texture) make_from_txo(std::istream &in, std::string_view filename = std::string_view()); + BLOCKING bool write_txo(std::ostream &out, std::string_view filename = std::string_view()) const; + BLOCKING bool read_dds(std::istream &in, std::string_view filename = std::string_view(), bool header_only = false); + BLOCKING bool read_ktx(std::istream &in, std::string_view filename = std::string_view(), bool header_only = false); BLOCKING INLINE bool load(const PNMImage &pnmimage, const LoaderOptions &options = LoaderOptions()); BLOCKING INLINE bool load(const PNMImage &pnmimage, int z, int n, const LoaderOptions &options = LoaderOptions()); @@ -454,17 +454,17 @@ class EXPCL_PANDA_GOBJ Texture : public TypedWritableReferenceCount, public Nama INLINE CPTA_uchar get_ram_image(); INLINE CompressionMode get_ram_image_compression() const; INLINE CPTA_uchar get_uncompressed_ram_image(); - CPTA_uchar get_ram_image_as(const std::string &requested_format); + CPTA_uchar get_ram_image_as(std::string_view requested_format); INLINE PTA_uchar modify_ram_image(); INLINE PTA_uchar make_ram_image(); #if !defined(CPPPARSER) || !defined(HAVE_PYTHON) INLINE void set_ram_image(CPTA_uchar image, CompressionMode compression = CM_off, size_t page_size = 0); - void set_ram_image_as(CPTA_uchar image, const std::string &provided_format); + void set_ram_image_as(CPTA_uchar image, std::string_view provided_format); #else // !CPPPARSER || !HAVE_PYTHON PY_EXTEND(void set_ram_image(PyObject *image, CompressionMode compression = CM_off, size_t page_size = 0)); - PY_EXTEND(void set_ram_image_as(PyObject *image, const std::string &provided_format)); + PY_EXTEND(void set_ram_image_as(PyObject *image, std::string_view provided_format)); #endif // !CPPPARSER || !HAVE_PYTHON INLINE void clear_ram_image(); INLINE void set_keep_ram_image(bool keep_ram_image); @@ -553,9 +553,9 @@ class EXPCL_PANDA_GOBJ Texture : public TypedWritableReferenceCount, public Nama size_t estimate_texture_memory() const; - void set_aux_data(const std::string &key, TypedReferenceCount *aux_data); - void clear_aux_data(const std::string &key); - TypedReferenceCount *get_aux_data(const std::string &key) const; + void set_aux_data(std::string key, TypedReferenceCount *aux_data); + void clear_aux_data(std::string_view key); + TypedReferenceCount *get_aux_data(std::string_view key) const; MAKE_MAP_PROPERTY(aux_data, get_aux_data, get_aux_data, set_aux_data, clear_aux_data); @@ -611,23 +611,23 @@ class EXPCL_PANDA_GOBJ Texture : public TypedWritableReferenceCount, public Nama static int down_to_power_2(int value); void consider_rescale(PNMImage &pnmimage); - static void consider_rescale(PNMImage &pnmimage, const std::string &name, AutoTextureScale auto_texture_scale = ATS_unspecified); + static void consider_rescale(PNMImage &pnmimage, std::string_view name, AutoTextureScale auto_texture_scale = ATS_unspecified); INLINE bool rescale_texture(); static std::string format_texture_type(TextureType tt); - static TextureType string_texture_type(const std::string &str); + static TextureType string_texture_type(std::string_view str); static std::string format_component_type(ComponentType ct); - static ComponentType string_component_type(const std::string &str); + static ComponentType string_component_type(std::string_view str); static std::string format_format(Format f); - static Format string_format(const std::string &str); + static Format string_format(std::string_view str); static std::string format_compression_mode(CompressionMode cm); - static CompressionMode string_compression_mode(const std::string &str); + static CompressionMode string_compression_mode(std::string_view str); static std::string format_quality_level(QualityLevel tql); - static QualityLevel string_quality_level(const std::string &str); + static QualityLevel string_quality_level(std::string_view str); public: void texture_uploaded(); @@ -646,9 +646,9 @@ class EXPCL_PANDA_GOBJ Texture : public TypedWritableReferenceCount, public Nama static bool is_srgb(Format format); static bool is_integer(Format format); - static bool adjust_size(int &x_size, int &y_size, const std::string &name, + static bool adjust_size(int &x_size, int &y_size, std::string_view name, bool for_padding, AutoTextureScale auto_texture_scale = ATS_unspecified); - INLINE bool adjust_this_size(int &x_size, int &y_size, const std::string &name, + INLINE bool adjust_this_size(int &x_size, int &y_size, std::string_view name, bool for_padding) const; virtual void ensure_loader_type(const Filename &filename); @@ -667,7 +667,7 @@ class EXPCL_PANDA_GOBJ Texture : public TypedWritableReferenceCount, public Nama // pointer representing that lock); generally, they also avoid adjusting the // _properties_modified and _image_modified semaphores. virtual bool do_adjust_this_size(const CData *cdata, - int &x_size, int &y_size, const std::string &name, + int &x_size, int &y_size, std::string_view name, bool for_padding) const; virtual bool do_read(CData *cdata, @@ -681,19 +681,19 @@ class EXPCL_PANDA_GOBJ Texture : public TypedWritableReferenceCount, public Nama const LoaderOptions &options, bool header_only, BamCacheRecord *record); virtual bool do_load_one(CData *cdata, - const PNMImage &pnmimage, const std::string &name, + const PNMImage &pnmimage, std::string_view name, int z, int n, const LoaderOptions &options); virtual bool do_load_one(CData *cdata, - const PfmFile &pfm, const std::string &name, + const PfmFile &pfm, std::string_view name, int z, int n, const LoaderOptions &options); virtual bool do_load_sub_image(CData *cdata, const PNMImage &image, int x, int y, int z, int n); bool do_read_txo_file(CData *cdata, const Filename &fullpath); - bool do_read_txo(CData *cdata, std::istream &in, const std::string &filename); + bool do_read_txo(CData *cdata, std::istream &in, std::string_view filename); bool do_read_dds_file(CData *cdata, const Filename &fullpath, bool header_only); - bool do_read_dds(CData *cdata, std::istream &in, const std::string &filename, bool header_only); + bool do_read_dds(CData *cdata, std::istream &in, std::string_view filename, bool header_only); bool do_read_ktx_file(CData *cdata, const Filename &fullpath, bool header_only); - bool do_read_ktx(CData *cdata, std::istream &in, const std::string &filename, bool header_only); + bool do_read_ktx(CData *cdata, std::istream &in, std::string_view filename, bool header_only); bool do_write(CData *cdata, const Filename &fullpath, int z, int n, bool write_pages, bool write_mipmaps); @@ -701,7 +701,7 @@ class EXPCL_PANDA_GOBJ Texture : public TypedWritableReferenceCount, public Nama bool do_store_one(CData *cdata, PNMImage &pnmimage, int z, int n); bool do_store_one(CData *cdata, PfmFile &pfm, int z, int n); bool do_write_txo_file(const CData *cdata, const Filename &fullpath) const; - bool do_write_txo(const CData *cdata, std::ostream &out, const std::string &filename) const; + bool do_write_txo(const CData *cdata, std::ostream &out, std::string_view filename) const; virtual CData *unlocked_ensure_ram_image(bool allow_compression); virtual void do_reload_ram_image(CData *cdata, bool allow_compression); @@ -868,7 +868,7 @@ class EXPCL_PANDA_GOBJ Texture : public TypedWritableReferenceCount, public Nama void clear_prepared(PreparedGraphicsObjects *prepared_objects); - static void consider_downgrade(PNMImage &pnmimage, int num_channels, const std::string &name); + static void consider_downgrade(PNMImage &pnmimage, int num_channels, std::string_view name); static bool compare_images(const PNMImage &a, const PNMImage &b); @@ -1091,7 +1091,7 @@ class EXPCL_PANDA_GOBJ Texture : public TypedWritableReferenceCount, public Nama private: // The auxiliary data is not recorded to a bam file. - typedef pmap AuxData; + typedef pmap> AuxData; AuxData _aux_data; static AutoTextureScale _textures_power_2; diff --git a/panda/src/gobj/textureCollection.cxx b/panda/src/gobj/textureCollection.cxx index 57f91a8ef8e..15b8c43977d 100644 --- a/panda/src/gobj/textureCollection.cxx +++ b/panda/src/gobj/textureCollection.cxx @@ -181,7 +181,7 @@ reserve(size_t num) { * NULL if no texture has that name. */ Texture *TextureCollection:: -find_texture(const std::string &name) const { +find_texture(std::string_view name) const { int num_textures = get_num_textures(); for (int i = 0; i < num_textures; i++) { Texture *texture = get_texture(i); diff --git a/panda/src/gobj/textureCollection.h b/panda/src/gobj/textureCollection.h index f83f03720cd..aafdb253547 100644 --- a/panda/src/gobj/textureCollection.h +++ b/panda/src/gobj/textureCollection.h @@ -41,7 +41,7 @@ class EXPCL_PANDA_GOBJ TextureCollection { void clear(); void reserve(size_t num); - Texture *find_texture(const std::string &name) const; + Texture *find_texture(std::string_view name) const; int get_num_textures() const; Texture *get_texture(int index) const; diff --git a/panda/src/gobj/texturePool.I b/panda/src/gobj/texturePool.I index 02e26ac58c8..f71e583a5ee 100644 --- a/panda/src/gobj/texturePool.I +++ b/panda/src/gobj/texturePool.I @@ -241,8 +241,8 @@ list_contents() { * if it is not. */ INLINE Texture *TexturePool:: -find_texture(const std::string &name) { - return get_global_ptr()->ns_find_texture(name); +find_texture(std::string name) { + return get_global_ptr()->ns_find_texture(std::move(name)); } /** @@ -250,8 +250,8 @@ find_texture(const std::string &name) { * name (which may contain wildcards). */ INLINE TextureCollection TexturePool:: -find_all_textures(const std::string &name) { - return get_global_ptr()->ns_find_all_textures(name); +find_all_textures(std::string name) { + return get_global_ptr()->ns_find_all_textures(std::move(name)); } /** @@ -295,7 +295,7 @@ get_fake_texture_image() { * register_texture_type(). */ PT(Texture) TexturePool:: -make_texture(const std::string &extension) { +make_texture(std::string_view extension) { return get_global_ptr()->ns_make_texture(extension); } diff --git a/panda/src/gobj/texturePool.cxx b/panda/src/gobj/texturePool.cxx index 6143fc3357b..4cc9f3e2320 100644 --- a/panda/src/gobj/texturePool.cxx +++ b/panda/src/gobj/texturePool.cxx @@ -56,7 +56,7 @@ write(ostream &out) { * insensitive. */ void TexturePool:: -register_texture_type(MakeTextureFunc *func, const string &extensions) { +register_texture_type(MakeTextureFunc *func, std::string_view extensions) { MutexHolder holder(_lock); vector_string words; @@ -161,7 +161,7 @@ get_filter(size_t i) const { * extension is not one of the extensions for a texture file. */ TexturePool::MakeTextureFunc *TexturePool:: -get_texture_type(const string &extension) const { +get_texture_type(std::string_view extension) const { MutexHolder holder(_lock); string c = downcase(extension); @@ -1164,9 +1164,9 @@ ns_list_contents(ostream &out) const { * The nonstatic implementation of find_texture(). */ Texture *TexturePool:: -ns_find_texture(const string &name) const { +ns_find_texture(std::string name) const { MutexHolder holder(_lock); - GlobPattern glob(name); + GlobPattern glob(std::move(name)); Textures::const_iterator ti; for (ti = _textures.begin(); ti != _textures.end(); ++ti) { @@ -1183,10 +1183,10 @@ ns_find_texture(const string &name) const { * The nonstatic implementation of find_all_textures(). */ TextureCollection TexturePool:: -ns_find_all_textures(const string &name) const { +ns_find_all_textures(std::string name) const { MutexHolder holder(_lock); TextureCollection result; - GlobPattern glob(name); + GlobPattern glob(std::move(name)); Textures::const_iterator ti; for (ti = _textures.begin(); ti != _textures.end(); ++ti) { @@ -1205,7 +1205,7 @@ ns_find_all_textures(const string &name) const { * register_texture_type(). */ PT(Texture) TexturePool:: -ns_make_texture(const string &extension) const { +ns_make_texture(std::string_view extension) const { MakeTextureFunc *func = get_texture_type(extension); if (func != nullptr) { return func(); diff --git a/panda/src/gobj/texturePool.h b/panda/src/gobj/texturePool.h index dee02921845..32b0e69cd6c 100644 --- a/panda/src/gobj/texturePool.h +++ b/panda/src/gobj/texturePool.h @@ -84,14 +84,14 @@ class EXPCL_PANDA_GOBJ TexturePool { INLINE static void list_contents(std::ostream &out); INLINE static void list_contents(); - INLINE static Texture *find_texture(const std::string &name); - INLINE static TextureCollection find_all_textures(const std::string &name = "*"); + INLINE static Texture *find_texture(std::string name); + INLINE static TextureCollection find_all_textures(std::string name = "*"); INLINE static void set_fake_texture_image(const Filename &filename); INLINE static void clear_fake_texture_image(); INLINE static bool has_fake_texture_image(); INLINE static const Filename &get_fake_texture_image(); - INLINE static PT(Texture) make_texture(const std::string &extension); + INLINE static PT(Texture) make_texture(std::string_view extension); INLINE static bool register_filter(TexturePoolFilter *tex_filter); INLINE static bool unregister_filter(TexturePoolFilter *tex_filter); @@ -113,9 +113,9 @@ class EXPCL_PANDA_GOBJ TexturePool { public: typedef Texture::MakeTextureFunc MakeTextureFunc; - void register_texture_type(MakeTextureFunc *func, const std::string &extensions); + void register_texture_type(MakeTextureFunc *func, std::string_view extensions); - MakeTextureFunc *get_texture_type(const std::string &extension) const; + MakeTextureFunc *get_texture_type(std::string_view extension) const; void write_texture_types(std::ostream &out, int indent_level) const; private: @@ -166,9 +166,9 @@ class EXPCL_PANDA_GOBJ TexturePool { void ns_release_all_textures(); int ns_garbage_collect(); void ns_list_contents(std::ostream &out) const; - Texture *ns_find_texture(const std::string &name) const; - TextureCollection ns_find_all_textures(const std::string &name) const; - PT(Texture) ns_make_texture(const std::string &extension) const; + Texture *ns_find_texture(std::string name) const; + TextureCollection ns_find_all_textures(std::string name) const; + PT(Texture) ns_make_texture(std::string_view extension) const; void resolve_filename(Filename &new_filename, const Filename &orig_filename, bool read_mipmaps, const LoaderOptions &options); diff --git a/panda/src/gobj/textureReloadRequest.I b/panda/src/gobj/textureReloadRequest.I index 05ac192cfa1..cdb505b59d2 100644 --- a/panda/src/gobj/textureReloadRequest.I +++ b/panda/src/gobj/textureReloadRequest.I @@ -16,10 +16,10 @@ * load_async(), to begin an asynchronous load. */ INLINE TextureReloadRequest:: -TextureReloadRequest(const std::string &name, +TextureReloadRequest(std::string name, PreparedGraphicsObjects *pgo, Texture *texture, bool allow_compressed) : - AsyncTask(name), + AsyncTask(std::move(name)), _pgo(pgo), _texture(texture), _allow_compressed(allow_compressed) diff --git a/panda/src/gobj/textureReloadRequest.h b/panda/src/gobj/textureReloadRequest.h index 1010cd7ec5f..5bd8299a3d3 100644 --- a/panda/src/gobj/textureReloadRequest.h +++ b/panda/src/gobj/textureReloadRequest.h @@ -35,7 +35,7 @@ class EXPCL_PANDA_GOBJ TextureReloadRequest : public AsyncTask { ALLOC_DELETED_CHAIN(TextureReloadRequest); PUBLISHED: - INLINE explicit TextureReloadRequest(const std::string &name, + INLINE explicit TextureReloadRequest(std::string name, PreparedGraphicsObjects *pgo, Texture *texture, bool allow_compressed); diff --git a/panda/src/gobj/textureStage.I b/panda/src/gobj/textureStage.I index a6d26d8600f..5c92b7dadf9 100644 --- a/panda/src/gobj/textureStage.I +++ b/panda/src/gobj/textureStage.I @@ -31,8 +31,8 @@ get_name() const { * Changes the name of this texture stage */ INLINE void TextureStage:: -set_name(const std::string &name) { - _name = name; +set_name(std::string name) { + _name = std::move(name); } /** @@ -121,7 +121,7 @@ set_texcoord_name(InternalName *name) { * any number of associated UV sets, each of which must have a unique name. */ INLINE void TextureStage:: -set_texcoord_name(const std::string &name) { +set_texcoord_name(std::string_view name) { set_texcoord_name(InternalName::get_texcoord_name(name)); } diff --git a/panda/src/gobj/textureStage.cxx b/panda/src/gobj/textureStage.cxx index 82920837735..64ffefcccca 100644 --- a/panda/src/gobj/textureStage.cxx +++ b/panda/src/gobj/textureStage.cxx @@ -28,8 +28,8 @@ TypeHandle TextureStage::_type_handle; * Initialize the texture stage at construction */ TextureStage:: -TextureStage(const std::string &name) : _used_by_auto_shader(false) { - _name = name; +TextureStage(std::string name) : _used_by_auto_shader(false) { + _name = std::move(name); _sort = 0; _priority = 0; _texcoord_name = InternalName::get_texcoord(); diff --git a/panda/src/gobj/textureStage.h b/panda/src/gobj/textureStage.h index ff5bcb82be7..5b35d174cd4 100644 --- a/panda/src/gobj/textureStage.h +++ b/panda/src/gobj/textureStage.h @@ -34,7 +34,7 @@ class FactoryParams; */ class EXPCL_PANDA_GOBJ TextureStage : public TypedWritableReferenceCount { PUBLISHED: - explicit TextureStage(const std::string &name); + explicit TextureStage(std::string name); INLINE TextureStage(const TextureStage ©); void operator = (const TextureStage ©); @@ -103,7 +103,7 @@ class EXPCL_PANDA_GOBJ TextureStage : public TypedWritableReferenceCount { CO_one_minus_src_alpha, }; - INLINE void set_name(const std::string &name); + INLINE void set_name(std::string name); INLINE const std::string &get_name() const; INLINE void set_sort(int sort); @@ -113,7 +113,7 @@ class EXPCL_PANDA_GOBJ TextureStage : public TypedWritableReferenceCount { INLINE int get_priority() const; INLINE void set_texcoord_name(InternalName *name); - INLINE void set_texcoord_name(const std::string &texcoord_name); + INLINE void set_texcoord_name(std::string_view texcoord_name); INLINE InternalName *get_texcoord_name() const; INLINE InternalName *get_tangent_name() const; INLINE InternalName *get_binormal_name() const; diff --git a/panda/src/gobj/texture_ext.cxx b/panda/src/gobj/texture_ext.cxx index 57393a14c6b..d5947f105de 100644 --- a/panda/src/gobj/texture_ext.cxx +++ b/panda/src/gobj/texture_ext.cxx @@ -92,7 +92,7 @@ set_ram_image(PyObject *image, Texture::CompressionMode compression, * support compressed image data or sub-pages; use set_ram_image() for that. */ void Extension:: -set_ram_image_as(PyObject *image, const std::string &provided_format) { +set_ram_image_as(PyObject *image, std::string_view provided_format) { // Check if perhaps a PointerToArray object was passed in. if (DtoolInstance_Check(image)) { if (DtoolInstance_TYPE(image) == &Dtool_ConstPointerToArray_unsigned_char) { diff --git a/panda/src/gobj/texture_ext.h b/panda/src/gobj/texture_ext.h index bebe54557f5..1b8f4b1c8a9 100644 --- a/panda/src/gobj/texture_ext.h +++ b/panda/src/gobj/texture_ext.h @@ -31,7 +31,7 @@ class Extension : public ExtensionBase { public: void set_ram_image(PyObject *image, Texture::CompressionMode compression = Texture::CM_off, size_t page_size = 0); - void set_ram_image_as(PyObject *image, const std::string &provided_format); + void set_ram_image_as(PyObject *image, std::string_view provided_format); PT(Texture) __deepcopy__(PyObject *memo) const; }; diff --git a/panda/src/gobj/userVertexSlider.cxx b/panda/src/gobj/userVertexSlider.cxx index a868be2058b..b1723ed6aeb 100644 --- a/panda/src/gobj/userVertexSlider.cxx +++ b/panda/src/gobj/userVertexSlider.cxx @@ -21,7 +21,7 @@ TypeHandle UserVertexSlider::_type_handle; * */ UserVertexSlider:: -UserVertexSlider(const std::string &name) : +UserVertexSlider(std::string_view name) : VertexSlider(InternalName::make(name)) { } diff --git a/panda/src/gobj/userVertexSlider.h b/panda/src/gobj/userVertexSlider.h index 574e6bc6b7c..eca7d3ef5f8 100644 --- a/panda/src/gobj/userVertexSlider.h +++ b/panda/src/gobj/userVertexSlider.h @@ -30,7 +30,7 @@ class FactoryParams; */ class EXPCL_PANDA_GOBJ UserVertexSlider : public VertexSlider { PUBLISHED: - explicit UserVertexSlider(const std::string &name); + explicit UserVertexSlider(std::string_view name); explicit UserVertexSlider(const InternalName *name); INLINE void set_slider(PN_stdfloat slider); diff --git a/panda/src/gobj/userVertexTransform.cxx b/panda/src/gobj/userVertexTransform.cxx index c27cb38d618..3cb7da6a698 100644 --- a/panda/src/gobj/userVertexTransform.cxx +++ b/panda/src/gobj/userVertexTransform.cxx @@ -21,8 +21,8 @@ TypeHandle UserVertexTransform::_type_handle; * */ UserVertexTransform:: -UserVertexTransform(const std::string &name) : - _name(name) +UserVertexTransform(std::string name) : + _name(std::move(name)) { } diff --git a/panda/src/gobj/userVertexTransform.h b/panda/src/gobj/userVertexTransform.h index 356d4f823af..1c0ed27ffa7 100644 --- a/panda/src/gobj/userVertexTransform.h +++ b/panda/src/gobj/userVertexTransform.h @@ -30,7 +30,7 @@ class FactoryParams; */ class EXPCL_PANDA_GOBJ UserVertexTransform : public VertexTransform { PUBLISHED: - explicit UserVertexTransform(const std::string &name); + explicit UserVertexTransform(std::string name); INLINE const std::string &get_name() const; diff --git a/panda/src/gobj/vertexDataPage.cxx b/panda/src/gobj/vertexDataPage.cxx index 7f48d39d0ae..631ad8ff386 100644 --- a/panda/src/gobj/vertexDataPage.cxx +++ b/panda/src/gobj/vertexDataPage.cxx @@ -919,8 +919,8 @@ stop_threads() { * */ VertexDataPage::PageThread:: -PageThread(PageThreadManager *manager, const std::string &name) : - Thread(name, name), +PageThread(PageThreadManager *manager, std::string_view name) : + Thread(std::string(name), std::string(name)), _manager(manager), _working_cvar(_tlock) { diff --git a/panda/src/gobj/vertexDataPage.h b/panda/src/gobj/vertexDataPage.h index 4aafeebac16..2064f0e5c66 100644 --- a/panda/src/gobj/vertexDataPage.h +++ b/panda/src/gobj/vertexDataPage.h @@ -113,7 +113,7 @@ class EXPCL_PANDA_GOBJ VertexDataPage : public SimpleAllocator, public SimpleLru class PageThreadManager; class EXPCL_PANDA_GOBJ PageThread : public Thread { public: - PageThread(PageThreadManager *manager, const std::string &name); + PageThread(PageThreadManager *manager, std::string_view name); protected: virtual void thread_main(); diff --git a/panda/src/gobj/vertexDataSaveFile.cxx b/panda/src/gobj/vertexDataSaveFile.cxx index 1cc96719c7b..558071c21d6 100644 --- a/panda/src/gobj/vertexDataSaveFile.cxx +++ b/panda/src/gobj/vertexDataSaveFile.cxx @@ -35,7 +35,7 @@ using std::hex; * */ VertexDataSaveFile:: -VertexDataSaveFile(const Filename &directory, const std::string &prefix, +VertexDataSaveFile(const Filename &directory, std::string_view prefix, size_t max_size) : SimpleAllocator(max_size, _lock) { diff --git a/panda/src/gobj/vertexDataSaveFile.h b/panda/src/gobj/vertexDataSaveFile.h index 56eac67ee33..d6e6d3755f2 100644 --- a/panda/src/gobj/vertexDataSaveFile.h +++ b/panda/src/gobj/vertexDataSaveFile.h @@ -35,7 +35,7 @@ class VertexDataSaveBlock; */ class EXPCL_PANDA_GOBJ VertexDataSaveFile : public SimpleAllocator { public: - VertexDataSaveFile(const Filename &directory, const std::string &prefix, + VertexDataSaveFile(const Filename &directory, std::string_view prefix, size_t max_size); ~VertexDataSaveFile(); diff --git a/panda/src/gobj/videoTexture.cxx b/panda/src/gobj/videoTexture.cxx index a3b5e2c72bd..6388b64ef92 100644 --- a/panda/src/gobj/videoTexture.cxx +++ b/panda/src/gobj/videoTexture.cxx @@ -23,8 +23,8 @@ TypeHandle VideoTexture::_type_handle; * */ VideoTexture:: -VideoTexture(const std::string &name) : - Texture(name) +VideoTexture(std::string name) : + Texture(std::move(name)) { // We don't want to try to compress each frame as it's loaded. Texture::CDWriter cdata(Texture::_cycler, true); @@ -181,7 +181,7 @@ do_can_reload(const Texture::CData *cdata) const { */ bool VideoTexture:: do_adjust_this_size(const Texture::CData *cdata_tex, - int &x_size, int &y_size, const std::string &name, + int &x_size, int &y_size, std::string_view name, bool for_padding) const { AutoTextureScale ats = do_get_auto_texture_scale(cdata_tex); if (ats != ATS_none) { diff --git a/panda/src/gobj/videoTexture.h b/panda/src/gobj/videoTexture.h index b9a0b4540ec..63436b90e82 100644 --- a/panda/src/gobj/videoTexture.h +++ b/panda/src/gobj/videoTexture.h @@ -27,7 +27,7 @@ */ class EXPCL_PANDA_GOBJ VideoTexture : public Texture, public AnimInterface { protected: - VideoTexture(const std::string &name); + VideoTexture(std::string name); VideoTexture(const VideoTexture ©); PUBLISHED: @@ -53,7 +53,7 @@ class EXPCL_PANDA_GOBJ VideoTexture : public Texture, public AnimInterface { virtual bool do_can_reload(const Texture::CData *cdata) const; virtual bool do_adjust_this_size(const Texture::CData *cdata, - int &x_size, int &y_size, const std::string &name, + int &x_size, int &y_size, std::string_view name, bool for_padding) const; virtual void consider_update(); diff --git a/panda/src/grutil/cardMaker.I b/panda/src/grutil/cardMaker.I index 2f8a17a7dc2..bc329f8291a 100644 --- a/panda/src/grutil/cardMaker.I +++ b/panda/src/grutil/cardMaker.I @@ -15,7 +15,7 @@ * */ INLINE CardMaker:: -CardMaker(const std::string &name) : Namable(name) { +CardMaker(std::string name) : Namable(std::move(name)) { reset(); } diff --git a/panda/src/grutil/cardMaker.h b/panda/src/grutil/cardMaker.h index 0ac90f23163..d930ac70392 100644 --- a/panda/src/grutil/cardMaker.h +++ b/panda/src/grutil/cardMaker.h @@ -28,7 +28,7 @@ */ class EXPCL_PANDA_GRUTIL CardMaker : public Namable { PUBLISHED: - INLINE explicit CardMaker(const std::string &name); + INLINE explicit CardMaker(std::string name); INLINE ~CardMaker(); void reset(); diff --git a/panda/src/grutil/fisheyeMaker.I b/panda/src/grutil/fisheyeMaker.I index 54085a23e0b..cb87d9277fe 100644 --- a/panda/src/grutil/fisheyeMaker.I +++ b/panda/src/grutil/fisheyeMaker.I @@ -15,7 +15,7 @@ * */ INLINE FisheyeMaker:: -FisheyeMaker(const std::string &name) : Namable(name) { +FisheyeMaker(std::string name) : Namable(std::move(name)) { reset(); } diff --git a/panda/src/grutil/fisheyeMaker.h b/panda/src/grutil/fisheyeMaker.h index 83aa118ac35..edc79cad277 100644 --- a/panda/src/grutil/fisheyeMaker.h +++ b/panda/src/grutil/fisheyeMaker.h @@ -33,7 +33,7 @@ class GeomVertexWriter; */ class EXPCL_PANDA_GRUTIL FisheyeMaker : public Namable { PUBLISHED: - INLINE explicit FisheyeMaker(const std::string &name); + INLINE explicit FisheyeMaker(std::string name); INLINE ~FisheyeMaker(); void reset(); diff --git a/panda/src/grutil/frameRateMeter.I b/panda/src/grutil/frameRateMeter.I index 02877fa226b..e9cd2f28f1e 100644 --- a/panda/src/grutil/frameRateMeter.I +++ b/panda/src/grutil/frameRateMeter.I @@ -56,8 +56,8 @@ get_update_interval() const { * per second. */ INLINE void FrameRateMeter:: -set_text_pattern(const std::string &text_pattern) { - _text_pattern = text_pattern; +set_text_pattern(std::string text_pattern) { + _text_pattern = std::move(text_pattern); Thread *current_thread = Thread::get_current_thread(); do_update(current_thread); } diff --git a/panda/src/grutil/frameRateMeter.cxx b/panda/src/grutil/frameRateMeter.cxx index cb734110e31..882eb964636 100644 --- a/panda/src/grutil/frameRateMeter.cxx +++ b/panda/src/grutil/frameRateMeter.cxx @@ -31,8 +31,8 @@ TypeHandle FrameRateMeter::_type_handle; * */ FrameRateMeter:: -FrameRateMeter(const std::string &name) : - TextNode(name), +FrameRateMeter(std::string name) : + TextNode(std::move(name)), _last_aspect_ratio(-1) { set_cull_callback(); diff --git a/panda/src/grutil/frameRateMeter.h b/panda/src/grutil/frameRateMeter.h index 5faa692a436..3660645a538 100644 --- a/panda/src/grutil/frameRateMeter.h +++ b/panda/src/grutil/frameRateMeter.h @@ -36,7 +36,7 @@ class ClockObject; */ class EXPCL_PANDA_GRUTIL FrameRateMeter : public TextNode { PUBLISHED: - explicit FrameRateMeter(const std::string &name); + explicit FrameRateMeter(std::string name); virtual ~FrameRateMeter(); void setup_window(GraphicsOutput *window); @@ -48,7 +48,7 @@ class EXPCL_PANDA_GRUTIL FrameRateMeter : public TextNode { INLINE void set_update_interval(double update_interval); INLINE double get_update_interval() const; - INLINE void set_text_pattern(const std::string &text_pattern); + INLINE void set_text_pattern(std::string text_pattern); INLINE const std::string &get_text_pattern() const; INLINE void set_clock_object(ClockObject *clock_object); diff --git a/panda/src/grutil/geoMipTerrain.I b/panda/src/grutil/geoMipTerrain.I index 681cfce24e8..18abc1d639e 100644 --- a/panda/src/grutil/geoMipTerrain.I +++ b/panda/src/grutil/geoMipTerrain.I @@ -17,8 +17,8 @@ * */ INLINE GeoMipTerrain:: -GeoMipTerrain(const std::string &name) { - _root = NodePath(name); +GeoMipTerrain(std::string name) { + _root = NodePath(std::move(name)); _root_flattened = false; _xsize = 0; _ysize = 0; @@ -429,7 +429,7 @@ set_color_map(const Texture *tex) { } INLINE bool GeoMipTerrain:: -set_color_map(const std::string &path) { +set_color_map(std::string_view path) { return set_color_map(Filename(path)); } diff --git a/panda/src/grutil/geoMipTerrain.h b/panda/src/grutil/geoMipTerrain.h index 1075e865de7..888757a39fd 100644 --- a/panda/src/grutil/geoMipTerrain.h +++ b/panda/src/grutil/geoMipTerrain.h @@ -35,7 +35,7 @@ */ class EXPCL_PANDA_GRUTIL GeoMipTerrain : public TypedObject { PUBLISHED: - INLINE explicit GeoMipTerrain(const std::string &name); + INLINE explicit GeoMipTerrain(std::string name); INLINE ~GeoMipTerrain(); INLINE PNMImage &heightfield(); @@ -46,7 +46,7 @@ class EXPCL_PANDA_GRUTIL GeoMipTerrain : public TypedObject { PNMFileType *type = nullptr); INLINE bool set_color_map(const PNMImage &image); INLINE bool set_color_map(const Texture *image); - INLINE bool set_color_map(const std::string &path); + INLINE bool set_color_map(std::string_view path); INLINE bool has_color_map() const; INLINE void clear_color_map(); void calc_ambient_occlusion(PN_stdfloat radius = 32, PN_stdfloat contrast = 2.0f, PN_stdfloat brightness = 0.75f); diff --git a/panda/src/grutil/heightfieldTesselator.I b/panda/src/grutil/heightfieldTesselator.I index 7bab2b0a459..dfba1a2b96f 100644 --- a/panda/src/grutil/heightfieldTesselator.I +++ b/panda/src/grutil/heightfieldTesselator.I @@ -15,7 +15,7 @@ * */ INLINE HeightfieldTesselator:: -HeightfieldTesselator(const std::string &name) : Namable(name) { +HeightfieldTesselator(std::string name) : Namable(std::move(name)) { _poly_count = 10000; _visibility_radius = 32768; _focal_x = 0; diff --git a/panda/src/grutil/heightfieldTesselator.h b/panda/src/grutil/heightfieldTesselator.h index f2d358a82fa..40c3366ba0e 100644 --- a/panda/src/grutil/heightfieldTesselator.h +++ b/panda/src/grutil/heightfieldTesselator.h @@ -57,7 +57,7 @@ class EXPCL_PANDA_GRUTIL HeightfieldTesselator : public Namable { PUBLISHED: - INLINE explicit HeightfieldTesselator(const std::string &name); + INLINE explicit HeightfieldTesselator(std::string name); INLINE ~HeightfieldTesselator(); INLINE PNMImage &heightfield(); diff --git a/panda/src/grutil/htmlVideoTexture.cxx b/panda/src/grutil/htmlVideoTexture.cxx index c5182f141d4..393e023487f 100644 --- a/panda/src/grutil/htmlVideoTexture.cxx +++ b/panda/src/grutil/htmlVideoTexture.cxx @@ -43,8 +43,8 @@ TypeHandle HTMLVideoTexture::_type_handle; * Creates a blank movie texture. Movies must be added using do_read_one. */ HTMLVideoTexture:: -HTMLVideoTexture(const std::string &name) : - Texture(name) +HTMLVideoTexture(std::string name) : + Texture(std::move(name)) { EM_ASM_INT({ if (!window._htmlVideoData) { @@ -372,7 +372,7 @@ do_can_reload(const Texture::CData *cdata) const { */ bool HTMLVideoTexture:: do_adjust_this_size(const Texture::CData *cdata_tex, - int &x_size, int &y_size, const std::string &name, + int &x_size, int &y_size, std::string_view name, bool for_padding) const { // We always scale, for now. May change in the future. AutoTextureScale ats = do_get_auto_texture_scale(cdata_tex); @@ -510,7 +510,7 @@ do_read_one(Texture::CData *cdata_tex, */ bool HTMLVideoTexture:: do_load_one(Texture::CData *cdata_tex, - const PNMImage &pnmimage, const std::string &name, int z, int n, + const PNMImage &pnmimage, std::string_view name, int z, int n, const LoaderOptions &options) { grutil_cat.error() << "You cannot load a static image into an HTMLVideoTexture\n"; return false; @@ -521,7 +521,7 @@ do_load_one(Texture::CData *cdata_tex, */ bool HTMLVideoTexture:: do_load_one(Texture::CData *cdata_tex, - const PfmFile &pfm, const std::string &name, int z, int n, + const PfmFile &pfm, std::string_view name, int z, int n, const LoaderOptions &options) { grutil_cat.error() << "You cannot load a static image into an HTMLVideoTexture\n"; return false; diff --git a/panda/src/grutil/htmlVideoTexture.h b/panda/src/grutil/htmlVideoTexture.h index e8a1f6a023e..1918288c99b 100644 --- a/panda/src/grutil/htmlVideoTexture.h +++ b/panda/src/grutil/htmlVideoTexture.h @@ -32,7 +32,7 @@ */ class EXPCL_PANDA_GRUTIL HTMLVideoTexture : public Texture { PUBLISHED: - explicit HTMLVideoTexture(const std::string &name); + explicit HTMLVideoTexture(std::string name); HTMLVideoTexture(const HTMLVideoTexture ©) = delete; virtual ~HTMLVideoTexture(); @@ -85,7 +85,7 @@ class EXPCL_PANDA_GRUTIL HTMLVideoTexture : public Texture { virtual bool do_can_reload(const Texture::CData *cdata) const; virtual bool do_adjust_this_size(const Texture::CData *cdata, - int &x_size, int &y_size, const std::string &name, + int &x_size, int &y_size, std::string_view name, bool for_padding) const; virtual bool do_read_one(Texture::CData *cdata, @@ -94,10 +94,10 @@ class EXPCL_PANDA_GRUTIL HTMLVideoTexture : public Texture { const LoaderOptions &options, bool header_only, BamCacheRecord *record); virtual bool do_load_one(Texture::CData *cdata, - const PNMImage &pnmimage, const std::string &name, + const PNMImage &pnmimage, std::string_view name, int z, int n, const LoaderOptions &options); virtual bool do_load_one(Texture::CData *cdata, - const PfmFile &pfm, const std::string &name, + const PfmFile &pfm, std::string_view name, int z, int n, const LoaderOptions &options); private: diff --git a/panda/src/grutil/lineSegs.cxx b/panda/src/grutil/lineSegs.cxx index d5ea4fc14bb..da8f7f07084 100644 --- a/panda/src/grutil/lineSegs.cxx +++ b/panda/src/grutil/lineSegs.cxx @@ -29,7 +29,7 @@ * which will render the described path. */ LineSegs:: -LineSegs(const std::string &name) : Namable(name) { +LineSegs(std::string name) : Namable(std::move(name)) { _color.set(1.0f, 1.0f, 1.0f, 1.0f); _thick = 1.0f; } diff --git a/panda/src/grutil/lineSegs.h b/panda/src/grutil/lineSegs.h index a77d828306a..975eee5a77f 100644 --- a/panda/src/grutil/lineSegs.h +++ b/panda/src/grutil/lineSegs.h @@ -33,7 +33,7 @@ */ class EXPCL_PANDA_GRUTIL LineSegs : public Namable { PUBLISHED: - explicit LineSegs(const std::string &name = "lines"); + explicit LineSegs(std::string name = "lines"); ~LineSegs(); void reset(); diff --git a/panda/src/grutil/movieTexture.cxx b/panda/src/grutil/movieTexture.cxx index 2942a474674..255fbf737ef 100644 --- a/panda/src/grutil/movieTexture.cxx +++ b/panda/src/grutil/movieTexture.cxx @@ -36,8 +36,8 @@ TypeHandle MovieTexture::_type_handle; * do_load_one. */ MovieTexture:: -MovieTexture(const std::string &name) : - Texture(name) +MovieTexture(std::string name) : + Texture(std::move(name)) { } @@ -189,7 +189,7 @@ do_recalculate_image_properties(CData *cdata, Texture::CData *cdata_tex, const L */ bool MovieTexture:: do_adjust_this_size(const Texture::CData *cdata_tex, - int &x_size, int &y_size, const std::string &name, + int &x_size, int &y_size, std::string_view name, bool for_padding) const { AutoTextureScale ats = do_get_auto_texture_scale(cdata_tex); if (ats != ATS_none) { @@ -286,7 +286,7 @@ do_load_one(Texture::CData *cdata_tex, */ bool MovieTexture:: do_load_one(Texture::CData *cdata_tex, - const PNMImage &pnmimage, const std::string &name, int z, int n, + const PNMImage &pnmimage, std::string_view name, int z, int n, const LoaderOptions &options) { grutil_cat.error() << "You cannot load a static image into a MovieTexture\n"; return false; @@ -297,7 +297,7 @@ do_load_one(Texture::CData *cdata_tex, */ bool MovieTexture:: do_load_one(Texture::CData *cdata_tex, - const PfmFile &pfm, const std::string &name, int z, int n, + const PfmFile &pfm, std::string_view name, int z, int n, const LoaderOptions &options) { grutil_cat.error() << "You cannot load a static image into a MovieTexture\n"; return false; diff --git a/panda/src/grutil/movieTexture.h b/panda/src/grutil/movieTexture.h index 1a49c885b13..d1dd8961852 100644 --- a/panda/src/grutil/movieTexture.h +++ b/panda/src/grutil/movieTexture.h @@ -32,7 +32,7 @@ */ class EXPCL_PANDA_GRUTIL MovieTexture : public Texture { PUBLISHED: - explicit MovieTexture(const std::string &name); + explicit MovieTexture(std::string name); explicit MovieTexture(MovieVideo *video); MovieTexture(const MovieTexture ©) = delete; virtual ~MovieTexture(); @@ -91,7 +91,7 @@ class EXPCL_PANDA_GRUTIL MovieTexture : public Texture { virtual bool do_can_reload(const Texture::CData *cdata) const; virtual bool do_adjust_this_size(const Texture::CData *cdata, - int &x_size, int &y_size, const std::string &name, + int &x_size, int &y_size, std::string_view name, bool for_padding) const; virtual bool do_read_one(Texture::CData *cdata, @@ -100,10 +100,10 @@ class EXPCL_PANDA_GRUTIL MovieTexture : public Texture { const LoaderOptions &options, bool header_only, BamCacheRecord *record); virtual bool do_load_one(Texture::CData *cdata, - const PNMImage &pnmimage, const std::string &name, + const PNMImage &pnmimage, std::string_view name, int z, int n, const LoaderOptions &options); virtual bool do_load_one(Texture::CData *cdata, - const PfmFile &pfm, const std::string &name, + const PfmFile &pfm, std::string_view name, int z, int n, const LoaderOptions &options); bool do_load_one(Texture::CData *cdata, PT(MovieVideoCursor) color, PT(MovieVideoCursor) alpha, diff --git a/panda/src/grutil/multitexReducer.cxx b/panda/src/grutil/multitexReducer.cxx index f2b31070519..68e0e705f56 100644 --- a/panda/src/grutil/multitexReducer.cxx +++ b/panda/src/grutil/multitexReducer.cxx @@ -718,7 +718,8 @@ make_texture_layer(const NodePath &render, case TextureStage::M_occlusion: case TextureStage::M_occlusion_metallic_roughness: // Don't know what to do with these funny modes. We should probably raise - // an exception or something. Fall through for now. + // an exception or something. + [[fallthrough]]; case TextureStage::M_modulate_glow: case TextureStage::M_modulate_gloss: diff --git a/panda/src/grutil/pfmVizzer.cxx b/panda/src/grutil/pfmVizzer.cxx index f3d60787a83..e622abfb176 100644 --- a/panda/src/grutil/pfmVizzer.cxx +++ b/panda/src/grutil/pfmVizzer.cxx @@ -476,8 +476,8 @@ make_displacement(PNMImage &result, double max_u, double max_v, bool for_32bit) // We use the blue channel to mark holes, so we can fill them in later. result.set_xel_val(xi, yi, - min(max(u_val, 0), PNM_MAXMAXVAL), - min(max(v_val, 0), PNM_MAXMAXVAL), + std::clamp(u_val, 0, PNM_MAXMAXVAL), + std::clamp(v_val, 0, PNM_MAXMAXVAL), 0); } } @@ -647,8 +647,8 @@ r_fill_displacement(PNMImage &result, int xi, int yi, int u_val = midval + (int)cfloor(x_shift * u_scale + 0.5); int v_val = midval + (int)cfloor(y_shift * v_scale + 0.5); result.set_xel_val(xi, yi, - min(max(u_val, 0), PNM_MAXMAXVAL), - min(max(v_val, 0), PNM_MAXMAXVAL), + std::clamp(u_val, 0, PNM_MAXMAXVAL), + std::clamp(v_val, 0, PNM_MAXMAXVAL), min(distance, PNM_MAXMAXVAL)); r_fill_displacement(result, xi - 1, yi, nxi, nyi, u_scale, v_scale, distance + 1); diff --git a/panda/src/grutil/rigidBodyCombiner.cxx b/panda/src/grutil/rigidBodyCombiner.cxx index 76ec13a5381..6db5e18c511 100644 --- a/panda/src/grutil/rigidBodyCombiner.cxx +++ b/panda/src/grutil/rigidBodyCombiner.cxx @@ -30,10 +30,10 @@ TypeHandle RigidBodyCombiner::_type_handle; * */ RigidBodyCombiner:: -RigidBodyCombiner(const std::string &name) : PandaNode(name) { +RigidBodyCombiner(std::string name) : PandaNode(name) { set_cull_callback(); - _internal_root = new PandaNode(name); + _internal_root = new PandaNode(std::move(name)); // We don't want to perform any additional culling once we get within the // RigidBodyCombiner. The internal Geom's bounding volume is not updated diff --git a/panda/src/grutil/rigidBodyCombiner.h b/panda/src/grutil/rigidBodyCombiner.h index f1694f49b03..93ad75c63e9 100644 --- a/panda/src/grutil/rigidBodyCombiner.h +++ b/panda/src/grutil/rigidBodyCombiner.h @@ -43,7 +43,7 @@ class NodePath; */ class EXPCL_PANDA_GRUTIL RigidBodyCombiner : public PandaNode { PUBLISHED: - explicit RigidBodyCombiner(const std::string &name); + explicit RigidBodyCombiner(std::string name); protected: RigidBodyCombiner(const RigidBodyCombiner ©); virtual PandaNode *make_copy() const; diff --git a/panda/src/grutil/sceneGraphAnalyzerMeter.cxx b/panda/src/grutil/sceneGraphAnalyzerMeter.cxx index ad3ec115e83..0429e0d32ad 100644 --- a/panda/src/grutil/sceneGraphAnalyzerMeter.cxx +++ b/panda/src/grutil/sceneGraphAnalyzerMeter.cxx @@ -30,8 +30,8 @@ TypeHandle SceneGraphAnalyzerMeter::_type_handle; * */ SceneGraphAnalyzerMeter:: -SceneGraphAnalyzerMeter(const std::string &name, PandaNode *node) : - TextNode(name), +SceneGraphAnalyzerMeter(std::string name, PandaNode *node) : + TextNode(std::move(name)), _last_aspect_ratio(-1) { set_cull_callback(); diff --git a/panda/src/grutil/sceneGraphAnalyzerMeter.h b/panda/src/grutil/sceneGraphAnalyzerMeter.h index e7c184e81b5..9030caeafdb 100644 --- a/panda/src/grutil/sceneGraphAnalyzerMeter.h +++ b/panda/src/grutil/sceneGraphAnalyzerMeter.h @@ -38,7 +38,7 @@ class ClockObject; */ class EXPCL_PANDA_GRUTIL SceneGraphAnalyzerMeter : public TextNode { PUBLISHED: - explicit SceneGraphAnalyzerMeter(const std::string &name, PandaNode *node); + explicit SceneGraphAnalyzerMeter(std::string name, PandaNode *node); virtual ~SceneGraphAnalyzerMeter(); void setup_window(GraphicsOutput *window); diff --git a/panda/src/grutil/shaderTerrainMesh.cxx b/panda/src/grutil/shaderTerrainMesh.cxx index cd128e77711..f1e3a0479ee 100644 --- a/panda/src/grutil/shaderTerrainMesh.cxx +++ b/panda/src/grutil/shaderTerrainMesh.cxx @@ -719,7 +719,7 @@ bool ShaderTerrainMesh::do_check_lod_matches(Chunk* chunk, TraversalData* data) max_edge = csqrt(max_edge); PN_stdfloat tesselation_factor = (max_edge / _target_triangle_width) / (PN_stdfloat)_chunk_size; - PN_stdfloat clod_factor = max(0.0, min(1.0, 2.0 - tesselation_factor)); + PN_stdfloat clod_factor = std::clamp(2.0 - tesselation_factor, 0.0, 1.0); // Store the clod factor chunk->last_clod = clod_factor; diff --git a/panda/src/gsgbase/graphicsStateGuardianBase.h b/panda/src/gsgbase/graphicsStateGuardianBase.h index c3fac9a003a..fdbe393fd5d 100644 --- a/panda/src/gsgbase/graphicsStateGuardianBase.h +++ b/panda/src/gsgbase/graphicsStateGuardianBase.h @@ -250,7 +250,7 @@ class EXPCL_PANDA_GSGBASE GraphicsStateGuardianBase : public TypedWritableRefere #endif } - virtual void push_group_marker(const std::string &marker) {} + virtual void push_group_marker(std::string_view marker) {} virtual void pop_group_marker() {} PUBLISHED: diff --git a/panda/src/iphonedisplay/iPhoneGraphicsPipe.h b/panda/src/iphonedisplay/iPhoneGraphicsPipe.h index 12405bcbbce..f36b51a4de1 100644 --- a/panda/src/iphonedisplay/iPhoneGraphicsPipe.h +++ b/panda/src/iphonedisplay/iPhoneGraphicsPipe.h @@ -40,7 +40,7 @@ class EXPCL_MISC IPhoneGraphicsPipe : public GraphicsPipe { void rotate_windows(); protected: - virtual PT(GraphicsOutput) make_output(const std::string &name, + virtual PT(GraphicsOutput) make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/iphonedisplay/iPhoneGraphicsPipe.mm b/panda/src/iphonedisplay/iPhoneGraphicsPipe.mm index 82e92f4b70d..5aa3046f5ad 100644 --- a/panda/src/iphonedisplay/iPhoneGraphicsPipe.mm +++ b/panda/src/iphonedisplay/iPhoneGraphicsPipe.mm @@ -101,7 +101,7 @@ * Creates a new window on the pipe, if possible. */ PT(GraphicsOutput) IPhoneGraphicsPipe:: -make_output(const string &name, +make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -130,7 +130,7 @@ ((flags&BF_can_bind_every)!=0)) { return NULL; } - return new IPhoneGraphicsWindow(engine, this, name, fb_prop, win_prop, + return new IPhoneGraphicsWindow(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } diff --git a/panda/src/iphonedisplay/iPhoneGraphicsWindow.h b/panda/src/iphonedisplay/iPhoneGraphicsWindow.h index 6da377b18da..fed55696323 100644 --- a/panda/src/iphonedisplay/iPhoneGraphicsWindow.h +++ b/panda/src/iphonedisplay/iPhoneGraphicsWindow.h @@ -28,7 +28,7 @@ class IPhoneGraphicsWindow : public GraphicsWindow { public: IPhoneGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/iphonedisplay/iPhoneGraphicsWindow.mm b/panda/src/iphonedisplay/iPhoneGraphicsWindow.mm index 07be09f5806..15d6ff8db31 100644 --- a/panda/src/iphonedisplay/iPhoneGraphicsWindow.mm +++ b/panda/src/iphonedisplay/iPhoneGraphicsWindow.mm @@ -42,13 +42,13 @@ */ IPhoneGraphicsWindow:: IPhoneGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + GraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { IPhoneGraphicsPipe *ipipe; DCAST_INTO_V(ipipe, _pipe); diff --git a/panda/src/linmath/configVariableColor.I b/panda/src/linmath/configVariableColor.I index 751d7f415a5..22f1734d2a0 100644 --- a/panda/src/linmath/configVariableColor.I +++ b/panda/src/linmath/configVariableColor.I @@ -15,7 +15,7 @@ * */ INLINE ConfigVariableColor:: -ConfigVariableColor(const std::string &name) : +ConfigVariableColor(std::string_view name) : ConfigVariable(name, VT_color), _local_modified(initial_invalid_cache()), _cache(0, 0, 0, 1) @@ -27,12 +27,12 @@ ConfigVariableColor(const std::string &name) : * */ INLINE ConfigVariableColor:: -ConfigVariableColor(const std::string &name, const LColor &default_value, - const std::string &description, int flags) : +ConfigVariableColor(std::string_view name, const LColor &default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariable(name, ConfigVariableCore::VT_color, description, flags), #else - ConfigVariable(name, ConfigVariableCore::VT_color, std::string(), flags), + ConfigVariable(name, ConfigVariableCore::VT_color, std::string_view(), flags), #endif _local_modified(initial_invalid_cache()), _cache(0, 0, 0, 1) @@ -45,12 +45,12 @@ ConfigVariableColor(const std::string &name, const LColor &default_value, * */ INLINE ConfigVariableColor:: -ConfigVariableColor(const std::string &name, const std::string &default_value, - const std::string &description, int flags) : +ConfigVariableColor(std::string_view name, std::string_view default_value, + std::string_view description, int flags) : #ifdef PRC_SAVE_DESCRIPTIONS ConfigVariable(name, ConfigVariableCore::VT_color, description, flags), #else - ConfigVariable(name, ConfigVariableCore::VT_color, std::string(), flags), + ConfigVariable(name, ConfigVariableCore::VT_color, std::string_view(), flags), #endif _local_modified(initial_invalid_cache()), _cache(0, 0, 0, 1) diff --git a/panda/src/linmath/configVariableColor.h b/panda/src/linmath/configVariableColor.h index 0d095bd9023..57f865800e5 100644 --- a/panda/src/linmath/configVariableColor.h +++ b/panda/src/linmath/configVariableColor.h @@ -34,14 +34,14 @@ */ class EXPCL_PANDA_LINMATH ConfigVariableColor : public ConfigVariable { PUBLISHED: - INLINE explicit ConfigVariableColor(const std::string &name); - INLINE explicit ConfigVariableColor(const std::string &name, + INLINE explicit ConfigVariableColor(std::string_view name); + INLINE explicit ConfigVariableColor(std::string_view name, const LColor &default_value, - const std::string &description = std::string(), + std::string_view description = "", int flags = 0); - INLINE explicit ConfigVariableColor(const std::string &name, - const std::string &default_value, - const std::string &description = std::string(), + INLINE explicit ConfigVariableColor(std::string_view name, + std::string_view default_value, + std::string_view description = "", int flags = 0); INLINE void operator = (const LColor &value); diff --git a/panda/src/linmath/coordinateSystem.cxx b/panda/src/linmath/coordinateSystem.cxx index b94b0ec4ff0..18cc3013c47 100644 --- a/panda/src/linmath/coordinateSystem.cxx +++ b/panda/src/linmath/coordinateSystem.cxx @@ -41,7 +41,7 @@ get_default_coordinate_system() { CoordinateSystem -parse_coordinate_system_string(const string &str) { +parse_coordinate_system_string(std::string_view str) { if (cmp_nocase_uh(str, "default") == 0) { return CS_default; diff --git a/panda/src/linmath/coordinateSystem.h b/panda/src/linmath/coordinateSystem.h index 6de6f909902..ab2cb1f3bcb 100644 --- a/panda/src/linmath/coordinateSystem.h +++ b/panda/src/linmath/coordinateSystem.h @@ -36,7 +36,7 @@ enum CoordinateSystem { }; EXPCL_PANDA_LINMATH CoordinateSystem get_default_coordinate_system(); -EXPCL_PANDA_LINMATH CoordinateSystem parse_coordinate_system_string(const std::string &str); +EXPCL_PANDA_LINMATH CoordinateSystem parse_coordinate_system_string(std::string_view str); EXPCL_PANDA_LINMATH std::string format_coordinate_system(CoordinateSystem cs); EXPCL_PANDA_LINMATH bool is_right_handed(CoordinateSystem cs = CS_default); diff --git a/panda/src/linmath/lvecBase4_src.h b/panda/src/linmath/lvecBase4_src.h index 792877d373b..164220ffdbf 100644 --- a/panda/src/linmath/lvecBase4_src.h +++ b/panda/src/linmath/lvecBase4_src.h @@ -19,7 +19,7 @@ class FLOATNAME(LVector3); /** * This is the base class for all three-component vectors and points. */ -class EXPCL_PANDA_LINMATH ALIGN_LINMATH FLOATNAME(LVecBase4) : public MemoryBase { +class EXPCL_PANDA_LINMATH ALIGN_LINMATH FLOATNAME(LVecBase4) { PUBLISHED: typedef FLOATTYPE numeric_type; typedef const FLOATTYPE *iterator; @@ -41,7 +41,13 @@ class EXPCL_PANDA_LINMATH ALIGN_LINMATH FLOATNAME(LVecBase4) : public MemoryBase INLINE_LINMATH explicit FLOATNAME(LVecBase4)(const FLOATNAME(LVecBase3) ©, FLOATTYPE w); INLINE_LINMATH FLOATNAME(LVecBase4)(const FLOATNAME(LPoint3) &point); INLINE_LINMATH FLOATNAME(LVecBase4)(const FLOATNAME(LVector3) &vector); + +#ifdef USE_DELETED_CHAIN ALLOC_DELETED_CHAIN(FLOATNAME(LVecBase4)); +#else + // Don't inherit from MemoryBase directly to work around GCC<10.1 bug. + ALLOC_MEMORY_BASE; +#endif #ifdef CPPPARSER FLOATNAME(LVecBase4) &operator = (const FLOATNAME(LVecBase4) ©) = default; diff --git a/panda/src/mathutil/boundingVolume.cxx b/panda/src/mathutil/boundingVolume.cxx index a806dc819bc..d8d92c99ad3 100644 --- a/panda/src/mathutil/boundingVolume.cxx +++ b/panda/src/mathutil/boundingVolume.cxx @@ -158,20 +158,20 @@ as_bounding_plane() const { * Returns the BoundsType corresponding to the indicated string. */ BoundingVolume::BoundsType BoundingVolume:: -string_bounds_type(const string &str) { - if (strcmp(str.c_str(), "default") == 0) { +string_bounds_type(std::string_view str) { + if (str == "default") { return BT_default; - } else if (strcmp(str.c_str(), "best") == 0) { + } else if (str == "best") { return BT_best; - } else if (strcmp(str.c_str(), "fastest") == 0) { + } else if (str == "fastest") { return BT_fastest; - } else if (strcmp(str.c_str(), "sphere") == 0) { + } else if (str == "sphere") { return BT_sphere; - } else if (strcmp(str.c_str(), "box") == 0) { + } else if (str == "box") { return BT_box; } diff --git a/panda/src/mathutil/boundingVolume.h b/panda/src/mathutil/boundingVolume.h index 67bde458392..41796ab7659 100644 --- a/panda/src/mathutil/boundingVolume.h +++ b/panda/src/mathutil/boundingVolume.h @@ -43,7 +43,7 @@ class EXPCL_PANDA_MATHUTIL BoundingVolume : public TypedReferenceCount { INLINE_MATHUTIL BoundingVolume(); PUBLISHED: - virtual BoundingVolume *make_copy() const=0; + [[nodiscard]] virtual BoundingVolume *make_copy() const=0; INLINE_MATHUTIL bool is_empty() const; INLINE_MATHUTIL bool is_infinite() const; @@ -115,7 +115,7 @@ class EXPCL_PANDA_MATHUTIL BoundingVolume : public TypedReferenceCount { virtual const BoundingLine *as_bounding_line() const; virtual const BoundingPlane *as_bounding_plane() const; - static BoundsType string_bounds_type(const std::string &str); + static BoundsType string_bounds_type(std::string_view str); protected: enum Flags { diff --git a/panda/src/movies/movieAudio.cxx b/panda/src/movies/movieAudio.cxx index 6843984ac31..24619826471 100644 --- a/panda/src/movies/movieAudio.cxx +++ b/panda/src/movies/movieAudio.cxx @@ -24,8 +24,8 @@ TypeHandle MovieAudio::_type_handle; * construct a subclass of this class. */ MovieAudio:: -MovieAudio(const std::string &name) : - Namable(name) +MovieAudio(std::string name) : + Namable(std::move(name)) { } diff --git a/panda/src/movies/movieAudio.h b/panda/src/movies/movieAudio.h index 819f501e357..a471c71d21c 100644 --- a/panda/src/movies/movieAudio.h +++ b/panda/src/movies/movieAudio.h @@ -43,7 +43,7 @@ class MovieAudioCursor; */ class EXPCL_PANDA_MOVIES MovieAudio : public TypedWritableReferenceCount, public Namable { PUBLISHED: - explicit MovieAudio(const std::string &name = "Blank Audio"); + explicit MovieAudio(std::string name = "Blank Audio"); virtual ~MovieAudio(); virtual PT(MovieAudioCursor) open(); static PT(MovieAudio) get(const Filename &name); diff --git a/panda/src/movies/movieTypeRegistry.cxx b/panda/src/movies/movieTypeRegistry.cxx index f17b43010db..39ed05a2718 100644 --- a/panda/src/movies/movieTypeRegistry.cxx +++ b/panda/src/movies/movieTypeRegistry.cxx @@ -80,7 +80,7 @@ make_audio(const Filename &name) { * will be loaded as this type. You may use * as a catch-all extension. */ void MovieTypeRegistry:: -register_audio_type(MakeAudioFunc func, const string &extensions) { +register_audio_type(MakeAudioFunc func, std::string_view extensions) { ReMutexHolder holder(_audio_lock); vector_string words; extract_words(downcase(extensions), words); @@ -117,7 +117,7 @@ load_audio_types() { if (words.size() == 1) { // Exactly one word: load the named library immediately. - string name = words[0]; + const string &name = words[0]; Filename dlname = Filename::dso_filename("lib" + name + ".so"); movies_cat.info() << "loading audio type module: " << name << endl; @@ -210,7 +210,7 @@ make_video(const Filename &name) { * will be loaded as this type. You may use * as a catch-all extension. */ void MovieTypeRegistry:: -register_video_type(MakeVideoFunc func, const string &extensions) { +register_video_type(MakeVideoFunc func, std::string_view extensions) { ReMutexHolder holder(_video_lock); vector_string words; extract_words(downcase(extensions), words); @@ -247,7 +247,7 @@ load_video_types() { if (words.size() == 1) { // Exactly one word: load the named library immediately. - string name = words[0]; + const string &name = words[0]; Filename dlname = Filename::dso_filename("lib" + name + ".so"); movies_cat.info() << "loading video type module: " << name << endl; @@ -288,9 +288,12 @@ load_video_types() { * Loads the module. */ void MovieTypeRegistry:: -load_movie_library(const string &name) { +load_movie_library(std::string_view name) { ReMutexHolder holder(_video_lock); - Filename dlname = Filename::dso_filename("lib" + name + ".so"); + std::string basename = "lib"; + basename += name; + basename += ".so"; + Filename dlname = Filename::dso_filename(basename); movies_cat.info() << "loading video type module: " << name << endl; void *tmp = load_dso(get_plugin_path().get_value(), dlname); diff --git a/panda/src/movies/movieTypeRegistry.h b/panda/src/movies/movieTypeRegistry.h index c9ddb53f15b..74d4b9ba5cd 100644 --- a/panda/src/movies/movieTypeRegistry.h +++ b/panda/src/movies/movieTypeRegistry.h @@ -29,15 +29,15 @@ class EXPCL_PANDA_MOVIES MovieTypeRegistry { public: typedef PT(MovieAudio) (*MakeAudioFunc)(const Filename&); PT(MovieAudio) make_audio(const Filename &name); - void register_audio_type(MakeAudioFunc func, const std::string &extensions); + void register_audio_type(MakeAudioFunc func, std::string_view extensions); void load_audio_types(); typedef PT(MovieVideo) (*MakeVideoFunc)(const Filename&); PT(MovieVideo) make_video(const Filename &name); - void register_video_type(MakeVideoFunc func, const std::string &extensions); + void register_video_type(MakeVideoFunc func, std::string_view extensions); void load_video_types(); - void load_movie_library(const std::string &name); + void load_movie_library(std::string_view name); INLINE static MovieTypeRegistry *get_global_ptr(); diff --git a/panda/src/movies/movieVideo.cxx b/panda/src/movies/movieVideo.cxx index 57b755a4535..402bf116e23 100644 --- a/panda/src/movies/movieVideo.cxx +++ b/panda/src/movies/movieVideo.cxx @@ -26,8 +26,8 @@ TypeHandle MovieVideo::_type_handle; * need to construct a subclass of this class. */ MovieVideo:: -MovieVideo(const std::string &name) : - Namable(name) +MovieVideo(std::string name) : + Namable(std::move(name)) { } diff --git a/panda/src/movies/movieVideo.h b/panda/src/movies/movieVideo.h index 5b2ae0b464a..283daf639a3 100644 --- a/panda/src/movies/movieVideo.h +++ b/panda/src/movies/movieVideo.h @@ -37,7 +37,7 @@ class BamReader; */ class EXPCL_PANDA_MOVIES MovieVideo : public TypedWritableReferenceCount, public Namable { PUBLISHED: - explicit MovieVideo(const std::string &name = "Blank Video"); + explicit MovieVideo(std::string name = "Blank Video"); virtual ~MovieVideo(); virtual PT(MovieVideoCursor) open(); static PT(MovieVideo) get(const Filename &name); diff --git a/panda/src/net/config_net.cxx b/panda/src/net/config_net.cxx index 753a5beb53b..b785b1d504f 100644 --- a/panda/src/net/config_net.cxx +++ b/panda/src/net/config_net.cxx @@ -120,7 +120,7 @@ get_net_max_block() { // This function is used in the ReaderThread and WriterThread constructors to // make a simple name for each thread. std::string -make_thread_name(const std::string &thread_name, int thread_index) { +make_thread_name(std::string_view thread_name, int thread_index) { std::ostringstream stream; stream << thread_name << "_" << thread_index; return stream.str(); diff --git a/panda/src/net/config_net.h b/panda/src/net/config_net.h index a80faa1642d..5f520ede3ca 100644 --- a/panda/src/net/config_net.h +++ b/panda/src/net/config_net.h @@ -31,7 +31,7 @@ extern int get_net_max_response_queue(); extern bool get_net_error_abort(); extern double get_net_max_poll_cycle(); extern double get_net_max_block(); -extern std::string make_thread_name(const std::string &thread_name, int thread_index); +extern std::string make_thread_name(std::string_view thread_name, int thread_index); extern ConfigVariableInt net_max_read_per_epoch; extern ConfigVariableInt net_max_write_per_epoch; diff --git a/panda/src/net/connectionListener.cxx b/panda/src/net/connectionListener.cxx index 2ab8b33ef71..07cc685d2ff 100644 --- a/panda/src/net/connectionListener.cxx +++ b/panda/src/net/connectionListener.cxx @@ -19,21 +19,13 @@ #include "config_net.h" #include "socket_tcp_listen.h" -static std::string -listener_thread_name(const std::string &thread_name) { - if (!thread_name.empty()) { - return thread_name; - } - return "ListenerThread"; -} - /** * */ ConnectionListener:: ConnectionListener(ConnectionManager *manager, int num_threads, - const std::string &thread_name) : - ConnectionReader(manager, num_threads, listener_thread_name(thread_name)) + std::string_view thread_name) : + ConnectionReader(manager, num_threads, !thread_name.empty() ? thread_name : "ListenerThread") { } diff --git a/panda/src/net/connectionListener.h b/panda/src/net/connectionListener.h index 7251dafe27d..7052a883653 100644 --- a/panda/src/net/connectionListener.h +++ b/panda/src/net/connectionListener.h @@ -31,7 +31,7 @@ class NetAddress; class EXPCL_PANDA_NET ConnectionListener : public ConnectionReader { PUBLISHED: ConnectionListener(ConnectionManager *manager, int num_threads, - const std::string &thread_name = std::string()); + std::string_view thread_name = std::string_view()); protected: virtual void receive_datagram(const NetDatagram &datagram); diff --git a/panda/src/net/connectionManager.h b/panda/src/net/connectionManager.h index a3a6f862c10..be337413904 100644 --- a/panda/src/net/connectionManager.h +++ b/panda/src/net/connectionManager.h @@ -78,8 +78,8 @@ class EXPCL_PANDA_NET ConnectionManager { public: Interface() { _flags = 0; } - void set_name(const std::string &name) { _name = name; } - void set_mac_address(const std::string &mac_address) { _mac_address = mac_address; } + void set_name(std::string name) { _name = std::move(name); } + void set_mac_address(std::string mac_address) { _mac_address = std::move(mac_address); } void set_ip(const NetAddress &ip) { _ip = ip; _flags |= F_has_ip; } void set_netmask(const NetAddress &ip) { _netmask = ip; _flags |= F_has_netmask; } void set_broadcast(const NetAddress &ip) { _broadcast = ip; _flags |= F_has_broadcast; } diff --git a/panda/src/net/connectionReader.cxx b/panda/src/net/connectionReader.cxx index 07651148849..3e58718d33a 100644 --- a/panda/src/net/connectionReader.cxx +++ b/panda/src/net/connectionReader.cxx @@ -61,7 +61,7 @@ get_socket() const { * */ ConnectionReader::ReaderThread:: -ReaderThread(ConnectionReader *reader, const std::string &thread_name, +ReaderThread(ConnectionReader *reader, std::string_view thread_name, int thread_index) : Thread(make_thread_name(thread_name, thread_index), make_thread_name(thread_name, thread_index)), @@ -86,7 +86,7 @@ thread_main() { */ ConnectionReader:: ConnectionReader(ConnectionManager *manager, int num_threads, - const std::string &thread_name) : + std::string_view thread_name) : _manager(manager) { if (!Thread::is_threading_supported()) { @@ -112,7 +112,7 @@ ConnectionReader(ConnectionManager *manager, int num_threads, _currently_polling_thread.store(-1, std::memory_order_relaxed); - std::string reader_thread_name = thread_name; + std::string reader_thread_name(thread_name); if (thread_name.empty()) { reader_thread_name = "ReaderThread"; } diff --git a/panda/src/net/connectionReader.h b/panda/src/net/connectionReader.h index 96536d6fe64..bb8f74ec1f0 100644 --- a/panda/src/net/connectionReader.h +++ b/panda/src/net/connectionReader.h @@ -61,7 +61,7 @@ class EXPCL_PANDA_NET ConnectionReader { // new call to PR_Poll(). explicit ConnectionReader(ConnectionManager *manager, int num_threads, - const std::string &thread_name = std::string()); + std::string_view thread_name = std::string_view()); virtual ~ConnectionReader(); bool add_connection(Connection *connection); @@ -135,7 +135,7 @@ class EXPCL_PANDA_NET ConnectionReader { class ReaderThread : public Thread { public: - ReaderThread(ConnectionReader *reader, const std::string &thread_name, + ReaderThread(ConnectionReader *reader, std::string_view thread_name, int thread_index); virtual void thread_main(); diff --git a/panda/src/net/connectionWriter.cxx b/panda/src/net/connectionWriter.cxx index 47cde6c35d1..e5c903f76a1 100644 --- a/panda/src/net/connectionWriter.cxx +++ b/panda/src/net/connectionWriter.cxx @@ -24,7 +24,7 @@ * */ ConnectionWriter::WriterThread:: -WriterThread(ConnectionWriter *writer, const std::string &thread_name, +WriterThread(ConnectionWriter *writer, std::string_view thread_name, int thread_index) : Thread(make_thread_name(thread_name, thread_index), make_thread_name(thread_name, thread_index)), @@ -50,7 +50,7 @@ thread_main() { */ ConnectionWriter:: ConnectionWriter(ConnectionManager *manager, int num_threads, - const std::string &thread_name) : + std::string_view thread_name) : _manager(manager) { if (!Thread::is_threading_supported()) { @@ -70,7 +70,7 @@ ConnectionWriter(ConnectionManager *manager, int num_threads, _immediate = (num_threads <= 0); _shutdown = false; - std::string writer_thread_name = thread_name; + std::string writer_thread_name(thread_name); if (thread_name.empty()) { writer_thread_name = "WriterThread"; } diff --git a/panda/src/net/connectionWriter.h b/panda/src/net/connectionWriter.h index 578cc260f83..06510c7a8dc 100644 --- a/panda/src/net/connectionWriter.h +++ b/panda/src/net/connectionWriter.h @@ -35,7 +35,7 @@ class NetAddress; class EXPCL_PANDA_NET ConnectionWriter { PUBLISHED: explicit ConnectionWriter(ConnectionManager *manager, int num_threads, - const std::string &thread_name = std::string()); + std::string_view thread_name = std::string_view()); ~ConnectionWriter(); void set_max_queue_size(int max_size); @@ -83,7 +83,7 @@ class EXPCL_PANDA_NET ConnectionWriter { class WriterThread : public Thread { public: - WriterThread(ConnectionWriter *writer, const std::string &thread_name, + WriterThread(ConnectionWriter *writer, std::string_view thread_name, int thread_index); virtual void thread_main(); diff --git a/panda/src/ode/odeSpace.I b/panda/src/ode/odeSpace.I index 93fc719e405..dfa458256a7 100644 --- a/panda/src/ode/odeSpace.I +++ b/panda/src/ode/odeSpace.I @@ -103,8 +103,8 @@ is_enabled() { } INLINE void OdeSpace:: -set_collision_event(const std::string &event_name) { - _collision_event = event_name; +set_collision_event(std::string event_name) { + _collision_event = std::move(event_name); } INLINE std::string OdeSpace:: diff --git a/panda/src/ode/odeSpace.h b/panda/src/ode/odeSpace.h index bcc5d153fd5..2fa7974f256 100644 --- a/panda/src/ode/odeSpace.h +++ b/panda/src/ode/odeSpace.h @@ -97,7 +97,7 @@ class EXPCL_PANDAODE OdeSpace : public TypedObject { int get_collide_id(dGeomID o1); int get_collide_id(OdeGeom& geom); - INLINE void set_collision_event(const std::string &event_name); + INLINE void set_collision_event(std::string event_name); INLINE std::string get_collision_event(); public: diff --git a/panda/src/ode/odeTriMeshData.cxx b/panda/src/ode/odeTriMeshData.cxx index 65e774953c0..112284ea076 100644 --- a/panda/src/ode/odeTriMeshData.cxx +++ b/panda/src/ode/odeTriMeshData.cxx @@ -49,7 +49,7 @@ unlink_data(dGeomID id) { } void OdeTriMeshData:: -print_data(const std::string &marker) { +print_data(std::string_view marker) { if (odetrimeshdata_cat.is_debug()) { odetrimeshdata_cat.debug() << get_class_type() << "::print_data(" << marker << ")\n"; const TriMeshDataMap &data_map = get_tri_mesh_data_map(); diff --git a/panda/src/ode/odeTriMeshData.h b/panda/src/ode/odeTriMeshData.h index efdda31c78f..42a22aedced 100644 --- a/panda/src/ode/odeTriMeshData.h +++ b/panda/src/ode/odeTriMeshData.h @@ -38,7 +38,7 @@ class EXPCL_PANDAODE OdeTriMeshData : public TypedReferenceCount { static PT(OdeTriMeshData) get_data(dGeomID id); static void unlink_data(dGeomID id); static void remove_data(OdeTriMeshData *data); - static void print_data(const std::string &marker); + static void print_data(std::string_view marker); private: typedef pmap TriMeshDataMap; diff --git a/panda/src/parametrics/curveFitter.cxx b/panda/src/parametrics/curveFitter.cxx index 74e32cea650..671d0d80248 100644 --- a/panda/src/parametrics/curveFitter.cxx +++ b/panda/src/parametrics/curveFitter.cxx @@ -137,8 +137,8 @@ get_sample_tangent(int n) const { */ void CurveFitter:: remove_samples(int begin, int end) { - begin = std::max(0, std::min((int)_data.size(), begin)); - end = std::max(0, std::min((int)_data.size(), end)); + begin = std::clamp(begin, 0, (int)_data.size()); + end = std::clamp(end, 0, (int)_data.size()); nassertv(begin <= end); diff --git a/panda/src/parametrics/hermiteCurve.cxx b/panda/src/parametrics/hermiteCurve.cxx index 55f3bccd28d..5fe50d7edbe 100644 --- a/panda/src/parametrics/hermiteCurve.cxx +++ b/panda/src/parametrics/hermiteCurve.cxx @@ -154,8 +154,8 @@ set_type(int type) { * Sets the name associated with the CV. */ void HermiteCurveCV:: -set_name(const string &name) { - _name = name; +set_name(std::string name) { + _name = std::move(name); } @@ -294,7 +294,7 @@ insert_cv(PN_stdfloat t) { return n; } - t = std::min(std::max(t, (PN_stdfloat)0.0), get_max_t()); + t = std::clamp(t, (PN_stdfloat)0.0, get_max_t()); int n = find_cv(t); nassertr(n+1 " << name << ".pool {\n"; diff --git a/panda/src/parametrics/hermiteCurve.h b/panda/src/parametrics/hermiteCurve.h index 45e601de1bd..06a30b3d624 100644 --- a/panda/src/parametrics/hermiteCurve.h +++ b/panda/src/parametrics/hermiteCurve.h @@ -57,7 +57,7 @@ class EXPCL_PANDA_PARAMETRICS HermiteCurveCV { void set_in(const LVecBase3 &in); void set_out(const LVecBase3 &out); void set_type(int type); - void set_name(const std::string &name); + void set_name(std::string name); void format_egg(std::ostream &out, int indent, int num_dimensions, bool show_in, bool show_out, @@ -140,8 +140,8 @@ class EXPCL_PANDA_PARAMETRICS HermiteCurve : public PiecewiseCurve { int rtype3, PN_stdfloat t3, const LVecBase4 &v3); protected: - virtual bool format_egg(std::ostream &out, const std::string &name, - const std::string &curve_type, int indent_level) const; + virtual bool format_egg(std::ostream &out, std::string_view name, + std::string_view curve_type, int indent_level) const; void invalidate_cv(int n, bool redo_all); int find_cv(PN_stdfloat t); diff --git a/panda/src/parametrics/nurbsCurve.cxx b/panda/src/parametrics/nurbsCurve.cxx index 5a60019f2ed..9d7b236976d 100644 --- a/panda/src/parametrics/nurbsCurve.cxx +++ b/panda/src/parametrics/nurbsCurve.cxx @@ -459,7 +459,7 @@ append_cv_impl(const LVecBase4 &v) { * Returns true on success, false on failure. */ bool NurbsCurve:: -format_egg(std::ostream &out, const std::string &name, const std::string &curve_type, +format_egg(std::ostream &out, std::string_view name, std::string_view curve_type, int indent_level) const { return NurbsCurveInterface::format_egg(out, name, curve_type, indent_level); } diff --git a/panda/src/parametrics/nurbsCurve.h b/panda/src/parametrics/nurbsCurve.h index 2bd7bd97291..2c0b6df7675 100644 --- a/panda/src/parametrics/nurbsCurve.h +++ b/panda/src/parametrics/nurbsCurve.h @@ -89,8 +89,8 @@ class EXPCL_PANDA_PARAMETRICS NurbsCurve final : public PiecewiseCurve, public N protected: virtual int append_cv_impl(const LVecBase4 &v); - virtual bool format_egg(std::ostream &out, const std::string &name, - const std::string &curve_type, int indent_level) const; + virtual bool format_egg(std::ostream &out, std::string_view name, + std::string_view curve_type, int indent_level) const; int find_cv(PN_stdfloat t); diff --git a/panda/src/parametrics/nurbsCurveEvaluator.I b/panda/src/parametrics/nurbsCurveEvaluator.I index 9f4f7937023..9f164905f1e 100644 --- a/panda/src/parametrics/nurbsCurveEvaluator.I +++ b/panda/src/parametrics/nurbsCurveEvaluator.I @@ -117,9 +117,9 @@ set_vertex_space(int i, const NodePath &space) { * node relative to the rel_to NodePath when the curve is evaluated. */ INLINE void NurbsCurveEvaluator:: -set_vertex_space(int i, const std::string &space) { +set_vertex_space(int i, std::string space) { nassertv(i >= 0 && i < (int)_vertices.size()); - _vertices[i].set_space(space); + _vertices[i].set_space(std::move(space)); } /** diff --git a/panda/src/parametrics/nurbsCurveEvaluator.h b/panda/src/parametrics/nurbsCurveEvaluator.h index 1a4192242d0..87d6a45f728 100644 --- a/panda/src/parametrics/nurbsCurveEvaluator.h +++ b/panda/src/parametrics/nurbsCurveEvaluator.h @@ -54,7 +54,7 @@ class EXPCL_PANDA_PARAMETRICS NurbsCurveEvaluator : public ReferenceCount { MAKE_SEQ(get_vertices, get_num_vertices, get_vertex); INLINE void set_vertex_space(int i, const NodePath &space); - INLINE void set_vertex_space(int i, const std::string &space); + INLINE void set_vertex_space(int i, std::string space); NodePath get_vertex_space(int i, const NodePath &rel_to) const; INLINE void set_extended_vertex(int i, int d, PN_stdfloat value); diff --git a/panda/src/parametrics/nurbsCurveInterface.cxx b/panda/src/parametrics/nurbsCurveInterface.cxx index 19b60957f4f..f29e224a4c9 100644 --- a/panda/src/parametrics/nurbsCurveInterface.cxx +++ b/panda/src/parametrics/nurbsCurveInterface.cxx @@ -93,7 +93,7 @@ write(std::ostream &out, int indent_level) const { * Formats the Nurbs curve for output to an Egg file. */ bool NurbsCurveInterface:: -format_egg(std::ostream &out, const std::string &name, const std::string &curve_type, +format_egg(std::ostream &out, std::string_view name, std::string_view curve_type, int indent_level) const { indent(out, indent_level) << " " << name << ".pool {\n"; diff --git a/panda/src/parametrics/nurbsCurveInterface.h b/panda/src/parametrics/nurbsCurveInterface.h index e37a24d07ea..d9c7c677334 100644 --- a/panda/src/parametrics/nurbsCurveInterface.h +++ b/panda/src/parametrics/nurbsCurveInterface.h @@ -67,8 +67,8 @@ class EXPCL_PANDA_PARAMETRICS NurbsCurveInterface { virtual int append_cv_impl(const LVecBase4 &v)=0; void write(std::ostream &out, int indent_level) const; - bool format_egg(std::ostream &out, const std::string &name, - const std::string &curve_type, int indent_level) const; + bool format_egg(std::ostream &out, std::string_view name, + std::string_view curve_type, int indent_level) const; bool convert_to_nurbs(ParametricCurve *nc) const; diff --git a/panda/src/parametrics/nurbsSurfaceEvaluator.I b/panda/src/parametrics/nurbsSurfaceEvaluator.I index 26c0f9c0e02..89c995b9d59 100644 --- a/panda/src/parametrics/nurbsSurfaceEvaluator.I +++ b/panda/src/parametrics/nurbsSurfaceEvaluator.I @@ -155,10 +155,10 @@ set_vertex_space(int ui, int vi, const NodePath &space) { * node relative to the rel_to NodePath when the surface is evaluated. */ INLINE void NurbsSurfaceEvaluator:: -set_vertex_space(int ui, int vi, const std::string &space) { +set_vertex_space(int ui, int vi, std::string space) { nassertv(ui >= 0 && ui < _num_u_vertices && vi >= 0 && vi < _num_v_vertices); - vert(ui, vi).set_space(space); + vert(ui, vi).set_space(std::move(space)); } /** diff --git a/panda/src/parametrics/nurbsSurfaceEvaluator.h b/panda/src/parametrics/nurbsSurfaceEvaluator.h index ced10130162..ccab6990905 100644 --- a/panda/src/parametrics/nurbsSurfaceEvaluator.h +++ b/panda/src/parametrics/nurbsSurfaceEvaluator.h @@ -52,7 +52,7 @@ class EXPCL_PANDA_PARAMETRICS NurbsSurfaceEvaluator : public ReferenceCount { INLINE LVecBase4 get_vertex(int ui, int vi, const NodePath &rel_to) const; INLINE void set_vertex_space(int ui, int vi, const NodePath &space); - INLINE void set_vertex_space(int ui, int vi, const std::string &space); + INLINE void set_vertex_space(int ui, int vi, std::string space); NodePath get_vertex_space(int ui, int vi, const NodePath &rel_to) const; INLINE void set_extended_vertex(int ui, int vi, int d, PN_stdfloat value); diff --git a/panda/src/parametrics/nurbsVertex.I b/panda/src/parametrics/nurbsVertex.I index 75a23a59e1e..13ce731b509 100644 --- a/panda/src/parametrics/nurbsVertex.I +++ b/panda/src/parametrics/nurbsVertex.I @@ -76,9 +76,9 @@ set_space(const NodePath &space) { * Sets the space of this vertex as a relative path from the rel_to node. */ INLINE void NurbsVertex:: -set_space(const std::string &space) { +set_space(std::string space) { _space = NodePath(); - _space_path = space; + _space_path = std::move(space); } /** diff --git a/panda/src/parametrics/nurbsVertex.h b/panda/src/parametrics/nurbsVertex.h index 751b36f335d..cd1d52ef749 100644 --- a/panda/src/parametrics/nurbsVertex.h +++ b/panda/src/parametrics/nurbsVertex.h @@ -40,7 +40,7 @@ class EXPCL_PANDA_PARAMETRICS NurbsVertex { INLINE const LVecBase4 &get_vertex() const; INLINE void set_space(const NodePath &space); - INLINE void set_space(const std::string &space); + INLINE void set_space(std::string space); INLINE NodePath get_space(const NodePath &rel_to) const; void set_extended_vertex(int d, PN_stdfloat value); diff --git a/panda/src/parametrics/parametricCurve.cxx b/panda/src/parametrics/parametricCurve.cxx index 9893c656043..794c4db8198 100644 --- a/panda/src/parametrics/parametricCurve.cxx +++ b/panda/src/parametrics/parametricCurve.cxx @@ -602,7 +602,7 @@ invalidate_all() { * Returns true on success, false on failure. */ bool ParametricCurve:: -format_egg(std::ostream &, const std::string &, const std::string &, int) const { +format_egg(std::ostream &, std::string_view, std::string_view, int) const { return false; } diff --git a/panda/src/parametrics/parametricCurve.h b/panda/src/parametrics/parametricCurve.h index ca8ee5aed71..67184b465e9 100644 --- a/panda/src/parametrics/parametricCurve.h +++ b/panda/src/parametrics/parametricCurve.h @@ -116,8 +116,8 @@ class EXPCL_PANDA_PARAMETRICS ParametricCurve : public PandaNode { void invalidate(PN_stdfloat t1, PN_stdfloat t2); void invalidate_all(); - virtual bool format_egg(std::ostream &out, const std::string &name, - const std::string &curve_type, int indent_level) const; + virtual bool format_egg(std::ostream &out, std::string_view name, + std::string_view curve_type, int indent_level) const; private: PN_stdfloat r_calc_length(PN_stdfloat t1, PN_stdfloat t2, diff --git a/panda/src/parametrics/ropeNode.cxx b/panda/src/parametrics/ropeNode.cxx index 239b71c3927..24cbab5de02 100644 --- a/panda/src/parametrics/ropeNode.cxx +++ b/panda/src/parametrics/ropeNode.cxx @@ -67,8 +67,8 @@ fillin(DatagramIterator &scan, BamReader *reader) { * */ RopeNode:: -RopeNode(const std::string &name) : - PandaNode(name) +RopeNode(std::string name) : + PandaNode(std::move(name)) { set_cull_callback(); set_renderable(); diff --git a/panda/src/parametrics/ropeNode.h b/panda/src/parametrics/ropeNode.h index 9285854a573..4028855dc35 100644 --- a/panda/src/parametrics/ropeNode.h +++ b/panda/src/parametrics/ropeNode.h @@ -34,7 +34,7 @@ class GeomVertexData; */ class EXPCL_PANDA_PARAMETRICS RopeNode : public PandaNode { PUBLISHED: - explicit RopeNode(const std::string &name); + explicit RopeNode(std::string name); protected: RopeNode(const RopeNode ©); diff --git a/panda/src/parametrics/sheetNode.cxx b/panda/src/parametrics/sheetNode.cxx index cac84092786..9584afdc0e8 100644 --- a/panda/src/parametrics/sheetNode.cxx +++ b/panda/src/parametrics/sheetNode.cxx @@ -66,8 +66,8 @@ fillin(DatagramIterator &scan, BamReader *reader) { * */ SheetNode:: -SheetNode(const std::string &name) : - PandaNode(name) +SheetNode(std::string name) : + PandaNode(std::move(name)) { set_cull_callback(); set_renderable(); diff --git a/panda/src/parametrics/sheetNode.h b/panda/src/parametrics/sheetNode.h index 1d27d840a80..ffbd67d3dc7 100644 --- a/panda/src/parametrics/sheetNode.h +++ b/panda/src/parametrics/sheetNode.h @@ -31,7 +31,7 @@ */ class EXPCL_PANDA_PARAMETRICS SheetNode : public PandaNode { PUBLISHED: - explicit SheetNode(const std::string &name); + explicit SheetNode(std::string name); protected: SheetNode(const SheetNode ©); diff --git a/panda/src/particlesystem/baseParticleEmitter.h b/panda/src/particlesystem/baseParticleEmitter.h index f1c66656797..95550e0954b 100644 --- a/panda/src/particlesystem/baseParticleEmitter.h +++ b/panda/src/particlesystem/baseParticleEmitter.h @@ -31,7 +31,7 @@ class EXPCL_PANDA_PARTICLESYSTEM BaseParticleEmitter : public ReferenceCount { }; virtual ~BaseParticleEmitter(); - virtual BaseParticleEmitter *make_copy() = 0; + [[nodiscard]] virtual BaseParticleEmitter *make_copy() = 0; void generate(LPoint3& pos, LVector3& vel); diff --git a/panda/src/particlesystem/baseParticleRenderer.h b/panda/src/particlesystem/baseParticleRenderer.h index 8dd8a0a0818..b178fda2f6b 100644 --- a/panda/src/particlesystem/baseParticleRenderer.h +++ b/panda/src/particlesystem/baseParticleRenderer.h @@ -66,7 +66,7 @@ class EXPCL_PANDA_PARTICLESYSTEM BaseParticleRenderer : public ReferenceCount { virtual void write(std::ostream &out, int indent=0) const; public: - virtual BaseParticleRenderer *make_copy() = 0; + [[nodiscard]] virtual BaseParticleRenderer *make_copy() = 0; protected: ParticleRendererAlphaMode _alpha_mode; diff --git a/panda/src/particlesystem/spriteParticleRenderer.cxx b/panda/src/particlesystem/spriteParticleRenderer.cxx index 71a42d6c0b4..1a7a2b8c12b 100644 --- a/panda/src/particlesystem/spriteParticleRenderer.cxx +++ b/panda/src/particlesystem/spriteParticleRenderer.cxx @@ -192,10 +192,10 @@ extract_textures_from_node(const NodePath &node_path, NodePathCollection &np_col * match the new geometry. */ void SpriteParticleRenderer:: -set_from_node(const NodePath &node_path, const std::string &model, const std::string &node, bool size_from_texels) { +set_from_node(const NodePath &node_path, std::string model, std::string node, bool size_from_texels) { // Clear all texture information _anims.clear(); - add_from_node(node_path,model,node,size_from_texels,true); + add_from_node(node_path, std::move(model), std::move(node), size_from_texels, true); } /** @@ -244,13 +244,13 @@ set_from_node(const NodePath &node_path, bool size_from_texels) { * now on. (Default is false) */ void SpriteParticleRenderer:: -add_from_node(const NodePath &node_path, const std::string &model, const std::string &node, bool size_from_texels, bool resize) { +add_from_node(const NodePath &node_path, std::string model, std::string node, bool size_from_texels, bool resize) { int anim_count = _anims.size(); if (anim_count == 0) resize = true; add_from_node(node_path,size_from_texels,resize); if (anim_count < (int)_anims.size()) { - get_last_anim()->set_source_info(model,node); + get_last_anim()->set_source_info(std::move(model), std::move(node)); } } diff --git a/panda/src/particlesystem/spriteParticleRenderer.h b/panda/src/particlesystem/spriteParticleRenderer.h index f23533118c4..4c6a75ff2c2 100644 --- a/panda/src/particlesystem/spriteParticleRenderer.h +++ b/panda/src/particlesystem/spriteParticleRenderer.h @@ -75,15 +75,15 @@ class SpriteAnim : public ReferenceCount{ ST_from_node, }; - void set_source_info(const std::string &tex) { + void set_source_info(std::string tex) { _source_type = ST_texture; - _source_tex = tex; + _source_tex = std::move(tex); } - void set_source_info(const std::string &model, const std::string &node) { + void set_source_info(std::string model, std::string node) { _source_type = ST_from_node; - _source_model = model; - _source_node = node; + _source_model = std::move(model); + _source_node = std::move(node); } SourceType get_source_type() const { @@ -162,9 +162,9 @@ class EXPCL_PANDA_PARTICLESYSTEM SpriteParticleRenderer : public BaseParticleRen PUBLISHED: void set_from_node(const NodePath &node_path, bool size_from_texels = false); - void set_from_node(const NodePath &node_path, const std::string &model, const std::string &node, bool size_from_texels = false); + void set_from_node(const NodePath &node_path, std::string model, std::string node, bool size_from_texels = false); void add_from_node(const NodePath &node_path, bool size_from_texels = false, bool resize = false); - void add_from_node(const NodePath &node_path, const std::string &model, const std::string &node, bool size_from_texels = false, bool resize = false); + void add_from_node(const NodePath &node_path, std::string model, std::string node, bool size_from_texels = false, bool resize = false); INLINE void set_texture(Texture *tex, PN_stdfloat texels_per_unit = 1.0f); INLINE void add_texture(Texture *tex, PN_stdfloat texels_per_unit = 1.0f, bool resize = false); diff --git a/panda/src/pgraph/attribNodeRegistry.I b/panda/src/pgraph/attribNodeRegistry.I index 406733fd789..a9c41c1cf64 100644 --- a/panda/src/pgraph/attribNodeRegistry.I +++ b/panda/src/pgraph/attribNodeRegistry.I @@ -39,9 +39,9 @@ Entry(const NodePath &node) : * */ INLINE AttribNodeRegistry::Entry:: -Entry(TypeHandle type, const std::string &name) : +Entry(TypeHandle type, std::string name) : _type(type), - _name(name) + _name(std::move(name)) { } diff --git a/panda/src/pgraph/attribNodeRegistry.cxx b/panda/src/pgraph/attribNodeRegistry.cxx index d2cd22c1ebb..25ceb8bd299 100644 --- a/panda/src/pgraph/attribNodeRegistry.cxx +++ b/panda/src/pgraph/attribNodeRegistry.cxx @@ -148,9 +148,9 @@ find_node(const NodePath &attrib_node) const { * the registry, or -1 if there is no such node in the registry. */ int AttribNodeRegistry:: -find_node(TypeHandle type, const std::string &name) const { +find_node(TypeHandle type, std::string name) const { LightMutexHolder holder(_lock); - Entries::const_iterator ei = _entries.find(Entry(type, name)); + Entries::const_iterator ei = _entries.find(Entry(type, std::move(name))); if (ei != _entries.end()) { return ei - _entries.begin(); } diff --git a/panda/src/pgraph/attribNodeRegistry.h b/panda/src/pgraph/attribNodeRegistry.h index 88d09f6bd45..fe1feb547a7 100644 --- a/panda/src/pgraph/attribNodeRegistry.h +++ b/panda/src/pgraph/attribNodeRegistry.h @@ -47,7 +47,7 @@ class EXPCL_PANDA_PGRAPH AttribNodeRegistry { std::string get_node_name(int n) const; int find_node(const NodePath &attrib_node) const; - int find_node(TypeHandle type, const std::string &name) const; + int find_node(TypeHandle type, std::string name) const; void remove_node(int n); void clear(); @@ -62,7 +62,7 @@ class EXPCL_PANDA_PGRAPH AttribNodeRegistry { class Entry { public: INLINE Entry(const NodePath &node); - INLINE Entry(TypeHandle type, const std::string &name); + INLINE Entry(TypeHandle type, std::string name); INLINE bool operator < (const Entry &other) const; TypeHandle _type; diff --git a/panda/src/pgraph/bamFile.cxx b/panda/src/pgraph/bamFile.cxx index 35478c11e2b..5cdfbbcc721 100644 --- a/panda/src/pgraph/bamFile.cxx +++ b/panda/src/pgraph/bamFile.cxx @@ -63,14 +63,14 @@ open_read(const Filename &bam_filename, bool report_errors) { * for information purposes only. Returns true if successful, false on error. */ bool BamFile:: -open_read(std::istream &in, const string &bam_filename, bool report_errors) { +open_read(std::istream &in, std::string bam_filename, bool report_errors) { close(); if (!_din.open(in)) { return false; } - return continue_open_read(bam_filename, report_errors); + return continue_open_read(std::move(bam_filename), report_errors); } /** @@ -213,7 +213,7 @@ open_write(const Filename &bam_filename, bool report_errors) { * for information purposes only. Returns true if successful, false on error. */ bool BamFile:: -open_write(std::ostream &out, const string &bam_filename, bool report_errors) { +open_write(std::ostream &out, std::string bam_filename, bool report_errors) { close(); if (!_dout.open(out)) { @@ -221,7 +221,7 @@ open_write(std::ostream &out, const string &bam_filename, bool report_errors) { return false; } - return continue_open_write(bam_filename, report_errors); + return continue_open_write(std::move(bam_filename), report_errors); } /** @@ -360,8 +360,8 @@ get_writer() { * contents of the file. Returns true if successful, false otherwise. */ bool BamFile:: -continue_open_read(const string &bam_filename, bool report_errors) { - _bam_filename = bam_filename; +continue_open_read(std::string bam_filename, bool report_errors) { + _bam_filename = std::move(bam_filename); if (!_bam_filename.empty()) { loader_cat.info() @@ -397,8 +397,8 @@ continue_open_read(const string &bam_filename, bool report_errors) { * the contents of the file. Returns true if successful, false otherwise. */ bool BamFile:: -continue_open_write(const string &bam_filename, bool report_errors) { - _bam_filename = bam_filename; +continue_open_write(std::string bam_filename, bool report_errors) { + _bam_filename = std::move(bam_filename); if (!_bam_filename.empty()) { loader_cat.info() << "Writing " << _bam_filename << "\n"; diff --git a/panda/src/pgraph/bamFile.h b/panda/src/pgraph/bamFile.h index 62a7ea93e7c..af20ed932ea 100644 --- a/panda/src/pgraph/bamFile.h +++ b/panda/src/pgraph/bamFile.h @@ -44,7 +44,7 @@ class EXPCL_PANDA_PGRAPH BamFile : public BamEnums { ~BamFile(); bool open_read(const Filename &bam_filename, bool report_errors = true); - bool open_read(std::istream &in, const std::string &bam_filename = "stream", + bool open_read(std::istream &in, std::string bam_filename = "stream", bool report_errors = true); #if defined(CPPPARSER) && defined(HAVE_PYTHON) @@ -59,7 +59,7 @@ class EXPCL_PANDA_PGRAPH BamFile : public BamEnums { PT(PandaNode) read_node(bool report_errors = true); bool open_write(const Filename &bam_filename, bool report_errors = true); - bool open_write(std::ostream &out, const std::string &bam_filename = "stream", + bool open_write(std::ostream &out, std::string bam_filename = "stream", bool report_errors = true); bool write_object(const TypedWritable *object); @@ -90,8 +90,8 @@ class EXPCL_PANDA_PGRAPH BamFile : public BamEnums { MAKE_PROPERTY(writer, get_writer); private: - bool continue_open_read(const std::string &bam_filename, bool report_errors); - bool continue_open_write(const std::string &bam_filename, bool report_errors); + bool continue_open_read(std::string bam_filename, bool report_errors); + bool continue_open_write(std::string bam_filename, bool report_errors); std::string _bam_filename; DatagramInputFile _din; diff --git a/panda/src/pgraph/camera.I b/panda/src/pgraph/camera.I index 7d32f433d32..3ae3054ee4f 100644 --- a/panda/src/pgraph/camera.I +++ b/panda/src/pgraph/camera.I @@ -180,8 +180,8 @@ get_initial_state() const { * the value of the tag (as specified to set_tag_state()). */ INLINE void Camera:: -set_tag_state_key(const std::string &tag_state_key) { - _tag_state_key = tag_state_key; +set_tag_state_key(std::string tag_state_key) { + _tag_state_key = std::move(tag_state_key); } /** diff --git a/panda/src/pgraph/camera.cxx b/panda/src/pgraph/camera.cxx index 3d2fa23d484..531080ca7d3 100644 --- a/panda/src/pgraph/camera.cxx +++ b/panda/src/pgraph/camera.cxx @@ -24,8 +24,8 @@ TypeHandle Camera::_type_handle; * */ Camera:: -Camera(const string &name, Lens *lens) : - LensNode(name, lens), +Camera(std::string name, Lens *lens) : + LensNode(std::move(name), lens), _active(true), _camera_mask(~PandaNode::get_overall_bit()), _lod_scale(1), @@ -104,16 +104,19 @@ safe_to_transform() const { * particular set of effects. */ void Camera:: -set_tag_state(const string &tag_state, const RenderState *state) { - _tag_states[tag_state] = state; +set_tag_state(std::string tag_state, const RenderState *state) { + _tag_states[std::move(tag_state)] = state; } /** * Removes the association established by a previous call to set_tag_state(). */ void Camera:: -clear_tag_state(const string &tag_state) { - _tag_states.erase(tag_state); +clear_tag_state(std::string_view tag_state) { + TagStates::iterator tsi = _tag_states.find(tag_state); + if (tsi != _tag_states.end()) { + _tag_states.erase(tsi); + } } /** @@ -129,7 +132,7 @@ clear_tag_states() { * indicated tag state, false otherwise. */ bool Camera:: -has_tag_state(const string &tag_state) const { +has_tag_state(std::string_view tag_state) const { TagStates::const_iterator tsi; tsi = _tag_states.find(tag_state); return (tsi != _tag_states.end()); @@ -140,7 +143,7 @@ has_tag_state(const string &tag_state) const { * call to set_tag_state(), or the empty state if nothing has been associated. */ CPT(RenderState) Camera:: -get_tag_state(const string &tag_state) const { +get_tag_state(std::string_view tag_state) const { TagStates::const_iterator tsi; tsi = _tag_states.find(tag_state); if (tsi != _tag_states.end()) { diff --git a/panda/src/pgraph/camera.h b/panda/src/pgraph/camera.h index 20e3a1dcba3..768758db37d 100644 --- a/panda/src/pgraph/camera.h +++ b/panda/src/pgraph/camera.h @@ -35,7 +35,7 @@ class DisplayRegion; */ class EXPCL_PANDA_PGRAPH Camera : public LensNode { PUBLISHED: - explicit Camera(const std::string &name, Lens *lens = new PerspectiveLens()); + explicit Camera(std::string name, Lens *lens = new PerspectiveLens()); Camera(const Camera ©); public: @@ -79,7 +79,7 @@ class EXPCL_PANDA_PGRAPH Camera : public LensNode { INLINE CPT(RenderState) get_initial_state() const; MAKE_PROPERTY(initial_state, get_initial_state, set_initial_state); - INLINE void set_tag_state_key(const std::string &tag_state_key); + INLINE void set_tag_state_key(std::string tag_state_key); INLINE const std::string &get_tag_state_key() const; MAKE_PROPERTY(tag_state_key, get_tag_state_key, set_tag_state_key); @@ -87,11 +87,11 @@ class EXPCL_PANDA_PGRAPH Camera : public LensNode { INLINE PN_stdfloat get_lod_scale() const; MAKE_PROPERTY(lod_scale, get_lod_scale, set_lod_scale); - void set_tag_state(const std::string &tag_state, const RenderState *state); - void clear_tag_state(const std::string &tag_state); + void set_tag_state(std::string tag_state, const RenderState *state); + void clear_tag_state(std::string_view tag_state); void clear_tag_states(); - bool has_tag_state(const std::string &tag_state) const; - CPT(RenderState) get_tag_state(const std::string &tag_state) const; + bool has_tag_state(std::string_view tag_state) const; + CPT(RenderState) get_tag_state(std::string_view tag_state) const; MAKE_MAP_PROPERTY(tag_states, has_tag_state, get_tag_state, set_tag_state, clear_tag_state); @@ -122,7 +122,7 @@ class EXPCL_PANDA_PGRAPH Camera : public LensNode { CPT(RenderState) _initial_state; std::string _tag_state_key; - typedef pmap TagStates; + typedef pmap> TagStates; TagStates _tag_states; typedef pmap AuxData; diff --git a/panda/src/pgraph/cullBin.I b/panda/src/pgraph/cullBin.I index 28f7b6542ed..6eb03dd2474 100644 --- a/panda/src/pgraph/cullBin.I +++ b/panda/src/pgraph/cullBin.I @@ -28,14 +28,14 @@ CullBin(const CullBin ©) : * */ INLINE CullBin:: -CullBin(const std::string &name, CullBin::BinType bin_type, +CullBin(std::string name, CullBin::BinType bin_type, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector) : - _name(name), + _name(std::move(name)), _bin_type(bin_type), _gsg(gsg), - _cull_this_pcollector(_cull_bin_pcollector, name), - _draw_this_pcollector(draw_region_pcollector, name) + _cull_this_pcollector(_cull_bin_pcollector, _name), + _draw_this_pcollector(draw_region_pcollector, _name) { } diff --git a/panda/src/pgraph/cullBin.h b/panda/src/pgraph/cullBin.h index 05e0fbb19ea..3766ad25507 100644 --- a/panda/src/pgraph/cullBin.h +++ b/panda/src/pgraph/cullBin.h @@ -41,7 +41,7 @@ class EXPCL_PANDA_PGRAPH CullBin : public TypedReferenceCount, public CullBinEnu protected: INLINE CullBin(const CullBin ©); public: - INLINE CullBin(const std::string &name, BinType bin_type, + INLINE CullBin(std::string name, BinType bin_type, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector); virtual ~CullBin(); diff --git a/panda/src/pgraph/cullBinAttrib.cxx b/panda/src/pgraph/cullBinAttrib.cxx index 27238c9c31e..4255b253993 100644 --- a/panda/src/pgraph/cullBinAttrib.cxx +++ b/panda/src/pgraph/cullBinAttrib.cxx @@ -28,9 +28,9 @@ int CullBinAttrib::_attrib_slot; * only to certain kinds of bins (in particular CullBinFixed type bins). */ CPT(RenderAttrib) CullBinAttrib:: -make(const std::string &bin_name, int draw_order) { +make(std::string bin_name, int draw_order) { CullBinAttrib *attrib = new CullBinAttrib; - attrib->_bin_name = bin_name; + attrib->_bin_name = std::move(bin_name); attrib->_draw_order = draw_order; return return_new(attrib); } diff --git a/panda/src/pgraph/cullBinAttrib.h b/panda/src/pgraph/cullBinAttrib.h index a3f8b0ab299..5e230e77594 100644 --- a/panda/src/pgraph/cullBinAttrib.h +++ b/panda/src/pgraph/cullBinAttrib.h @@ -30,7 +30,7 @@ class EXPCL_PANDA_PGRAPH CullBinAttrib final : public RenderAttrib { INLINE CullBinAttrib(); PUBLISHED: - static CPT(RenderAttrib) make(const std::string &bin_name, int draw_order); + static CPT(RenderAttrib) make(std::string bin_name, int draw_order); static CPT(RenderAttrib) make_default(); INLINE const std::string &get_bin_name() const; diff --git a/panda/src/pgraph/cullBinManager.I b/panda/src/pgraph/cullBinManager.I index cea6cc12b19..892eeae0b07 100644 --- a/panda/src/pgraph/cullBinManager.I +++ b/panda/src/pgraph/cullBinManager.I @@ -85,7 +85,7 @@ get_bin_type(int bin_index) const { * Returns the type of the bin with the indicated name. */ INLINE CullBinManager::BinType CullBinManager:: -get_bin_type(const std::string &name) const { +get_bin_type(std::string_view name) const { int bin_index = find_bin(name); nassertr(bin_index != -1, BT_invalid); return get_bin_type(bin_index); @@ -112,7 +112,7 @@ set_bin_type(int bin_index, CullBinManager::BinType type) { * frame, depending on the bin type. */ INLINE void CullBinManager:: -set_bin_type(const std::string &name, CullBinManager::BinType type) { +set_bin_type(std::string_view name, CullBinManager::BinType type) { int bin_index = find_bin(name); nassertv(bin_index != -1); set_bin_type(bin_index, type); @@ -139,7 +139,7 @@ get_bin_sort(int bin_index) const { * may be changed from time to time to reorder the bins. */ INLINE int CullBinManager:: -get_bin_sort(const std::string &name) const { +get_bin_sort(std::string_view name) const { int bin_index = find_bin(name); nassertr(bin_index != -1, 0); return get_bin_sort(bin_index); @@ -167,7 +167,7 @@ set_bin_sort(int bin_index, int sort) { * may be changed from time to time to reorder the bins. */ INLINE void CullBinManager:: -set_bin_sort(const std::string &name, int sort) { +set_bin_sort(std::string_view name, int sort) { int bin_index = find_bin(name); nassertv(bin_index != -1); set_bin_sort(bin_index, sort); @@ -192,7 +192,7 @@ get_bin_active(int bin_index) const { * When a bin is marked inactive, all geometry assigned to it is not rendered. */ INLINE bool CullBinManager:: -get_bin_active(const std::string &name) const { +get_bin_active(std::string_view name) const { int bin_index = find_bin(name); nassertr(bin_index != -1, false); return get_bin_active(bin_index); @@ -217,7 +217,7 @@ set_bin_active(int bin_index, bool active) { * When a bin is marked inactive, all geometry assigned to it is not rendered. */ INLINE void CullBinManager:: -set_bin_active(const std::string &name, bool active) { +set_bin_active(std::string_view name, bool active) { int bin_index = find_bin(name); nassertv(bin_index != -1); set_bin_active(bin_index, active); diff --git a/panda/src/pgraph/cullBinManager.cxx b/panda/src/pgraph/cullBinManager.cxx index cfacd85a03f..30156c72e95 100644 --- a/panda/src/pgraph/cullBinManager.cxx +++ b/panda/src/pgraph/cullBinManager.cxx @@ -49,7 +49,7 @@ CullBinManager:: * had the same properties; otherwise, reports an error and returns -1. */ int CullBinManager:: -add_bin(const string &name, BinType type, int sort) { +add_bin(string name, BinType type, int sort) { BinsByName::const_iterator bni = _bins_by_name.find(name); if (bni != _bins_by_name.end()) { // We already have such a bin. This is not a problem if the bin has the @@ -95,7 +95,6 @@ add_bin(const string &name, BinType type, int sort) { BinDefinition &def = _bin_definitions[new_bin_index]; def._in_use = true; - def._name = name; def._type = type; def._sort = sort; def._active = true; @@ -113,6 +112,7 @@ add_bin(const string &name, BinType type, int sort) { #endif _bins_by_name.insert(BinsByName::value_type(name, new_bin_index)); + def._name = std::move(name); _sorted_bins.push_back(new_bin_index); _bins_are_sorted = false; @@ -154,7 +154,7 @@ remove_bin(int bin_index) { * no bin has that name. */ int CullBinManager:: -find_bin(const string &name) const { +find_bin(std::string_view name) const { BinsByName::const_iterator bni; bni = _bins_by_name.find(name); if (bni != _bins_by_name.end()) { @@ -294,7 +294,7 @@ setup_initial_bins() { * BT_invalid if it is an unknown type. */ CullBinManager::BinType CullBinManager:: -parse_bin_type(const string &bin_type) { +parse_bin_type(std::string_view bin_type) { if (cmp_nocase_uh(bin_type, "unsorted") == 0) { return BT_unsorted; diff --git a/panda/src/pgraph/cullBinManager.h b/panda/src/pgraph/cullBinManager.h index 1bc203ab840..07cbb0180df 100644 --- a/panda/src/pgraph/cullBinManager.h +++ b/panda/src/pgraph/cullBinManager.h @@ -39,30 +39,30 @@ class EXPCL_PANDA_PGRAPH CullBinManager : public CullBinEnums { PUBLISHED: typedef CullBin::BinType BinType; - int add_bin(const std::string &name, BinType type, int sort); + int add_bin(std::string name, BinType type, int sort); void remove_bin(int bin_index); INLINE int get_num_bins() const; INLINE int get_bin(int n) const; MAKE_SEQ(get_bins, get_num_bins, get_bin); - int find_bin(const std::string &name) const; + int find_bin(std::string_view name) const; INLINE std::string get_bin_name(int bin_index) const; INLINE BinType get_bin_type(int bin_index) const; - INLINE BinType get_bin_type(const std::string &name) const; + INLINE BinType get_bin_type(std::string_view name) const; INLINE void set_bin_type(int bin_index, BinType type); - INLINE void set_bin_type(const std::string &name, BinType type); + INLINE void set_bin_type(std::string_view name, BinType type); INLINE int get_bin_sort(int bin_index) const; - INLINE int get_bin_sort(const std::string &name) const; + INLINE int get_bin_sort(std::string_view name) const; INLINE void set_bin_sort(int bin_index, int sort); - INLINE void set_bin_sort(const std::string &name, int sort); + INLINE void set_bin_sort(std::string_view name, int sort); INLINE bool get_bin_active(int bin_index) const; - INLINE bool get_bin_active(const std::string &name) const; + INLINE bool get_bin_active(std::string_view name) const; INLINE void set_bin_active(int bin_index, bool active); - INLINE void set_bin_active(const std::string &name, bool active); + INLINE void set_bin_active(std::string_view name, bool active); #ifndef NDEBUG INLINE bool get_bin_flash_active(int bin_index) const; @@ -83,7 +83,7 @@ class EXPCL_PANDA_PGRAPH CullBinManager : public CullBinEnums { // This defines the factory interface for defining constructors to bin types // (the implementations are in the cull directory, not here in pgraph, so we // can't call the constructors directly). - typedef CullBin *BinConstructor(const std::string &name, + typedef CullBin *BinConstructor(std::string name, GraphicsStateGuardianBase *gsg, const PStatCollector &draw_region_pcollector); @@ -92,7 +92,7 @@ class EXPCL_PANDA_PGRAPH CullBinManager : public CullBinEnums { private: void do_sort_bins(); void setup_initial_bins(); - static BinType parse_bin_type(const std::string &bin_type); + static BinType parse_bin_type(std::string_view bin_type); class EXPCL_PANDA_PGRAPH BinDefinition { public: @@ -116,7 +116,7 @@ class EXPCL_PANDA_PGRAPH CullBinManager : public CullBinEnums { CullBinManager *_manager; }; - typedef pmap BinsByName; + typedef pmap> BinsByName; BinsByName _bins_by_name; typedef vector_int SortedBins; diff --git a/panda/src/pgraph/cullResult.cxx b/panda/src/pgraph/cullResult.cxx index eb8d3519d2d..da1093acc91 100644 --- a/panda/src/pgraph/cullResult.cxx +++ b/panda/src/pgraph/cullResult.cxx @@ -390,10 +390,11 @@ new_page() { void CullResult:: delete_page(AllocationPage *page) { size_t size = std::exchange(page->_size, 0); + CullableObject *objects = std::launder(reinterpret_cast(page->_memory)); for (size_t i = 0; i < size; ++i) { - ((CullableObject *)page->_memory)[i].~CullableObject(); + objects[i].~CullableObject(); #ifdef DO_MEMORY_USAGE - //MemoryUsage::remove_void_pointer(&((CullableObject *)page->_memory)[i]); + //MemoryUsage::remove_void_pointer(&objects[i]); #endif } diff --git a/panda/src/pgraph/findApproxPath.cxx b/panda/src/pgraph/findApproxPath.cxx index 093a160f32f..4446b66f59c 100644 --- a/panda/src/pgraph/findApproxPath.cxx +++ b/panda/src/pgraph/findApproxPath.cxx @@ -26,8 +26,6 @@ using std::string; */ bool FindApproxPath::Component:: matches(PandaNode *node) const { - string node_name; - switch (_type) { case CT_match_name: // Match the node's name exactly. @@ -114,13 +112,13 @@ output(ostream &out) const { * true if successful, false if the string contained an error. */ bool FindApproxPath:: -add_string(const string &str_path) { +add_string(std::string_view str_path) { // First, chop the string up by slashes into its components. - vector_string components; + std::vector components; size_t start = 0; size_t slash = str_path.find('/'); - while (slash != string::npos) { + while (slash != std::string_view::npos) { components.push_back(str_path.substr(start, slash - start)); start = slash + 1; slash = str_path.find('/', start); @@ -133,21 +131,20 @@ add_string(const string &str_path) { // entire string; if this is less than start, there is no semicolon right of // start. if (semicolon < start) { - semicolon = string::npos; + semicolon = std::string_view::npos; } components.push_back(str_path.substr(start, semicolon - start)); - if (semicolon != string::npos) { + if (semicolon != std::string_view::npos) { if (!add_flags(str_path.substr(semicolon + 1))) { return false; } } // Now decode each component and add it to the path. - vector_string::const_iterator ci; - for (ci = components.begin(); ci != components.end(); ++ci) { - if (!add_component(*ci)) { + for (std::string_view component : components) { + if (!add_component(component)) { return false; } } @@ -161,8 +158,8 @@ add_string(const string &str_path) { * true if successful, false otherwise. */ bool FindApproxPath:: -add_flags(const string &str_flags) { - string::const_iterator pi = str_flags.begin(); +add_flags(std::string_view str_flags) { + std::string_view::const_iterator pi = str_flags.begin(); while (pi != str_flags.end()) { bool on; switch (*pi) { @@ -217,7 +214,7 @@ add_flags(const string &str_flags) { * false if the string component was in some way invalid. */ bool FindApproxPath:: -add_component(string str_component) { +add_component(std::string_view str_component) { int flags = 0; if (str_component.size() >= 2 && str_component.substr(0, 2) == "@@") { flags |= CF_stashed; @@ -236,7 +233,7 @@ add_component(string str_component) { add_match_many(flags); } else if (!str_component.empty() && str_component[0] == '-') { - string type_name = str_component.substr(1); + std::string_view type_name = str_component.substr(1); TypeHandle handle = TypeRegistry::ptr()->find_type(type_name); if (handle == TypeHandle::none()) { @@ -249,7 +246,7 @@ add_component(string str_component) { } } else if (!str_component.empty() && str_component[0] == '+') { - string type_name = str_component.substr(1); + std::string_view type_name = str_component.substr(1); TypeHandle handle = TypeRegistry::ptr()->find_type(type_name); if (handle == TypeHandle::none()) { @@ -263,19 +260,19 @@ add_component(string str_component) { } else if (!str_component.empty() && str_component[0] == '=') { size_t equals = str_component.find('=', 1); - if (equals != string::npos) { + if (equals != std::string_view::npos) { // =key=value - string tag_key = str_component.substr(1, equals - 1); - string tag_value = str_component.substr(equals + 1); - add_match_tag_value(tag_key, tag_value, flags); + std::string_view tag_key = str_component.substr(1, equals - 1); + std::string_view tag_value = str_component.substr(equals + 1); + add_match_tag_value(std::string(tag_key), std::string(tag_value), flags); } else { // =key - string tag_key = str_component.substr(1); - add_match_tag(tag_key, flags); + std::string_view tag_key = str_component.substr(1); + add_match_tag(std::string(tag_key), flags); } } else { - add_match_name_glob(str_component, flags); + add_match_name_glob(std::string(str_component), flags); } return true; @@ -285,12 +282,12 @@ add_component(string str_component) { * Adds a component that must match the name of a node exactly. */ void FindApproxPath:: -add_match_name(const string &name, int flags) { +add_match_name(std::string name, int flags) { Component comp; comp._type = _case_insensitive ? CT_match_name_insensitive : CT_match_name; - comp._name = name; + comp._name = std::move(name); comp._flags = flags; - _path.push_back(comp); + _path.push_back(std::move(comp)); } /** @@ -298,19 +295,19 @@ add_match_name(const string &name, int flags) { * globbing rules, with wildcard characters accepted. */ void FindApproxPath:: -add_match_name_glob(const string &name, int flags) { +add_match_name_glob(std::string name, int flags) { Component comp; comp._type = CT_match_name_glob; - comp._name = name; - comp._glob.set_pattern(name); + comp._name = std::move(name); + comp._glob.set_pattern(comp._name); comp._glob.set_case_sensitive(!_case_insensitive); comp._flags = flags; if (!comp._glob.has_glob_characters()) { // The glob pattern contains no special characters; make it a literal // match for efficiency. - add_match_name(name, flags); + add_match_name(std::move(comp._name), flags); } else { - _path.push_back(comp); + _path.push_back(std::move(comp)); } } @@ -324,7 +321,7 @@ add_match_exact_type(TypeHandle type, int flags) { comp._type = CT_match_exact_type; comp._type_handle = type; comp._flags = flags; - _path.push_back(comp); + _path.push_back(std::move(comp)); } /** @@ -337,7 +334,7 @@ add_match_inexact_type(TypeHandle type, int flags) { comp._type = CT_match_inexact_type; comp._type_handle = type; comp._flags = flags; - _path.push_back(comp); + _path.push_back(std::move(comp)); } /** @@ -345,12 +342,12 @@ add_match_inexact_type(TypeHandle type, int flags) { * key, no matter what the value is. */ void FindApproxPath:: -add_match_tag(const string &name, int flags) { +add_match_tag(std::string name, int flags) { Component comp; comp._type = CT_match_tag; - comp._name = name; + comp._name = std::move(name); comp._flags = flags; - _path.push_back(comp); + _path.push_back(std::move(comp)); } /** @@ -359,13 +356,13 @@ add_match_tag(const string &name, int flags) { * to match only those nodes with the indicated value. */ void FindApproxPath:: -add_match_tag_value(const string &name, const string &value, int flags) { +add_match_tag_value(std::string name, std::string value, int flags) { Component comp; comp._type = CT_match_tag_value; - comp._name = name; - comp._glob.set_pattern(value); + comp._name = std::move(name); + comp._glob.set_pattern(std::move(value)); comp._flags = flags; - _path.push_back(comp); + _path.push_back(std::move(comp)); } /** @@ -376,7 +373,7 @@ add_match_one(int flags) { Component comp; comp._type = CT_match_one; comp._flags = flags; - _path.push_back(comp); + _path.push_back(std::move(comp)); } /** @@ -387,7 +384,7 @@ add_match_many(int flags) { Component comp; comp._type = CT_match_many; comp._flags = flags; - _path.push_back(comp); + _path.push_back(std::move(comp)); } /** @@ -399,7 +396,7 @@ add_match_pointer(PandaNode *pointer, int flags) { comp._type = CT_match_pointer; comp._pointer = pointer; comp._flags = flags; - _path.push_back(comp); + _path.push_back(std::move(comp)); } /** diff --git a/panda/src/pgraph/findApproxPath.h b/panda/src/pgraph/findApproxPath.h index a9a7ba88274..4718332721d 100644 --- a/panda/src/pgraph/findApproxPath.h +++ b/panda/src/pgraph/findApproxPath.h @@ -32,16 +32,16 @@ class FindApproxPath { public: INLINE FindApproxPath(); - bool add_string(const std::string &str_path); - bool add_flags(const std::string &str_flags); - bool add_component(std::string str_component); + bool add_string(std::string_view str_path); + bool add_flags(std::string_view str_flags); + bool add_component(std::string_view str_component); - void add_match_name(const std::string &name, int flags); - void add_match_name_glob(const std::string &glob, int flags); + void add_match_name(std::string name, int flags); + void add_match_name_glob(std::string glob, int flags); void add_match_exact_type(TypeHandle type, int flags); void add_match_inexact_type(TypeHandle type, int flags); - void add_match_tag(const std::string &key, int flags); - void add_match_tag_value(const std::string &key, const std::string &value, int flags); + void add_match_tag(std::string key, int flags); + void add_match_tag_value(std::string key, std::string value, int flags); void add_match_one(int flags); void add_match_many(int flags); diff --git a/panda/src/pgraph/fog.cxx b/panda/src/pgraph/fog.cxx index dc45af63ee1..0b5c3ea04e2 100644 --- a/panda/src/pgraph/fog.cxx +++ b/panda/src/pgraph/fog.cxx @@ -47,8 +47,8 @@ operator << (std::ostream &out, Fog::Mode mode) { * */ Fog:: -Fog(const std::string &name) : - PandaNode(name) +Fog(std::string name) : + PandaNode(std::move(name)) { _mode = M_linear; _color.set(1.0f, 1.0f, 1.0f, 1.0f); diff --git a/panda/src/pgraph/fog.h b/panda/src/pgraph/fog.h index 5788df409f0..7d7dac79b46 100644 --- a/panda/src/pgraph/fog.h +++ b/panda/src/pgraph/fog.h @@ -40,7 +40,7 @@ class TransformState; */ class EXPCL_PANDA_PGRAPH Fog : public PandaNode { PUBLISHED: - explicit Fog(const std::string &name); + explicit Fog(std::string name); protected: Fog(const Fog ©); diff --git a/panda/src/pgraph/geomNode.cxx b/panda/src/pgraph/geomNode.cxx index 0b4f54ea5fb..a5823476be1 100644 --- a/panda/src/pgraph/geomNode.cxx +++ b/panda/src/pgraph/geomNode.cxx @@ -52,8 +52,8 @@ TypeHandle GeomNode::_type_handle; * */ GeomNode:: -GeomNode(const std::string &name) : - PandaNode(name) +GeomNode(std::string name) : + PandaNode(std::move(name)) { _preserved = preserve_geom_nodes; diff --git a/panda/src/pgraph/geomNode.h b/panda/src/pgraph/geomNode.h index c6e28516cb2..bcb290e45c7 100644 --- a/panda/src/pgraph/geomNode.h +++ b/panda/src/pgraph/geomNode.h @@ -33,7 +33,7 @@ class GraphicsStateGuardianBase; */ class EXPCL_PANDA_PGRAPH GeomNode : public PandaNode { PUBLISHED: - explicit GeomNode(const std::string &name); + explicit GeomNode(std::string name); protected: GeomNode(const GeomNode ©); diff --git a/panda/src/pgraph/instancedNode.cxx b/panda/src/pgraph/instancedNode.cxx index c1a51281ea1..46f175ff42c 100644 --- a/panda/src/pgraph/instancedNode.cxx +++ b/panda/src/pgraph/instancedNode.cxx @@ -24,8 +24,8 @@ TypeHandle InstancedNode::CData::_type_handle; * */ InstancedNode:: -InstancedNode(const std::string &name) : - PandaNode(name) +InstancedNode(std::string name) : + PandaNode(std::move(name)) { set_cull_callback(); } diff --git a/panda/src/pgraph/instancedNode.h b/panda/src/pgraph/instancedNode.h index f3a6432c0f8..e9b309a031f 100644 --- a/panda/src/pgraph/instancedNode.h +++ b/panda/src/pgraph/instancedNode.h @@ -33,7 +33,7 @@ */ class EXPCL_PANDA_PGRAPH InstancedNode : public PandaNode { PUBLISHED: - explicit InstancedNode(const std::string &name); + explicit InstancedNode(std::string name); protected: InstancedNode(const InstancedNode ©); diff --git a/panda/src/pgraph/lensNode.cxx b/panda/src/pgraph/lensNode.cxx index ae90f61c4b4..e72ba59a3d0 100644 --- a/panda/src/pgraph/lensNode.cxx +++ b/panda/src/pgraph/lensNode.cxx @@ -26,8 +26,8 @@ TypeHandle LensNode::_type_handle; * */ LensNode:: -LensNode(const std::string &name, Lens *lens) : - PandaNode(name) +LensNode(std::string name, Lens *lens) : + PandaNode(std::move(name)) { if (lens == nullptr) { lens = new PerspectiveLens; diff --git a/panda/src/pgraph/lensNode.h b/panda/src/pgraph/lensNode.h index bfd13357477..6ac008ea4ee 100644 --- a/panda/src/pgraph/lensNode.h +++ b/panda/src/pgraph/lensNode.h @@ -29,7 +29,7 @@ */ class EXPCL_PANDA_PGRAPH LensNode : public PandaNode { PUBLISHED: - explicit LensNode(const std::string &name, Lens *lens = nullptr); + explicit LensNode(std::string name, Lens *lens = nullptr); protected: LensNode(const LensNode ©); diff --git a/panda/src/pgraph/loader.I b/panda/src/pgraph/loader.I index 8ca4fc8f50b..7e6d09bd50c 100644 --- a/panda/src/pgraph/loader.I +++ b/panda/src/pgraph/loader.I @@ -109,8 +109,8 @@ get_task_manager() const { * is the initial name of the Loader object. */ INLINE void Loader:: -set_task_chain(const std::string &task_chain) { - _task_chain = task_chain; +set_task_chain(std::string task_chain) { + _task_chain = std::move(task_chain); } /** diff --git a/panda/src/pgraph/loader.cxx b/panda/src/pgraph/loader.cxx index 84d25b47f8a..773369166f0 100644 --- a/panda/src/pgraph/loader.cxx +++ b/panda/src/pgraph/loader.cxx @@ -42,8 +42,8 @@ TypeHandle Loader::_type_handle; * */ Loader:: -Loader(const string &name) : - Namable(name) +Loader(std::string name) : + Namable(std::move(name)) { _task_manager = AsyncTaskManager::get_global_ptr(); _task_chain = name; diff --git a/panda/src/pgraph/loader.h b/panda/src/pgraph/loader.h index 9758151ec1b..f40052eca1a 100644 --- a/panda/src/pgraph/loader.h +++ b/panda/src/pgraph/loader.h @@ -70,11 +70,11 @@ class EXPCL_PANDA_PGRAPH Loader : public TypedReferenceCount, public Namable { Files _files; }; - explicit Loader(const std::string &name = "loader"); + explicit Loader(std::string name = "loader"); INLINE void set_task_manager(AsyncTaskManager *task_manager); INLINE AsyncTaskManager *get_task_manager() const; - INLINE void set_task_chain(const std::string &task_chain); + INLINE void set_task_chain(std::string task_chain); INLINE const std::string &get_task_chain() const; BLOCKING INLINE void stop_threads(); diff --git a/panda/src/pgraph/loaderFileTypeRegistry.cxx b/panda/src/pgraph/loaderFileTypeRegistry.cxx index 2a8d321323e..256617973ab 100644 --- a/panda/src/pgraph/loaderFileTypeRegistry.cxx +++ b/panda/src/pgraph/loaderFileTypeRegistry.cxx @@ -75,7 +75,7 @@ register_type(LoaderFileType *type) { * register_type() when it initializes, thus making the extension loadable. */ void LoaderFileTypeRegistry:: -register_deferred_type(const string &extension, const string &library) { +register_deferred_type(std::string_view extension, std::string library) { string dcextension = downcase(extension); Extensions::const_iterator ei; @@ -110,7 +110,7 @@ register_deferred_type(const string &extension, const string &library) { } } - _deferred_types[dcextension] = library; + _deferred_types[std::move(dcextension)] = std::move(library); } /** @@ -170,7 +170,7 @@ get_type(int n) const { * leading dot). Returns NULL if the extension matches no known file types. */ LoaderFileType *LoaderFileTypeRegistry:: -get_type_from_extension(const string &extension) { +get_type_from_extension(std::string_view extension) { string dcextension = downcase(extension); Extensions::const_iterator ei; @@ -278,8 +278,14 @@ get_global_ptr() { * Records a filename extension recognized by a loader file type. */ void LoaderFileTypeRegistry:: -record_extension(const string &extension, LoaderFileType *type) { +record_extension(std::string_view extension, LoaderFileType *type) { string dcextension = downcase(extension); + + DeferredTypes::iterator di = _deferred_types.find(dcextension); + if (di != _deferred_types.end()) { + _deferred_types.erase(di); + } + Extensions::const_iterator ei; ei = _extensions.find(dcextension); if (ei != _extensions.end()) { @@ -289,8 +295,6 @@ record_extension(const string &extension, LoaderFileType *type) { << dcextension << "\n"; } } else { - _extensions.insert(Extensions::value_type(dcextension, type)); + _extensions.insert(Extensions::value_type(std::move(dcextension), type)); } - - _deferred_types.erase(dcextension); } diff --git a/panda/src/pgraph/loaderFileTypeRegistry.h b/panda/src/pgraph/loaderFileTypeRegistry.h index 9cb1cafa54f..87bb22fc910 100644 --- a/panda/src/pgraph/loaderFileTypeRegistry.h +++ b/panda/src/pgraph/loaderFileTypeRegistry.h @@ -33,7 +33,7 @@ class EXPCL_PANDA_PGRAPH LoaderFileTypeRegistry { ~LoaderFileTypeRegistry(); void register_type(LoaderFileType *type); - void register_deferred_type(const std::string &extension, const std::string &library); + void register_deferred_type(std::string_view extension, std::string library); void unregister_type(LoaderFileType *type); @@ -47,7 +47,7 @@ class EXPCL_PANDA_PGRAPH LoaderFileTypeRegistry { LoaderFileType *get_type(int n) const; MAKE_SEQ(get_types, get_num_types, get_type); MAKE_SEQ_PROPERTY(types, get_num_types, get_type); - LoaderFileType *get_type_from_extension(const std::string &extension); + LoaderFileType *get_type_from_extension(std::string_view extension); void write(std::ostream &out, int indent_level = 0) const; @@ -56,16 +56,16 @@ class EXPCL_PANDA_PGRAPH LoaderFileTypeRegistry { PY_EXTENSION(PyObject *__reduce__() const); private: - void record_extension(const std::string &extension, LoaderFileType *type); + void record_extension(std::string_view extension, LoaderFileType *type); private: typedef pvector Types; Types _types; - typedef pmap Extensions; + typedef pmap> Extensions; Extensions _extensions; - typedef pmap DeferredTypes; + typedef pmap> DeferredTypes; DeferredTypes _deferred_types; static LoaderFileTypeRegistry *_global_ptr; diff --git a/panda/src/pgraph/materialCollection.cxx b/panda/src/pgraph/materialCollection.cxx index 37fbd79c80d..78a9b4a9a61 100644 --- a/panda/src/pgraph/materialCollection.cxx +++ b/panda/src/pgraph/materialCollection.cxx @@ -173,7 +173,7 @@ clear() { * NULL if no material has that name. */ Material *MaterialCollection:: -find_material(const std::string &name) const { +find_material(std::string_view name) const { int num_materials = get_num_materials(); for (int i = 0; i < num_materials; i++) { Material *material = get_material(i); diff --git a/panda/src/pgraph/materialCollection.h b/panda/src/pgraph/materialCollection.h index 1dc46aeca2b..12b21a77047 100644 --- a/panda/src/pgraph/materialCollection.h +++ b/panda/src/pgraph/materialCollection.h @@ -36,7 +36,7 @@ class EXPCL_PANDA_PGRAPH MaterialCollection { bool has_material(Material *material) const; void clear(); - Material *find_material(const std::string &name) const; + Material *find_material(std::string_view name) const; int get_num_materials() const; Material *get_material(int index) const; diff --git a/panda/src/pgraph/modelLoadRequest.cxx b/panda/src/pgraph/modelLoadRequest.cxx index 0bbec06161c..659edeba8aa 100644 --- a/panda/src/pgraph/modelLoadRequest.cxx +++ b/panda/src/pgraph/modelLoadRequest.cxx @@ -22,10 +22,10 @@ TypeHandle ModelLoadRequest::_type_handle; * to begin an asynchronous load. */ ModelLoadRequest:: -ModelLoadRequest(const std::string &name, +ModelLoadRequest(std::string name, const Filename &filename, const LoaderOptions &options, Loader *loader) : - AsyncTask(name), + AsyncTask(std::move(name)), _filename(filename), _options(options), _loader(loader) diff --git a/panda/src/pgraph/modelLoadRequest.h b/panda/src/pgraph/modelLoadRequest.h index f99dc7c38d2..93b592a5003 100644 --- a/panda/src/pgraph/modelLoadRequest.h +++ b/panda/src/pgraph/modelLoadRequest.h @@ -34,7 +34,7 @@ class EXPCL_PANDA_PGRAPH ModelLoadRequest : public AsyncTask { ALLOC_DELETED_CHAIN(ModelLoadRequest); PUBLISHED: - explicit ModelLoadRequest(const std::string &name, + explicit ModelLoadRequest(std::string name, const Filename &filename, const LoaderOptions &options, Loader *loader); diff --git a/panda/src/pgraph/modelNode.I b/panda/src/pgraph/modelNode.I index 929bedd6fc0..fb746030af7 100644 --- a/panda/src/pgraph/modelNode.I +++ b/panda/src/pgraph/modelNode.I @@ -15,8 +15,8 @@ * */ INLINE ModelNode:: -ModelNode(const std::string &name) : - PandaNode(name) +ModelNode(std::string name) : + PandaNode(std::move(name)) { _preserve_transform = PT_none; _preserve_attributes = 0; diff --git a/panda/src/pgraph/modelNode.h b/panda/src/pgraph/modelNode.h index c57d98476ce..463ad98554f 100644 --- a/panda/src/pgraph/modelNode.h +++ b/panda/src/pgraph/modelNode.h @@ -30,7 +30,7 @@ */ class EXPCL_PANDA_PGRAPH ModelNode : public PandaNode { PUBLISHED: - explicit INLINE ModelNode(const std::string &name); + explicit INLINE ModelNode(std::string name); protected: INLINE ModelNode(const ModelNode ©); diff --git a/panda/src/pgraph/modelRoot.I b/panda/src/pgraph/modelRoot.I index 7a8ea482fff..840f7f4cc73 100644 --- a/panda/src/pgraph/modelRoot.I +++ b/panda/src/pgraph/modelRoot.I @@ -15,9 +15,9 @@ * */ INLINE ModelRoot:: -ModelRoot(const std::string &name) : +ModelRoot(std::string name) : ModelNode(name), - _fullpath(name), + _fullpath(std::move(name)), _timestamp(0), _reference(new ModelRoot::ModelReference), _loader_type(TypeHandle::none()) diff --git a/panda/src/pgraph/modelRoot.h b/panda/src/pgraph/modelRoot.h index d249340b110..eb7f3e29127 100644 --- a/panda/src/pgraph/modelRoot.h +++ b/panda/src/pgraph/modelRoot.h @@ -26,7 +26,7 @@ */ class EXPCL_PANDA_PGRAPH ModelRoot : public ModelNode { PUBLISHED: - INLINE explicit ModelRoot(const std::string &name); + INLINE explicit ModelRoot(std::string name); INLINE explicit ModelRoot(const Filename &fullpath, time_t timestamp); INLINE int get_model_ref_count() const; diff --git a/panda/src/pgraph/modelSaveRequest.cxx b/panda/src/pgraph/modelSaveRequest.cxx index eefca944d41..f78a937974b 100644 --- a/panda/src/pgraph/modelSaveRequest.cxx +++ b/panda/src/pgraph/modelSaveRequest.cxx @@ -22,10 +22,10 @@ TypeHandle ModelSaveRequest::_type_handle; * to begin an asynchronous save. */ ModelSaveRequest:: -ModelSaveRequest(const std::string &name, +ModelSaveRequest(std::string name, const Filename &filename, const LoaderOptions &options, PandaNode *node, Loader *loader) : - AsyncTask(name), + AsyncTask(std::move(name)), _filename(filename), _options(options), _node(node), diff --git a/panda/src/pgraph/modelSaveRequest.h b/panda/src/pgraph/modelSaveRequest.h index f15225e1591..6ec6e919013 100644 --- a/panda/src/pgraph/modelSaveRequest.h +++ b/panda/src/pgraph/modelSaveRequest.h @@ -33,7 +33,7 @@ class EXPCL_PANDA_PGRAPH ModelSaveRequest : public AsyncTask { ALLOC_DELETED_CHAIN(ModelSaveRequest); PUBLISHED: - explicit ModelSaveRequest(const std::string &name, + explicit ModelSaveRequest(std::string name, const Filename &filename, const LoaderOptions &options, PandaNode *node, Loader *loader); diff --git a/panda/src/pgraph/nodePath.I b/panda/src/pgraph/nodePath.I index ae0236f427d..51ba67a59d2 100644 --- a/panda/src/pgraph/nodePath.I +++ b/panda/src/pgraph/nodePath.I @@ -26,10 +26,10 @@ NodePath() : * PandaNode is created with the indicated name. */ INLINE NodePath:: -NodePath(const std::string &top_node_name, Thread *current_thread) : +NodePath(std::string top_node_name, Thread *current_thread) : _error_type(ET_ok) { - PandaNode *top_node = new PandaNode(top_node_name); + PandaNode *top_node = new PandaNode(std::move(top_node_name)); int pipeline_stage = current_thread->get_pipeline_stage(); _head = top_node->get_generic_component(false, pipeline_stage, current_thread); _backup_key = 0; @@ -386,10 +386,10 @@ get_parent(Thread *current_thread) const { * returning a new NodePath that references it. */ INLINE NodePath NodePath:: -attach_new_node(const std::string &name, int sort, Thread *current_thread) const { +attach_new_node(std::string name, int sort, Thread *current_thread) const { nassertr(verify_complete(current_thread), NodePath::fail()); - return attach_new_node(new PandaNode(name), sort, current_thread); + return attach_new_node(new PandaNode(std::move(name)), sort, current_thread); } /** @@ -1741,7 +1741,7 @@ clear_project_texture(TextureStage *stage) { * string for the default texture coordinate set. */ INLINE bool NodePath:: -has_texcoord(const std::string &texcoord_name) const { +has_texcoord(std::string_view texcoord_name) const { return has_vertex_column(InternalName::get_texcoord_name(texcoord_name)); } @@ -2089,9 +2089,9 @@ list_tags() const { * Changes the name of the referenced node. */ INLINE void NodePath:: -set_name(const std::string &name) { +set_name(std::string name) { nassertv_always(!is_empty()); - node()->set_name(name); + node()->set_name(std::move(name)); } /** diff --git a/panda/src/pgraph/nodePath.cxx b/panda/src/pgraph/nodePath.cxx index 66d8f6f868a..2275f83537e 100644 --- a/panda/src/pgraph/nodePath.cxx +++ b/panda/src/pgraph/nodePath.cxx @@ -313,7 +313,7 @@ get_sort(Thread *current_thread) const { * The referenced node itself is not considered in the search. */ NodePath NodePath:: -find(const string &path) const { +find(std::string_view path) const { nassertr_always(!is_empty(), fail()); NodePathCollection col; @@ -355,7 +355,7 @@ find_path_to(PandaNode *node) const { * The referenced node itself is not considered in the search. */ NodePathCollection NodePath:: -find_all_matches(const string &path) const { +find_all_matches(std::string_view path) const { NodePathCollection col; nassertr_always(!is_empty(), col); nassertr(verify_complete(), col); @@ -519,9 +519,9 @@ instance_to(const NodePath &other, int sort, Thread *current_thread) const { * the programmer to set a unique state and/or transform on this instance. */ NodePath NodePath:: -instance_under_node(const NodePath &other, const string &name, int sort, +instance_under_node(const NodePath &other, std::string name, int sort, Thread *current_thread) const { - NodePath new_node = other.attach_new_node(name, sort, current_thread); + NodePath new_node = other.attach_new_node(std::move(name), sort, current_thread); NodePath instance = instance_to(new_node, 0, current_thread); if (instance.is_empty()) { new_node.remove_node(current_thread); @@ -2865,9 +2865,9 @@ has_scissor() const { * e.g. "fixed". Other kinds of bins ignore it. */ void NodePath:: -set_bin(const string &bin_name, int draw_order, int priority) { +set_bin(std::string bin_name, int draw_order, int priority) { nassertv_always(!is_empty()); - node()->set_attrib(CullBinAttrib::make(bin_name, draw_order), priority); + node()->set_attrib(CullBinAttrib::make(std::move(bin_name), draw_order), priority); } /** @@ -3898,17 +3898,15 @@ find_all_vertex_columns() const { * wildcard characters). */ InternalNameCollection NodePath:: -find_all_vertex_columns(const string &name) const { +find_all_vertex_columns(std::string name) const { nassertr_always(!is_empty(), InternalNameCollection()); InternalNames vertex_columns; r_find_all_vertex_columns(node(), vertex_columns); - GlobPattern glob(name); + GlobPattern glob(std::move(name)); InternalNameCollection tc; - InternalNames::iterator ti; - for (ti = vertex_columns.begin(); ti != vertex_columns.end(); ++ti) { - const InternalName *name = (*ti); + for (const InternalName *name : vertex_columns) { if (glob.matches(name->get_name())) { tc.add_name(name); } @@ -3929,10 +3927,9 @@ find_all_texcoords() const { CPT(InternalName) texcoord_name = InternalName::get_texcoord(); InternalNameCollection tc; - InternalNames::iterator ti; - for (ti = vertex_columns.begin(); ti != vertex_columns.end(); ++ti) { - if ((*ti)->get_top() == texcoord_name) { - tc.add_name(*ti); + for (const InternalName *name : vertex_columns) { + if (name->get_top() == texcoord_name) { + tc.add_name(name); } } return tc; @@ -3944,18 +3941,16 @@ find_all_texcoords() const { * wildcard characters). */ InternalNameCollection NodePath:: -find_all_texcoords(const string &name) const { +find_all_texcoords(std::string name) const { nassertr_always(!is_empty(), InternalNameCollection()); InternalNames vertex_columns; r_find_all_vertex_columns(node(), vertex_columns); - GlobPattern glob(name); + GlobPattern glob(std::move(name)); CPT_InternalName texcoord_name = InternalName::get_texcoord(); InternalNameCollection tc; - InternalNames::iterator ti; - for (ti = vertex_columns.begin(); ti != vertex_columns.end(); ++ti) { - const InternalName *name = (*ti); + for (const InternalName *name : vertex_columns) { if (name->get_top() == texcoord_name) { // This is a texture coordinate name. Figure out the basename of the // texture coordinates. @@ -3977,9 +3972,9 @@ find_all_texcoords(const string &name) const { * texture if it is found, or NULL if it is not. */ Texture *NodePath:: -find_texture(const string &name) const { +find_texture(std::string name) const { nassertr_always(!is_empty(), nullptr); - GlobPattern glob(name); + GlobPattern glob(std::move(name)); return r_find_texture(node(), get_net_state(), glob); } @@ -4016,12 +4011,12 @@ find_all_textures() const { * that match the indicated name (which may contain wildcard characters). */ TextureCollection NodePath:: -find_all_textures(const string &name) const { +find_all_textures(std::string name) const { nassertr_always(!is_empty(), TextureCollection()); Textures textures; r_find_all_textures(node(), get_net_state(), textures); - GlobPattern glob(name); + GlobPattern glob(std::move(name)); TextureCollection tc; Textures::iterator ti; @@ -4059,9 +4054,9 @@ find_all_textures(TextureStage *stage) const { * Returns the TextureStage if it is found, or NULL if it is not. */ TextureStage *NodePath:: -find_texture_stage(const string &name) const { +find_texture_stage(std::string name) const { nassertr_always(!is_empty(), nullptr); - GlobPattern glob(name); + GlobPattern glob(std::move(name)); return r_find_texture_stage(node(), get_net_state(), glob); } @@ -4102,12 +4097,12 @@ unify_texture_stages(TextureStage *stage) { * characters). */ TextureStageCollection NodePath:: -find_all_texture_stages(const string &name) const { +find_all_texture_stages(std::string name) const { nassertr_always(!is_empty(), TextureStageCollection()); TextureStages texture_stages; r_find_all_texture_stages(node(), get_net_state(), texture_stages); - GlobPattern glob(name); + GlobPattern glob(std::move(name)); TextureStageCollection tc; TextureStages::iterator ti; @@ -4126,9 +4121,9 @@ find_all_texture_stages(const string &name) const { * material if it is found, or NULL if it is not. */ Material *NodePath:: -find_material(const string &name) const { +find_material(std::string name) const { nassertr_always(!is_empty(), nullptr); - GlobPattern glob(name); + GlobPattern glob(std::move(name)); return r_find_material(node(), get_net_state(), glob); } @@ -4154,12 +4149,12 @@ find_all_materials() const { * that match the indicated name (which may contain wildcard characters). */ MaterialCollection NodePath:: -find_all_materials(const string &name) const { +find_all_materials(std::string name) const { nassertr_always(!is_empty(), MaterialCollection()); Materials materials; r_find_all_materials(node(), get_net_state(), materials); - GlobPattern glob(name); + GlobPattern glob(std::move(name)); MaterialCollection tc; Materials::iterator ti; @@ -6137,8 +6132,7 @@ r_get_partial_prev_transform(NodePathComponent *comp, int n, Thread *current_thr * matches to return, or -1 not to limit the number returned. */ void NodePath:: -find_matches(NodePathCollection &result, const string &path, - int max_matches) const { +find_matches(NodePathCollection &result, std::string_view path, int max_matches) const { if (is_empty()) { pgraph_cat.warning() << "Attempt to extend an empty NodePath by '" << path diff --git a/panda/src/pgraph/nodePath.h b/panda/src/pgraph/nodePath.h index 21328a58886..332ca3d3b87 100644 --- a/panda/src/pgraph/nodePath.h +++ b/panda/src/pgraph/nodePath.h @@ -168,7 +168,7 @@ class EXPCL_PANDA_PGRAPH NodePath { }; INLINE NodePath(); - INLINE explicit NodePath(const std::string &top_node_name, Thread *current_thread = Thread::get_current_thread()); + INLINE explicit NodePath(std::string top_node_name, Thread *current_thread = Thread::get_current_thread()); INLINE explicit NodePath(PandaNode *node, Thread *current_thread = Thread::get_current_thread()); INLINE static NodePath any_path(PandaNode *node, Thread *current_thread = Thread::get_current_thread()); explicit NodePath(const NodePath &parent, PandaNode *child_node, @@ -242,9 +242,9 @@ class EXPCL_PANDA_PGRAPH NodePath { MAKE_PROPERTY2(parent, has_parent, get_parent); MAKE_PROPERTY(sort, get_sort); - NodePath find(const std::string &path) const; + NodePath find(std::string_view path) const; NodePath find_path_to(PandaNode *node) const; - NodePathCollection find_all_matches(const std::string &path) const; + NodePathCollection find_all_matches(std::string_view path) const; NodePathCollection find_all_paths_to(PandaNode *node) const; // Methods that actually move nodes around in the scene graph. The optional @@ -260,14 +260,14 @@ class EXPCL_PANDA_PGRAPH NodePath { Thread *current_thread = Thread::get_current_thread()); NodePath instance_to(const NodePath &other, int sort = 0, Thread *current_thread = Thread::get_current_thread()) const; - NodePath instance_under_node(const NodePath &other, const std::string &name, + NodePath instance_under_node(const NodePath &other, std::string name, int sort = 0, Thread *current_thread = Thread::get_current_thread()) const; NodePath copy_to(const NodePath &other, int sort = 0, Thread *current_thread = Thread::get_current_thread()) const; NodePath attach_new_node(PandaNode *node, int sort = 0, Thread *current_thread = Thread::get_current_thread()) const; - INLINE NodePath attach_new_node(const std::string &name, int sort = 0, + INLINE NodePath attach_new_node(std::string name, int sort = 0, Thread *current_thread = Thread::get_current_thread()) const; void remove_node(Thread *current_thread = Thread::get_current_thread()); void detach_node(Thread *current_thread = Thread::get_current_thread()); @@ -598,7 +598,7 @@ class EXPCL_PANDA_PGRAPH NodePath { void clear_occluder(const NodePath &occluder); bool has_occluder(const NodePath &occluder) const; - void set_bin(const std::string &bin_name, int draw_order, int priority = 0); + void set_bin(std::string bin_name, int draw_order, int priority = 0); void clear_bin(); bool has_bin() const; std::string get_bin_name() const; @@ -745,28 +745,28 @@ class EXPCL_PANDA_PGRAPH NodePath { void project_texture(TextureStage *stage, Texture *tex, const NodePath &projector); INLINE void clear_project_texture(TextureStage *stage); - INLINE bool has_texcoord(const std::string &texcoord_name) const; + INLINE bool has_texcoord(std::string_view texcoord_name) const; bool has_vertex_column(const InternalName *name) const; InternalNameCollection find_all_vertex_columns() const; - InternalNameCollection find_all_vertex_columns(const std::string &name) const; + InternalNameCollection find_all_vertex_columns(std::string name) const; InternalNameCollection find_all_texcoords() const; - InternalNameCollection find_all_texcoords(const std::string &name) const; + InternalNameCollection find_all_texcoords(std::string name) const; - Texture *find_texture(const std::string &name) const; + Texture *find_texture(std::string name) const; Texture *find_texture(TextureStage *stage) const; TextureCollection find_all_textures() const; - TextureCollection find_all_textures(const std::string &name) const; + TextureCollection find_all_textures(std::string name) const; TextureCollection find_all_textures(TextureStage *stage) const; - TextureStage *find_texture_stage(const std::string &name) const; + TextureStage *find_texture_stage(std::string name) const; TextureStageCollection find_all_texture_stages() const; - TextureStageCollection find_all_texture_stages(const std::string &name) const; + TextureStageCollection find_all_texture_stages(std::string name) const; void unify_texture_stages(TextureStage *stage); - Material *find_material(const std::string &name) const; + Material *find_material(std::string name) const; MaterialCollection find_all_materials() const; - MaterialCollection find_all_materials(const std::string &name) const; + MaterialCollection find_all_materials(std::string name) const; void set_material(Material *tex, int priority = 0); void set_material_off(int priority = 0); @@ -953,7 +953,7 @@ class EXPCL_PANDA_PGRAPH NodePath { INLINE void list_tags() const; - INLINE void set_name(const std::string &name); + INLINE void set_name(std::string name); INLINE std::string get_name() const; MAKE_PROPERTY(name, get_name, set_name); @@ -988,7 +988,7 @@ class EXPCL_PANDA_PGRAPH NodePath { int n, Thread *current_thread) const; void find_matches(NodePathCollection &result, - const std::string &approx_path_str, + std::string_view approx_path_str, int max_matches) const; void find_matches(NodePathCollection &result, FindApproxPath &approx_path, diff --git a/panda/src/pgraph/nodePathCollection.cxx b/panda/src/pgraph/nodePathCollection.cxx index 545691d0fc7..1eb684b7818 100644 --- a/panda/src/pgraph/nodePathCollection.cxx +++ b/panda/src/pgraph/nodePathCollection.cxx @@ -226,7 +226,7 @@ ls(std::ostream &out, int indent_level) const { * listed first. */ NodePathCollection NodePathCollection:: -find_all_matches(const std::string &path) const { +find_all_matches(std::string_view path) const { NodePathCollection result; FindApproxPath approx_path; diff --git a/panda/src/pgraph/nodePathCollection.h b/panda/src/pgraph/nodePathCollection.h index cc80f5f3889..fd5e7b11d65 100644 --- a/panda/src/pgraph/nodePathCollection.h +++ b/panda/src/pgraph/nodePathCollection.h @@ -56,7 +56,7 @@ class EXPCL_PANDA_PGRAPH NodePathCollection { INLINE void ls() const; void ls(std::ostream &out, int indent_level = 0) const; - NodePathCollection find_all_matches(const std::string &path) const; + NodePathCollection find_all_matches(std::string_view path) const; void reparent_to(const NodePath &other); void wrt_reparent_to(const NodePath &other); diff --git a/panda/src/pgraph/occluderNode.cxx b/panda/src/pgraph/occluderNode.cxx index 408f5e28f19..f0072dcc810 100644 --- a/panda/src/pgraph/occluderNode.cxx +++ b/panda/src/pgraph/occluderNode.cxx @@ -51,8 +51,8 @@ PT(Texture) OccluderNode::_viz_tex; * vertices with set_vertices(). */ OccluderNode:: -OccluderNode(const std::string &name) : - PandaNode(name) +OccluderNode(std::string name) : + PandaNode(std::move(name)) { set_cull_callback(); set_renderable(); diff --git a/panda/src/pgraph/occluderNode.h b/panda/src/pgraph/occluderNode.h index 484c38753d7..ec32fc15259 100644 --- a/panda/src/pgraph/occluderNode.h +++ b/panda/src/pgraph/occluderNode.h @@ -30,7 +30,7 @@ */ class EXPCL_PANDA_PGRAPH OccluderNode : public PandaNode { PUBLISHED: - explicit OccluderNode(const std::string &name); + explicit OccluderNode(std::string name); protected: OccluderNode(const OccluderNode ©); diff --git a/panda/src/pgraph/pandaNode.cxx b/panda/src/pgraph/pandaNode.cxx index e71e4bae439..f986b964b7e 100644 --- a/panda/src/pgraph/pandaNode.cxx +++ b/panda/src/pgraph/pandaNode.cxx @@ -74,8 +74,8 @@ TypeHandle PandaNodePipelineReader::_type_handle; * */ PandaNode:: -PandaNode(const string &name) : - Namable(name), +PandaNode(std::string name) : + Namable(std::move(name)), _paths_lock("PandaNode::_paths_lock"), _prev_transform_valid(_reset_prev_transform_seq) { @@ -1222,7 +1222,7 @@ copy_tags(PandaNode *other) { * of the associated tag keys. */ void PandaNode:: -list_tags(ostream &out, const string &separator) const { +list_tags(ostream &out, std::string_view separator) const { CDReader cdata(_cycler); for (size_t n = 0; n < cdata->_tag_data.size(); ++n) { if (n > 0) { diff --git a/panda/src/pgraph/pandaNode.h b/panda/src/pgraph/pandaNode.h index 8d0723a4cf6..febcb1e10a9 100644 --- a/panda/src/pgraph/pandaNode.h +++ b/panda/src/pgraph/pandaNode.h @@ -65,7 +65,7 @@ class GraphicsStateGuardianBase; class EXPCL_PANDA_PGRAPH PandaNode : public TypedWritableReferenceCount, public Namable { PUBLISHED: - explicit PandaNode(const std::string &name); + explicit PandaNode(std::string name); virtual ~PandaNode(); // published so that characters can be combined. virtual PandaNode *combine_with(PandaNode *other); @@ -104,7 +104,7 @@ class EXPCL_PANDA_PGRAPH PandaNode : public TypedWritableReferenceCount, virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data); PUBLISHED: - virtual PandaNode *make_copy() const; + [[nodiscard]] virtual PandaNode *make_copy() const; PT(PandaNode) copy_subgraph(Thread *current_thread = Thread::get_current_thread()) const; EXTENSION(PT(PandaNode) __copy__() const); @@ -219,7 +219,7 @@ class EXPCL_PANDA_PGRAPH PandaNode : public TypedWritableReferenceCount, INLINE bool has_tags() const; void copy_tags(PandaNode *other); - void list_tags(std::ostream &out, const std::string &separator = "\n") const; + void list_tags(std::ostream &out, std::string_view separator = "\n") const; int compare_tags(const PandaNode *other) const; diff --git a/panda/src/pgraph/planeNode.cxx b/panda/src/pgraph/planeNode.cxx index 4a290a24544..1813fad9fe3 100644 --- a/panda/src/pgraph/planeNode.cxx +++ b/panda/src/pgraph/planeNode.cxx @@ -59,8 +59,8 @@ fillin(DatagramIterator &scan, BamReader *) { * */ PlaneNode:: -PlaneNode(const std::string &name, const LPlane &plane) : - PandaNode(name), +PlaneNode(std::string name, const LPlane &plane) : + PandaNode(std::move(name)), _priority(0), _clip_effect(~0) { diff --git a/panda/src/pgraph/planeNode.h b/panda/src/pgraph/planeNode.h index 2a77d68bc21..47cfe974dcd 100644 --- a/panda/src/pgraph/planeNode.h +++ b/panda/src/pgraph/planeNode.h @@ -35,7 +35,7 @@ */ class EXPCL_PANDA_PGRAPH PlaneNode : public PandaNode { PUBLISHED: - explicit PlaneNode(const std::string &name, const LPlane &plane = LPlane()); + explicit PlaneNode(std::string name, const LPlane &plane = LPlane()); protected: PlaneNode(const PlaneNode ©); diff --git a/panda/src/pgraph/polylightNode.cxx b/panda/src/pgraph/polylightNode.cxx index 508a1c97cfa..f420ab155b7 100644 --- a/panda/src/pgraph/polylightNode.cxx +++ b/panda/src/pgraph/polylightNode.cxx @@ -29,8 +29,8 @@ TypeHandle PolylightNode::_type_handle; * Use PolylightNode() to construct a new PolylightNode object. */ PolylightNode:: -PolylightNode(const std::string &name) : -PandaNode(name) +PolylightNode(std::string name) : +PandaNode(std::move(name)) { _enabled = true; set_pos(0,0,0); diff --git a/panda/src/pgraph/polylightNode.h b/panda/src/pgraph/polylightNode.h index e5caf30735b..69880422eb0 100644 --- a/panda/src/pgraph/polylightNode.h +++ b/panda/src/pgraph/polylightNode.h @@ -52,7 +52,7 @@ class EXPCL_PANDA_PGRAPH PolylightNode : public PandaNode{ AQUADRATIC, }; - explicit PolylightNode(const std::string &name); + explicit PolylightNode(std::string name); INLINE void enable(); INLINE void disable(); INLINE void set_pos(const LPoint3 &position); diff --git a/panda/src/pgraph/portalNode.cxx b/panda/src/pgraph/portalNode.cxx index dd9462f432e..c2909fb88e6 100644 --- a/panda/src/pgraph/portalNode.cxx +++ b/panda/src/pgraph/portalNode.cxx @@ -41,8 +41,8 @@ TypeHandle PortalNode::_type_handle; * Then you can set the vertices yourself, with addVertex. */ PortalNode:: -PortalNode(const std::string &name) : - PandaNode(name), +PortalNode(std::string name) : + PandaNode(std::move(name)), _from_portal_mask(PortalMask::all_on()), _into_portal_mask(PortalMask::all_on()), _flags(0) @@ -61,8 +61,8 @@ PortalNode(const std::string &name) : * portal and setup from Python */ PortalNode:: -PortalNode(const std::string &name, LPoint3 pos, PN_stdfloat scale) : - PandaNode(name), +PortalNode(std::string name, LPoint3 pos, PN_stdfloat scale) : + PandaNode(std::move(name)), _from_portal_mask(PortalMask::all_on()), _into_portal_mask(PortalMask::all_on()), _flags(0) diff --git a/panda/src/pgraph/portalNode.h b/panda/src/pgraph/portalNode.h index 602dd961392..d5ad25fe6b8 100644 --- a/panda/src/pgraph/portalNode.h +++ b/panda/src/pgraph/portalNode.h @@ -29,8 +29,8 @@ */ class EXPCL_PANDA_PGRAPH PortalNode : public PandaNode { PUBLISHED: - explicit PortalNode(const std::string &name); - explicit PortalNode(const std::string &name, LPoint3 pos, PN_stdfloat scale=10.0); + explicit PortalNode(std::string name); + explicit PortalNode(std::string name, LPoint3 pos, PN_stdfloat scale=10.0); protected: PortalNode(const PortalNode ©); diff --git a/panda/src/pgraph/scissorAttrib.cxx b/panda/src/pgraph/scissorAttrib.cxx index f84bab3fc07..363d8abb74d 100644 --- a/panda/src/pgraph/scissorAttrib.cxx +++ b/panda/src/pgraph/scissorAttrib.cxx @@ -35,10 +35,10 @@ ScissorAttrib(const LVecBase4 &frame) : _off(false) { // Impose sensible bounds. - _frame[0] = max(min(_frame[0], (PN_stdfloat)1.0), (PN_stdfloat)0.0); - _frame[1] = max(min(_frame[1], (PN_stdfloat)1.0), _frame[0]); - _frame[2] = max(min(_frame[2], (PN_stdfloat)1.0), (PN_stdfloat)0.0); - _frame[3] = max(min(_frame[3], (PN_stdfloat)1.0), _frame[2]); + _frame[0] = std::clamp(_frame[0], (PN_stdfloat)0.0, (PN_stdfloat)1.0); + _frame[1] = std::clamp(_frame[1], _frame[0], (PN_stdfloat)1.0); + _frame[2] = std::clamp(_frame[2], (PN_stdfloat)0.0, (PN_stdfloat)1.0); + _frame[3] = std::clamp(_frame[3], _frame[2], (PN_stdfloat)1.0); } /** diff --git a/panda/src/pgraph/scissorEffect.cxx b/panda/src/pgraph/scissorEffect.cxx index 09619b6c2b2..91724bdecaf 100644 --- a/panda/src/pgraph/scissorEffect.cxx +++ b/panda/src/pgraph/scissorEffect.cxx @@ -262,10 +262,10 @@ cull_callback(CullTraverser *trav, CullTraverserData &data, } // Impose bounding volumes. - frame[0] = max(min(frame[0], (PN_stdfloat)1.0), (PN_stdfloat)0.0); - frame[1] = max(min(frame[1], (PN_stdfloat)1.0), frame[0]); - frame[2] = max(min(frame[2], (PN_stdfloat)1.0), (PN_stdfloat)0.0); - frame[3] = max(min(frame[3], (PN_stdfloat)1.0), frame[2]); + frame[0] = std::clamp(frame[0], (PN_stdfloat)0.0, (PN_stdfloat)1.0); + frame[1] = std::clamp(frame[1], frame[0], (PN_stdfloat)1.0); + frame[2] = std::clamp(frame[2], (PN_stdfloat)0.0, (PN_stdfloat)1.0); + frame[3] = std::clamp(frame[3], frame[2], (PN_stdfloat)1.0); if (_clip) { CPT(RenderAttrib) scissor_attrib = ScissorAttrib::make(frame); diff --git a/panda/src/pgraph/shaderAttrib.cxx b/panda/src/pgraph/shaderAttrib.cxx index 440eff1acc1..b096f1e743d 100644 --- a/panda/src/pgraph/shaderAttrib.cxx +++ b/panda/src/pgraph/shaderAttrib.cxx @@ -273,7 +273,7 @@ clear_shader_input(const InternalName *id) const { * */ CPT(RenderAttrib) ShaderAttrib:: -clear_shader_input(const std::string &id) const { +clear_shader_input(std::string_view id) const { return clear_shader_input(InternalName::make(id)); } @@ -306,7 +306,7 @@ get_shader_input(const InternalName *id) const { * function does not return NULL --- it returns the "blank" ShaderInput. */ const ShaderInput &ShaderAttrib:: -get_shader_input(const std::string &id) const { +get_shader_input(std::string_view id) const { return get_shader_input(InternalName::make(id)); } diff --git a/panda/src/pgraph/shaderAttrib.h b/panda/src/pgraph/shaderAttrib.h index 119f2f997c7..3e1a466e8ab 100644 --- a/panda/src/pgraph/shaderAttrib.h +++ b/panda/src/pgraph/shaderAttrib.h @@ -106,7 +106,7 @@ class EXPCL_PANDA_PGRAPH ShaderAttrib final : public RenderAttrib { CPT(RenderAttrib) clear_flag(int flag) const; CPT(RenderAttrib) clear_shader_input(const InternalName *id) const; - CPT(RenderAttrib) clear_shader_input(const std::string &id) const; + CPT(RenderAttrib) clear_shader_input(std::string_view id) const; CPT(RenderAttrib) clear_all_shader_inputs() const; @@ -115,7 +115,7 @@ class EXPCL_PANDA_PGRAPH ShaderAttrib final : public RenderAttrib { const Shader *get_shader() const; const ShaderInput &get_shader_input(const InternalName *id) const; - const ShaderInput &get_shader_input(const std::string &id) const; + const ShaderInput &get_shader_input(std::string_view id) const; NodePath get_shader_input_nodepath(const InternalName *id) const; LVecBase4 get_shader_input_vector(InternalName *id) const; diff --git a/panda/src/pgraph/textureStageCollection.cxx b/panda/src/pgraph/textureStageCollection.cxx index b7fe96d885c..78f7293cef2 100644 --- a/panda/src/pgraph/textureStageCollection.cxx +++ b/panda/src/pgraph/textureStageCollection.cxx @@ -176,7 +176,7 @@ clear() { * any, or NULL if no texture_stage has that name. */ TextureStage *TextureStageCollection:: -find_texture_stage(const std::string &name) const { +find_texture_stage(std::string_view name) const { int num_texture_stages = get_num_texture_stages(); for (int i = 0; i < num_texture_stages; i++) { TextureStage *texture_stage = get_texture_stage(i); diff --git a/panda/src/pgraph/textureStageCollection.h b/panda/src/pgraph/textureStageCollection.h index d29a5c222dc..a8c2cd9fb40 100644 --- a/panda/src/pgraph/textureStageCollection.h +++ b/panda/src/pgraph/textureStageCollection.h @@ -36,7 +36,7 @@ class EXPCL_PANDA_PGRAPH TextureStageCollection { bool has_texture_stage(TextureStage *texture_stage) const; void clear(); - TextureStage *find_texture_stage(const std::string &name) const; + TextureStage *find_texture_stage(std::string_view name) const; int get_num_texture_stages() const; TextureStage *get_texture_stage(int index) const; diff --git a/panda/src/pgraphnodes/ambientLight.cxx b/panda/src/pgraphnodes/ambientLight.cxx index f072f1ba6fe..3bbc57c0d43 100644 --- a/panda/src/pgraphnodes/ambientLight.cxx +++ b/panda/src/pgraphnodes/ambientLight.cxx @@ -23,8 +23,8 @@ TypeHandle AmbientLight::_type_handle; * */ AmbientLight:: -AmbientLight(const std::string &name) : - LightNode(name) +AmbientLight(std::string name) : + LightNode(std::move(name)) { } diff --git a/panda/src/pgraphnodes/ambientLight.h b/panda/src/pgraphnodes/ambientLight.h index 6c9d494b0cd..1730d258850 100644 --- a/panda/src/pgraphnodes/ambientLight.h +++ b/panda/src/pgraphnodes/ambientLight.h @@ -25,7 +25,7 @@ */ class EXPCL_PANDA_PGRAPHNODES AmbientLight : public LightNode { PUBLISHED: - explicit AmbientLight(const std::string &name); + explicit AmbientLight(std::string name); protected: AmbientLight(const AmbientLight ©); diff --git a/panda/src/pgraphnodes/callbackNode.cxx b/panda/src/pgraphnodes/callbackNode.cxx index 8ebb38cd15d..d71f6982bcd 100644 --- a/panda/src/pgraphnodes/callbackNode.cxx +++ b/panda/src/pgraphnodes/callbackNode.cxx @@ -26,8 +26,8 @@ TypeHandle CallbackNode::_type_handle; * */ CallbackNode:: -CallbackNode(const std::string &name) : - PandaNode(name) +CallbackNode(std::string name) : + PandaNode(std::move(name)) { PandaNode::set_cull_callback(); PandaNode::set_renderable(); diff --git a/panda/src/pgraphnodes/callbackNode.h b/panda/src/pgraphnodes/callbackNode.h index f658137ddc3..50edda3268f 100644 --- a/panda/src/pgraphnodes/callbackNode.h +++ b/panda/src/pgraphnodes/callbackNode.h @@ -25,7 +25,7 @@ */ class EXPCL_PANDA_PGRAPHNODES CallbackNode : public PandaNode { PUBLISHED: - explicit CallbackNode(const std::string &name); + explicit CallbackNode(std::string name); INLINE void set_cull_callback(CallbackObject *object); INLINE void clear_cull_callback(); diff --git a/panda/src/pgraphnodes/computeNode.cxx b/panda/src/pgraphnodes/computeNode.cxx index 505989762d2..f3f3e558b93 100644 --- a/panda/src/pgraphnodes/computeNode.cxx +++ b/panda/src/pgraphnodes/computeNode.cxx @@ -27,8 +27,8 @@ TypeHandle ComputeNode::_type_handle; * assign a shader using a ShaderAttrib. */ ComputeNode:: -ComputeNode(const std::string &name) : - PandaNode(name), +ComputeNode(std::string name) : + PandaNode(std::move(name)), _dispatcher(new ComputeNode::Dispatcher) { set_internal_bounds(new OmniBoundingVolume); diff --git a/panda/src/pgraphnodes/computeNode.h b/panda/src/pgraphnodes/computeNode.h index 34065ca16f4..7aacb4be922 100644 --- a/panda/src/pgraphnodes/computeNode.h +++ b/panda/src/pgraphnodes/computeNode.h @@ -27,7 +27,7 @@ */ class EXPCL_PANDA_PGRAPHNODES ComputeNode : public PandaNode { PUBLISHED: - explicit ComputeNode(const std::string &name); + explicit ComputeNode(std::string name); INLINE void add_dispatch(const LVecBase3i &num_groups); INLINE void add_dispatch(int num_groups_x, int num_groups_y, int num_groups_z); diff --git a/panda/src/pgraphnodes/directionalLight.cxx b/panda/src/pgraphnodes/directionalLight.cxx index 062d2d364dc..2357055079d 100644 --- a/panda/src/pgraphnodes/directionalLight.cxx +++ b/panda/src/pgraphnodes/directionalLight.cxx @@ -55,8 +55,8 @@ fillin(DatagramIterator &scan, BamReader *) { * */ DirectionalLight:: -DirectionalLight(const std::string &name) : - LightLensNode(name, new OrthographicLens()) { +DirectionalLight(std::string name) : + LightLensNode(std::move(name), new OrthographicLens()) { _lenses[0]._lens->set_interocular_distance(0); } diff --git a/panda/src/pgraphnodes/directionalLight.h b/panda/src/pgraphnodes/directionalLight.h index f5453399ef6..53b5f8a8137 100644 --- a/panda/src/pgraphnodes/directionalLight.h +++ b/panda/src/pgraphnodes/directionalLight.h @@ -24,7 +24,7 @@ */ class EXPCL_PANDA_PGRAPHNODES DirectionalLight : public LightLensNode { PUBLISHED: - explicit DirectionalLight(const std::string &name); + explicit DirectionalLight(std::string name); protected: DirectionalLight(const DirectionalLight ©); diff --git a/panda/src/pgraphnodes/fadeLodNode.cxx b/panda/src/pgraphnodes/fadeLodNode.cxx index 3223dcc0f8c..b30e299b9a6 100644 --- a/panda/src/pgraphnodes/fadeLodNode.cxx +++ b/panda/src/pgraphnodes/fadeLodNode.cxx @@ -28,8 +28,8 @@ TypeHandle FadeLODNode::_type_handle; * */ FadeLODNode:: -FadeLODNode(const std::string &name) : - LODNode(name) +FadeLODNode(std::string name) : + LODNode(std::move(name)) { set_cull_callback(); @@ -232,8 +232,8 @@ output(std::ostream &out) const { * of the geometry during a transition. */ void FadeLODNode:: -set_fade_bin(const std::string &name, int draw_order) { - _fade_bin_name = name; +set_fade_bin(std::string name, int draw_order) { + _fade_bin_name = std::move(name); _fade_bin_draw_order = draw_order; _fade_1_new_state.clear(); _fade_2_old_state.clear(); diff --git a/panda/src/pgraphnodes/fadeLodNode.h b/panda/src/pgraphnodes/fadeLodNode.h index 7f748ace4e6..3bc34a78442 100644 --- a/panda/src/pgraphnodes/fadeLodNode.h +++ b/panda/src/pgraphnodes/fadeLodNode.h @@ -23,7 +23,7 @@ */ class EXPCL_PANDA_PGRAPHNODES FadeLODNode : public LODNode { PUBLISHED: - explicit FadeLODNode(const std::string &name); + explicit FadeLODNode(std::string name); protected: FadeLODNode(const FadeLODNode ©); @@ -37,7 +37,7 @@ class EXPCL_PANDA_PGRAPHNODES FadeLODNode : public LODNode { INLINE PN_stdfloat get_fade_time() const; MAKE_PROPERTY(fade_time, get_fade_time, set_fade_time); - void set_fade_bin(const std::string &name, int draw_order); + void set_fade_bin(std::string name, int draw_order); INLINE const std::string &get_fade_bin_name() const; INLINE int get_fade_bin_draw_order() const; MAKE_PROPERTY(fade_bin_name, get_fade_bin_name); diff --git a/panda/src/pgraphnodes/lightLensNode.cxx b/panda/src/pgraphnodes/lightLensNode.cxx index 2caa2e7ac26..1633c4f5450 100644 --- a/panda/src/pgraphnodes/lightLensNode.cxx +++ b/panda/src/pgraphnodes/lightLensNode.cxx @@ -28,8 +28,8 @@ TypeHandle LightLensNode::_type_handle; * */ LightLensNode:: -LightLensNode(const std::string &name, Lens *lens) : - Camera(name, lens), +LightLensNode(std::string name, Lens *lens) : + Camera(std::move(name), lens), _has_specular_color(false), _used_by_auto_shader(false), _attrib_count(0) diff --git a/panda/src/pgraphnodes/lightLensNode.h b/panda/src/pgraphnodes/lightLensNode.h index 6b52c974513..fb05828f98c 100644 --- a/panda/src/pgraphnodes/lightLensNode.h +++ b/panda/src/pgraphnodes/lightLensNode.h @@ -32,7 +32,7 @@ class GraphicsStateGuardian; */ class EXPCL_PANDA_PGRAPHNODES LightLensNode : public Light, public Camera { PUBLISHED: - explicit LightLensNode(const std::string &name, Lens *lens = new PerspectiveLens()); + explicit LightLensNode(std::string name, Lens *lens = new PerspectiveLens()); virtual ~LightLensNode(); INLINE bool has_specular_color() const; diff --git a/panda/src/pgraphnodes/lightNode.cxx b/panda/src/pgraphnodes/lightNode.cxx index cffcb05a2f1..66e4cb74c16 100644 --- a/panda/src/pgraphnodes/lightNode.cxx +++ b/panda/src/pgraphnodes/lightNode.cxx @@ -23,8 +23,8 @@ TypeHandle LightNode::_type_handle; * */ LightNode:: -LightNode(const std::string &name) : - PandaNode(name) +LightNode(std::string name) : + PandaNode(std::move(name)) { } diff --git a/panda/src/pgraphnodes/lightNode.h b/panda/src/pgraphnodes/lightNode.h index a3b85a8d908..57b4ed585c9 100644 --- a/panda/src/pgraphnodes/lightNode.h +++ b/panda/src/pgraphnodes/lightNode.h @@ -26,7 +26,7 @@ */ class EXPCL_PANDA_PGRAPHNODES LightNode : public Light, public PandaNode { PUBLISHED: - explicit LightNode(const std::string &name); + explicit LightNode(std::string name); protected: LightNode(const LightNode ©); diff --git a/panda/src/pgraphnodes/lodNode.I b/panda/src/pgraphnodes/lodNode.I index 92398e35fe9..4d1ce5318fc 100644 --- a/panda/src/pgraphnodes/lodNode.I +++ b/panda/src/pgraphnodes/lodNode.I @@ -15,8 +15,8 @@ * */ INLINE LODNode:: -LODNode(const std::string &name) : - PandaNode(name) +LODNode(std::string name) : + PandaNode(std::move(name)) { set_cull_callback(); } diff --git a/panda/src/pgraphnodes/lodNode.cxx b/panda/src/pgraphnodes/lodNode.cxx index 61e0ce0dcf4..1ab3ce43b20 100644 --- a/panda/src/pgraphnodes/lodNode.cxx +++ b/panda/src/pgraphnodes/lodNode.cxx @@ -45,18 +45,18 @@ TypeHandle LODNode::_type_handle; * variable. */ PT(LODNode) LODNode:: -make_default_lod(const std::string &name) { +make_default_lod(std::string name) { switch (default_lod_type.get_value()) { case LNT_pop: - return new LODNode(name); + return new LODNode(std::move(name)); case LNT_fade: - return new FadeLODNode(name); + return new FadeLODNode(std::move(name)); default: pgraph_cat.error() << "Invalid LODNodeType value: " << (int)default_lod_type << "\n"; - return new LODNode(name); + return new LODNode(std::move(name)); } } diff --git a/panda/src/pgraphnodes/lodNode.h b/panda/src/pgraphnodes/lodNode.h index 6c46659c04f..3789a1ac9ed 100644 --- a/panda/src/pgraphnodes/lodNode.h +++ b/panda/src/pgraphnodes/lodNode.h @@ -28,9 +28,9 @@ */ class EXPCL_PANDA_PGRAPHNODES LODNode : public PandaNode { PUBLISHED: - INLINE explicit LODNode(const std::string &name); + INLINE explicit LODNode(std::string name); - static PT(LODNode) make_default_lod(const std::string &name); + static PT(LODNode) make_default_lod(std::string name); protected: INLINE LODNode(const LODNode ©); diff --git a/panda/src/pgraphnodes/pointLight.cxx b/panda/src/pgraphnodes/pointLight.cxx index 8a132515aa6..f0d536a77be 100644 --- a/panda/src/pgraphnodes/pointLight.cxx +++ b/panda/src/pgraphnodes/pointLight.cxx @@ -61,8 +61,8 @@ fillin(DatagramIterator &scan, BamReader *manager) { * */ PointLight:: -PointLight(const std::string &name) : - LightLensNode(name) { +PointLight(std::string name) : + LightLensNode(std::move(name)) { PT(Lens) lens; lens = new PerspectiveLens(90, 90); lens->set_interocular_distance(0); diff --git a/panda/src/pgraphnodes/pointLight.h b/panda/src/pgraphnodes/pointLight.h index d54efc04ba0..15f9f5394d7 100644 --- a/panda/src/pgraphnodes/pointLight.h +++ b/panda/src/pgraphnodes/pointLight.h @@ -24,7 +24,7 @@ */ class EXPCL_PANDA_PGRAPHNODES PointLight : public LightLensNode { PUBLISHED: - explicit PointLight(const std::string &name); + explicit PointLight(std::string name); protected: PointLight(const PointLight ©); diff --git a/panda/src/pgraphnodes/rectangleLight.cxx b/panda/src/pgraphnodes/rectangleLight.cxx index 1af641788ce..ffe050aca24 100644 --- a/panda/src/pgraphnodes/rectangleLight.cxx +++ b/panda/src/pgraphnodes/rectangleLight.cxx @@ -50,8 +50,8 @@ fillin(DatagramIterator &scan, BamReader *manager) { * */ RectangleLight:: -RectangleLight(const std::string &name) : - LightLensNode(name) +RectangleLight(std::string name) : + LightLensNode(std::move(name)) { } diff --git a/panda/src/pgraphnodes/rectangleLight.h b/panda/src/pgraphnodes/rectangleLight.h index 770f7f7d0d6..40f36c89fc8 100644 --- a/panda/src/pgraphnodes/rectangleLight.h +++ b/panda/src/pgraphnodes/rectangleLight.h @@ -27,7 +27,7 @@ */ class EXPCL_PANDA_PGRAPHNODES RectangleLight : public LightLensNode { PUBLISHED: - explicit RectangleLight(const std::string &name); + explicit RectangleLight(std::string name); protected: RectangleLight(const RectangleLight ©); diff --git a/panda/src/pgraphnodes/selectiveChildNode.I b/panda/src/pgraphnodes/selectiveChildNode.I index 46b40ba3a70..c95143bfecc 100644 --- a/panda/src/pgraphnodes/selectiveChildNode.I +++ b/panda/src/pgraphnodes/selectiveChildNode.I @@ -15,8 +15,8 @@ * */ INLINE SelectiveChildNode:: -SelectiveChildNode(const std::string &name) : - PandaNode(name) +SelectiveChildNode(std::string name) : + PandaNode(std::move(name)) { } diff --git a/panda/src/pgraphnodes/selectiveChildNode.h b/panda/src/pgraphnodes/selectiveChildNode.h index aa23a49f1d2..82ea97919d0 100644 --- a/panda/src/pgraphnodes/selectiveChildNode.h +++ b/panda/src/pgraphnodes/selectiveChildNode.h @@ -26,7 +26,7 @@ */ class EXPCL_PANDA_PGRAPHNODES SelectiveChildNode : public PandaNode { PUBLISHED: - INLINE explicit SelectiveChildNode(const std::string &name); + INLINE explicit SelectiveChildNode(std::string name); protected: INLINE SelectiveChildNode(const SelectiveChildNode ©); diff --git a/panda/src/pgraphnodes/sequenceNode.I b/panda/src/pgraphnodes/sequenceNode.I index 68fb10120ea..98a852e225b 100644 --- a/panda/src/pgraphnodes/sequenceNode.I +++ b/panda/src/pgraphnodes/sequenceNode.I @@ -15,8 +15,8 @@ * */ INLINE SequenceNode:: -SequenceNode(const std::string &name) : - SelectiveChildNode(name) +SequenceNode(std::string name) : + SelectiveChildNode(std::move(name)) { set_cull_callback(); } diff --git a/panda/src/pgraphnodes/sequenceNode.h b/panda/src/pgraphnodes/sequenceNode.h index ba67bbf18cf..83b7e4295a4 100644 --- a/panda/src/pgraphnodes/sequenceNode.h +++ b/panda/src/pgraphnodes/sequenceNode.h @@ -26,7 +26,7 @@ */ class EXPCL_PANDA_PGRAPHNODES SequenceNode : public SelectiveChildNode, public AnimInterface { PUBLISHED: - INLINE explicit SequenceNode(const std::string &name); + INLINE explicit SequenceNode(std::string name); protected: SequenceNode(const SequenceNode ©); diff --git a/panda/src/pgraphnodes/sphereLight.cxx b/panda/src/pgraphnodes/sphereLight.cxx index 6cd70c2fbbe..afa6a82b71a 100644 --- a/panda/src/pgraphnodes/sphereLight.cxx +++ b/panda/src/pgraphnodes/sphereLight.cxx @@ -50,8 +50,8 @@ fillin(DatagramIterator &scan, BamReader *manager) { * */ SphereLight:: -SphereLight(const std::string &name) : - PointLight(name) +SphereLight(std::string name) : + PointLight(std::move(name)) { } diff --git a/panda/src/pgraphnodes/sphereLight.h b/panda/src/pgraphnodes/sphereLight.h index 3717764b774..525580b8cca 100644 --- a/panda/src/pgraphnodes/sphereLight.h +++ b/panda/src/pgraphnodes/sphereLight.h @@ -27,7 +27,7 @@ */ class EXPCL_PANDA_PGRAPHNODES SphereLight : public PointLight { PUBLISHED: - explicit SphereLight(const std::string &name); + explicit SphereLight(std::string name); protected: SphereLight(const SphereLight ©); diff --git a/panda/src/pgraphnodes/spotlight.cxx b/panda/src/pgraphnodes/spotlight.cxx index a7d334e7213..0c5208d59a5 100644 --- a/panda/src/pgraphnodes/spotlight.cxx +++ b/panda/src/pgraphnodes/spotlight.cxx @@ -64,8 +64,8 @@ fillin(DatagramIterator &scan, BamReader *manager) { * */ Spotlight:: -Spotlight(const std::string &name) : - LightLensNode(name) { +Spotlight(std::string name) : + LightLensNode(std::move(name)) { _lenses[0]._lens->set_interocular_distance(0); } diff --git a/panda/src/pgraphnodes/spotlight.h b/panda/src/pgraphnodes/spotlight.h index b548b92e8bb..cadbf95af27 100644 --- a/panda/src/pgraphnodes/spotlight.h +++ b/panda/src/pgraphnodes/spotlight.h @@ -31,7 +31,7 @@ */ class EXPCL_PANDA_PGRAPHNODES Spotlight : public LightLensNode { PUBLISHED: - explicit Spotlight(const std::string &name); + explicit Spotlight(std::string name); protected: Spotlight(const Spotlight ©); diff --git a/panda/src/pgraphnodes/switchNode.I b/panda/src/pgraphnodes/switchNode.I index b7943210dce..a55f5865777 100644 --- a/panda/src/pgraphnodes/switchNode.I +++ b/panda/src/pgraphnodes/switchNode.I @@ -32,8 +32,8 @@ CData(const SwitchNode::CData ©) : * */ INLINE SwitchNode:: -SwitchNode(const std::string &name) : - SelectiveChildNode(name) +SwitchNode(std::string name) : + SelectiveChildNode(std::move(name)) { set_cull_callback(); } diff --git a/panda/src/pgraphnodes/switchNode.h b/panda/src/pgraphnodes/switchNode.h index 1fe3353a68b..075302264bb 100644 --- a/panda/src/pgraphnodes/switchNode.h +++ b/panda/src/pgraphnodes/switchNode.h @@ -24,7 +24,7 @@ */ class EXPCL_PANDA_PGRAPHNODES SwitchNode : public SelectiveChildNode { PUBLISHED: - INLINE explicit SwitchNode(const std::string &name); + INLINE explicit SwitchNode(std::string name); public: SwitchNode(const SwitchNode ©); diff --git a/panda/src/pgraphnodes/uvScrollNode.I b/panda/src/pgraphnodes/uvScrollNode.I index 893f76e2cc4..899265567bf 100644 --- a/panda/src/pgraphnodes/uvScrollNode.I +++ b/panda/src/pgraphnodes/uvScrollNode.I @@ -15,8 +15,8 @@ * */ INLINE UvScrollNode:: -UvScrollNode(const std::string &name, PN_stdfloat u_speed, PN_stdfloat v_speed, PN_stdfloat w_speed, PN_stdfloat r_speed) : - PandaNode(name), +UvScrollNode(std::string name, PN_stdfloat u_speed, PN_stdfloat v_speed, PN_stdfloat w_speed, PN_stdfloat r_speed) : + PandaNode(std::move(name)), _u_speed(u_speed), _v_speed(v_speed), _w_speed(w_speed), @@ -30,8 +30,8 @@ UvScrollNode(const std::string &name, PN_stdfloat u_speed, PN_stdfloat v_speed, * */ INLINE UvScrollNode:: -UvScrollNode(const std::string &name) : - PandaNode(name), +UvScrollNode(std::string name) : + PandaNode(std::move(name)), _u_speed(0), _v_speed(0), _w_speed(0), diff --git a/panda/src/pgraphnodes/uvScrollNode.h b/panda/src/pgraphnodes/uvScrollNode.h index 51ab828130b..5c799ef43e6 100644 --- a/panda/src/pgraphnodes/uvScrollNode.h +++ b/panda/src/pgraphnodes/uvScrollNode.h @@ -25,8 +25,8 @@ */ class EXPCL_PANDA_PGRAPHNODES UvScrollNode : public PandaNode { PUBLISHED: - INLINE explicit UvScrollNode(const std::string &name, PN_stdfloat u_speed, PN_stdfloat v_speed, PN_stdfloat w_speed, PN_stdfloat r_speed); - INLINE explicit UvScrollNode(const std::string &name); + INLINE explicit UvScrollNode(std::string name, PN_stdfloat u_speed, PN_stdfloat v_speed, PN_stdfloat w_speed, PN_stdfloat r_speed); + INLINE explicit UvScrollNode(std::string name); protected: INLINE UvScrollNode(const UvScrollNode ©); diff --git a/panda/src/pgui/pgButton.cxx b/panda/src/pgui/pgButton.cxx index 09a91120d40..2ad1e1a6b59 100644 --- a/panda/src/pgui/pgButton.cxx +++ b/panda/src/pgui/pgButton.cxx @@ -26,7 +26,7 @@ TypeHandle PGButton::_type_handle; * */ PGButton:: -PGButton(const std::string &name) : PGItem(name) +PGButton(std::string name) : PGItem(std::move(name)) { _button_down = false; _click_buttons.insert(MouseButton::one()); @@ -154,7 +154,7 @@ click(const MouseWatcherParameter ¶m) { * to the size of the text. */ void PGButton:: -setup(const std::string &label, PN_stdfloat bevel) { +setup(std::string_view label, PN_stdfloat bevel) { LightReMutexHolder holder(_lock); clear_state_def(S_ready); clear_state_def(S_depressed); diff --git a/panda/src/pgui/pgButton.h b/panda/src/pgui/pgButton.h index 3405f5b5d1f..8073a051168 100644 --- a/panda/src/pgui/pgButton.h +++ b/panda/src/pgui/pgButton.h @@ -28,7 +28,7 @@ */ class EXPCL_PANDA_PGUI PGButton : public PGItem { PUBLISHED: - explicit PGButton(const std::string &name); + explicit PGButton(std::string name); virtual ~PGButton(); protected: @@ -55,7 +55,7 @@ class EXPCL_PANDA_PGUI PGButton : public PGItem { S_inactive }; - void setup(const std::string &label, PN_stdfloat bevel = 0.1f); + void setup(std::string_view label, PN_stdfloat bevel = 0.1f); INLINE void setup(const NodePath &ready); INLINE void setup(const NodePath &ready, const NodePath &depressed); INLINE void setup(const NodePath &ready, const NodePath &depressed, diff --git a/panda/src/pgui/pgEntry.I b/panda/src/pgui/pgEntry.I index 61262d87aa9..adf8edf94ea 100644 --- a/panda/src/pgui/pgEntry.I +++ b/panda/src/pgui/pgEntry.I @@ -20,7 +20,7 @@ * truncated (see set_max_width(), etc.). */ INLINE bool PGEntry:: -set_text(const std::string &text) { +set_text(std::string_view text) { LightReMutexHolder holder(_lock); TextNode *text_node = get_text_def(S_focus); nassertr(text_node != nullptr, false); @@ -382,9 +382,9 @@ get_overflow_mode() const { * candidate string that the user can actively scroll through. */ INLINE void PGEntry:: -set_candidate_active(const std::string &candidate_active) { +set_candidate_active(std::string candidate_active) { LightReMutexHolder holder(_lock); - _candidate_active = candidate_active; + _candidate_active = std::move(candidate_active); } /** @@ -409,9 +409,9 @@ get_candidate_active() const { * candidate string that the user is not actively scrolling through. */ INLINE void PGEntry:: -set_candidate_inactive(const std::string &candidate_inactive) { +set_candidate_inactive(std::string candidate_inactive) { LightReMutexHolder holder(_lock); - _candidate_inactive = candidate_inactive; + _candidate_inactive = std::move(candidate_inactive); } /** diff --git a/panda/src/pgui/pgEntry.cxx b/panda/src/pgui/pgEntry.cxx index a3f41af9b05..8db94bd0d1c 100644 --- a/panda/src/pgui/pgEntry.cxx +++ b/panda/src/pgui/pgEntry.cxx @@ -38,8 +38,8 @@ TypeHandle PGEntry::_type_handle; * */ PGEntry:: -PGEntry(const string &name) : - PGItem(name), +PGEntry(std::string name) : + PGItem(std::move(name)), _text(get_text_node()), _obscure_text(get_text_node()), _candidate_text(get_text_node()) diff --git a/panda/src/pgui/pgEntry.h b/panda/src/pgui/pgEntry.h index 3497220c722..87064c3bd00 100644 --- a/panda/src/pgui/pgEntry.h +++ b/panda/src/pgui/pgEntry.h @@ -37,7 +37,7 @@ */ class EXPCL_PANDA_PGUI PGEntry : public PGItem { PUBLISHED: - explicit PGEntry(const std::string &name); + explicit PGEntry(std::string name); virtual ~PGEntry(); protected: @@ -69,7 +69,7 @@ class EXPCL_PANDA_PGUI PGEntry : public PGItem { void setup(PN_stdfloat width, int num_lines); void setup_minimal(PN_stdfloat width, int num_lines); - INLINE bool set_text(const std::string &text); + INLINE bool set_text(std::string_view text); INLINE std::string get_plain_text() const; INLINE std::string get_text() const; @@ -115,11 +115,11 @@ class EXPCL_PANDA_PGUI PGEntry : public PGItem { INLINE bool get_overflow_mode() const; MAKE_PROPERTY(overflow_mode, get_overflow_mode, set_overflow_mode); - INLINE void set_candidate_active(const std::string &candidate_active); + INLINE void set_candidate_active(std::string candidate_active); INLINE const std::string &get_candidate_active() const; MAKE_PROPERTY(candidate_active, get_candidate_active, set_candidate_active); - INLINE void set_candidate_inactive(const std::string &candidate_inactive); + INLINE void set_candidate_inactive(std::string candidate_inactive); INLINE const std::string &get_candidate_inactive() const; MAKE_PROPERTY(candidate_inactive, get_candidate_inactive, set_candidate_inactive); diff --git a/panda/src/pgui/pgItem.I b/panda/src/pgui/pgItem.I index cfbf10f6b0b..d051c80fef7 100644 --- a/panda/src/pgui/pgItem.I +++ b/panda/src/pgui/pgItem.I @@ -15,9 +15,9 @@ * */ INLINE void PGItem:: -set_name(const std::string &name) { - Namable::set_name(name); +set_name(std::string name) { _lock.set_name(name); + Namable::set_name(std::move(name)); } /** @@ -235,9 +235,9 @@ get_id() const { * decide to redefine the ID to be something possibly more meaningful. */ INLINE void PGItem:: -set_id(const std::string &id) { +set_id(std::string id) { LightReMutexHolder holder(_lock); - _region->set_name(id); + _region->set_name(std::move(id)); } /** diff --git a/panda/src/pgui/pgItem.cxx b/panda/src/pgui/pgItem.cxx index d612e889ccb..a9f6de98249 100644 --- a/panda/src/pgui/pgItem.cxx +++ b/panda/src/pgui/pgItem.cxx @@ -56,9 +56,9 @@ is_right(const LVector2 &v1, const LVector2 &v2) { * */ PGItem:: -PGItem(const string &name) : - PandaNode(name), - _lock(name), +PGItem(std::string name) : + PandaNode(std::move(name)), + _lock(get_name()), _notify(nullptr), _has_frame(false), _frame(0, 0, 0, 0), @@ -1031,18 +1031,21 @@ set_frame_style(int state, const PGFrameStyle &style) { * Sets the sound that will be played whenever the indicated event occurs. */ void PGItem:: -set_sound(const string &event, AudioSound *sound) { +set_sound(std::string_view event, AudioSound *sound) { LightReMutexHolder holder(_lock); - _sounds[event] = sound; + _sounds[std::string(event)] = sound; } /** * Removes the sound associated with the indicated event. */ void PGItem:: -clear_sound(const string &event) { +clear_sound(std::string_view event) { LightReMutexHolder holder(_lock); - _sounds.erase(event); + Sounds::iterator si = _sounds.find(event); + if (si != _sounds.end()) { + _sounds.erase(si); + } } /** @@ -1050,7 +1053,7 @@ clear_sound(const string &event) { * no associated sound. */ AudioSound *PGItem:: -get_sound(const string &event) const { +get_sound(std::string_view event) const { LightReMutexHolder holder(_lock); Sounds::const_iterator si = _sounds.find(event); if (si != _sounds.end()) { @@ -1064,7 +1067,7 @@ get_sound(const string &event) const { * false otherwise. */ bool PGItem:: -has_sound(const string &event) const { +has_sound(std::string_view event) const { LightReMutexHolder holder(_lock); return (_sounds.count(event) != 0); } @@ -1092,7 +1095,7 @@ get_text_node() { * Plays the sound associated with the indicated event, if there is one. */ void PGItem:: -play_sound(const string &event) { +play_sound(std::string_view event) { #ifdef HAVE_AUDIO LightReMutexHolder holder(_lock); Sounds::const_iterator si = _sounds.find(event); diff --git a/panda/src/pgui/pgItem.h b/panda/src/pgui/pgItem.h index 048c01f5321..ccc8bb6cba7 100644 --- a/panda/src/pgui/pgItem.h +++ b/panda/src/pgui/pgItem.h @@ -52,10 +52,10 @@ class ScissorAttrib; */ class EXPCL_PANDA_PGUI PGItem : public PandaNode { PUBLISHED: - explicit PGItem(const std::string &name); + explicit PGItem(std::string name); virtual ~PGItem(); - INLINE void set_name(const std::string &name); + INLINE void set_name(std::string name); protected: PGItem(const PGItem ©); @@ -139,7 +139,7 @@ class EXPCL_PANDA_PGUI PGItem : public PandaNode { void set_frame_style(int state, const PGFrameStyle &style); INLINE const std::string &get_id() const; - INLINE void set_id(const std::string &id); + INLINE void set_id(std::string id); MAKE_PROPERTY(name, get_name, set_name); MAKE_PROPERTY2(frame, has_frame, get_frame, set_frame, clear_frame); @@ -186,10 +186,10 @@ class EXPCL_PANDA_PGUI PGItem : public PandaNode { INLINE LMatrix4 get_frame_inv_xform() const; #ifdef HAVE_AUDIO - void set_sound(const std::string &event, AudioSound *sound); - void clear_sound(const std::string &event); - AudioSound *get_sound(const std::string &event) const; - bool has_sound(const std::string &event) const; + void set_sound(std::string_view event, AudioSound *sound); + void clear_sound(std::string_view event); + AudioSound *get_sound(std::string_view event) const; + bool has_sound(std::string_view event) const; #endif static TextNode *get_text_node(); @@ -198,7 +198,7 @@ class EXPCL_PANDA_PGUI PGItem : public PandaNode { INLINE static PGItem *get_focus_item(); protected: - void play_sound(const std::string &event); + void play_sound(std::string_view event); void reduce_region(LVecBase4 &clip, PGItem *obscurer) const; void reduce_region(LVecBase4 &frame, PN_stdfloat px, PN_stdfloat py) const; @@ -253,7 +253,7 @@ class EXPCL_PANDA_PGUI PGItem : public PandaNode { StateDefs _state_defs; #ifdef HAVE_AUDIO - typedef pmap Sounds; + typedef pmap > Sounds; Sounds _sounds; #endif diff --git a/panda/src/pgui/pgScrollFrame.cxx b/panda/src/pgui/pgScrollFrame.cxx index 60920b88f8b..3e50c92bc92 100644 --- a/panda/src/pgui/pgScrollFrame.cxx +++ b/panda/src/pgui/pgScrollFrame.cxx @@ -19,8 +19,8 @@ TypeHandle PGScrollFrame::_type_handle; * */ PGScrollFrame:: -PGScrollFrame(const std::string &name) : - PGVirtualFrame(name), +PGScrollFrame(std::string name) : + PGVirtualFrame(std::move(name)), _needs_remanage(false), _needs_recompute_clip(false), _has_virtual_frame(false), diff --git a/panda/src/pgui/pgScrollFrame.h b/panda/src/pgui/pgScrollFrame.h index c759700ae2e..e4546a57f59 100644 --- a/panda/src/pgui/pgScrollFrame.h +++ b/panda/src/pgui/pgScrollFrame.h @@ -35,7 +35,7 @@ */ class EXPCL_PANDA_PGUI PGScrollFrame : public PGVirtualFrame, public PGSliderBarNotify { PUBLISHED: - explicit PGScrollFrame(const std::string &name = ""); + explicit PGScrollFrame(std::string name = ""); virtual ~PGScrollFrame(); protected: diff --git a/panda/src/pgui/pgSliderBar.cxx b/panda/src/pgui/pgSliderBar.cxx index 7fe5bc8c73c..a082a91fcc6 100644 --- a/panda/src/pgui/pgSliderBar.cxx +++ b/panda/src/pgui/pgSliderBar.cxx @@ -29,8 +29,8 @@ TypeHandle PGSliderBar::_type_handle; * */ PGSliderBar:: -PGSliderBar(const std::string &name) - : PGItem(name) +PGSliderBar(std::string name) + : PGItem(std::move(name)) { set_cull_callback(); diff --git a/panda/src/pgui/pgSliderBar.h b/panda/src/pgui/pgSliderBar.h index 106426148e9..6e670006108 100644 --- a/panda/src/pgui/pgSliderBar.h +++ b/panda/src/pgui/pgSliderBar.h @@ -30,7 +30,7 @@ */ class EXPCL_PANDA_PGUI PGSliderBar : public PGItem, public PGButtonNotify { PUBLISHED: - explicit PGSliderBar(const std::string &name = ""); + explicit PGSliderBar(std::string name = ""); virtual ~PGSliderBar(); protected: diff --git a/panda/src/pgui/pgTop.cxx b/panda/src/pgui/pgTop.cxx index f4d9f31fda4..1451a50b486 100644 --- a/panda/src/pgui/pgTop.cxx +++ b/panda/src/pgui/pgTop.cxx @@ -24,8 +24,8 @@ TypeHandle PGTop::_type_handle; * */ PGTop:: -PGTop(const std::string &name) : - PandaNode(name) +PGTop(std::string name) : + PandaNode(std::move(name)) { set_cull_callback(); diff --git a/panda/src/pgui/pgTop.h b/panda/src/pgui/pgTop.h index d69ab4decc1..ec6998e8994 100644 --- a/panda/src/pgui/pgTop.h +++ b/panda/src/pgui/pgTop.h @@ -37,7 +37,7 @@ class PGMouseWatcherGroup; */ class EXPCL_PANDA_PGUI PGTop : public PandaNode { PUBLISHED: - explicit PGTop(const std::string &name); + explicit PGTop(std::string name); virtual ~PGTop(); protected: diff --git a/panda/src/pgui/pgVirtualFrame.cxx b/panda/src/pgui/pgVirtualFrame.cxx index 01013fd87f5..f4edd15206e 100644 --- a/panda/src/pgui/pgVirtualFrame.cxx +++ b/panda/src/pgui/pgVirtualFrame.cxx @@ -21,7 +21,7 @@ TypeHandle PGVirtualFrame::_type_handle; * */ PGVirtualFrame:: -PGVirtualFrame(const std::string &name) : PGItem(name) +PGVirtualFrame(std::string name) : PGItem(std::move(name)) { _has_clip_frame = false; _clip_frame.set(0.0f, 0.0f, 0.0f, 0.0f); diff --git a/panda/src/pgui/pgVirtualFrame.h b/panda/src/pgui/pgVirtualFrame.h index 7480a6fc926..f84f167b486 100644 --- a/panda/src/pgui/pgVirtualFrame.h +++ b/panda/src/pgui/pgVirtualFrame.h @@ -42,7 +42,7 @@ class TransformState; */ class EXPCL_PANDA_PGUI PGVirtualFrame : public PGItem { PUBLISHED: - explicit PGVirtualFrame(const std::string &name = ""); + explicit PGVirtualFrame(std::string name = ""); virtual ~PGVirtualFrame(); protected: diff --git a/panda/src/pgui/pgWaitBar.cxx b/panda/src/pgui/pgWaitBar.cxx index 8348b692dcc..f83a93f9c10 100644 --- a/panda/src/pgui/pgWaitBar.cxx +++ b/panda/src/pgui/pgWaitBar.cxx @@ -22,7 +22,7 @@ TypeHandle PGWaitBar::_type_handle; * */ PGWaitBar:: -PGWaitBar(const std::string &name) : PGItem(name) +PGWaitBar(std::string name) : PGItem(std::move(name)) { set_cull_callback(); @@ -147,7 +147,7 @@ update() { // And scale the bar according to our value. PN_stdfloat frac = _value / _range; - frac = std::max(std::min(frac, (PN_stdfloat)1.0), (PN_stdfloat)0.0); + frac = std::clamp(frac, (PN_stdfloat)0.0, (PN_stdfloat)1.0); bar_frame[1] = bar_frame[0] + frac * (bar_frame[1] - bar_frame[0]); _bar = _bar_style.generate_into(root, bar_frame, 1); diff --git a/panda/src/pgui/pgWaitBar.h b/panda/src/pgui/pgWaitBar.h index 34480adba75..a0f70e35ac5 100644 --- a/panda/src/pgui/pgWaitBar.h +++ b/panda/src/pgui/pgWaitBar.h @@ -25,7 +25,7 @@ */ class EXPCL_PANDA_PGUI PGWaitBar : public PGItem { PUBLISHED: - explicit PGWaitBar(const std::string &name = ""); + explicit PGWaitBar(std::string name = ""); virtual ~PGWaitBar(); protected: diff --git a/panda/src/physics/actorNode.cxx b/panda/src/physics/actorNode.cxx index ac9a03a69dd..d50580ea1f7 100644 --- a/panda/src/physics/actorNode.cxx +++ b/panda/src/physics/actorNode.cxx @@ -23,14 +23,14 @@ TypeHandle ActorNode::_type_handle; * Constructor */ ActorNode:: -ActorNode(const std::string &name) : - PhysicalNode(name) { +ActorNode(std::string name) : + PhysicalNode(std::move(name)) { _contact_vector = LVector3::zero(); add_physical(new Physical(1, true)); _mass_center = get_physical(0)->get_phys_body(); _mass_center->set_active(true); #ifndef NDEBUG - _mass_center->set_name(name); + _mass_center->set_name(get_name()); #endif _ok_to_callback = true; _transform_limit = 0.0; diff --git a/panda/src/physics/actorNode.h b/panda/src/physics/actorNode.h index 719b6b16f95..4ffffae4493 100644 --- a/panda/src/physics/actorNode.h +++ b/panda/src/physics/actorNode.h @@ -25,7 +25,7 @@ */ class EXPCL_PANDA_PHYSICS ActorNode : public PhysicalNode { PUBLISHED: - explicit ActorNode(const std::string &name = ""); + explicit ActorNode(std::string name = ""); ActorNode(const ActorNode ©); virtual ~ActorNode(); diff --git a/panda/src/physics/forceNode.cxx b/panda/src/physics/forceNode.cxx index c8f744f777f..faadf8092a3 100644 --- a/panda/src/physics/forceNode.cxx +++ b/panda/src/physics/forceNode.cxx @@ -20,8 +20,8 @@ TypeHandle ForceNode::_type_handle; * default constructor */ ForceNode:: -ForceNode(const std::string &name) : - PandaNode(name) { +ForceNode(std::string name) : + PandaNode(std::move(name)) { } /** diff --git a/panda/src/physics/forceNode.h b/panda/src/physics/forceNode.h index 0f7758199d5..1cb11143712 100644 --- a/panda/src/physics/forceNode.h +++ b/panda/src/physics/forceNode.h @@ -26,7 +26,7 @@ */ class EXPCL_PANDA_PHYSICS ForceNode : public PandaNode { PUBLISHED: - explicit ForceNode(const std::string &name); + explicit ForceNode(std::string name); INLINE void clear(); INLINE BaseForce *get_force(size_t index) const; INLINE size_t get_num_forces() const; diff --git a/panda/src/physics/physicalNode.cxx b/panda/src/physics/physicalNode.cxx index dee169bfe57..5035247873f 100644 --- a/panda/src/physics/physicalNode.cxx +++ b/panda/src/physics/physicalNode.cxx @@ -24,8 +24,8 @@ TypeHandle PhysicalNode::_type_handle; * default constructor */ PhysicalNode:: -PhysicalNode(const std::string &name) : - PandaNode(name) +PhysicalNode(std::string name) : + PandaNode(std::move(name)) { } diff --git a/panda/src/physics/physicalNode.h b/panda/src/physics/physicalNode.h index 5948f50455d..8313f0df6de 100644 --- a/panda/src/physics/physicalNode.h +++ b/panda/src/physics/physicalNode.h @@ -29,7 +29,7 @@ */ class EXPCL_PANDA_PHYSICS PhysicalNode : public PandaNode { PUBLISHED: - explicit PhysicalNode(const std::string &name); + explicit PhysicalNode(std::string name); INLINE void clear(); INLINE Physical *get_physical(size_t index) const; INLINE size_t get_num_physicals() const; diff --git a/panda/src/physics/physicsObject.h b/panda/src/physics/physicsObject.h index 851430b1c56..ff53da18e33 100644 --- a/panda/src/physics/physicsObject.h +++ b/panda/src/physics/physicsObject.h @@ -85,11 +85,11 @@ class EXPCL_PANDA_PHYSICS PhysicsObject : public TypedReferenceCount { virtual LMatrix4 get_inertial_tensor() const; virtual LMatrix4 get_lcs() const; - virtual PhysicsObject *make_copy() const; + [[nodiscard]] virtual PhysicsObject *make_copy() const; #if !defined(NDEBUG) || !defined(CPPPARSER) - void set_name(const std::string &name) { - _name = name; + void set_name(std::string name) { + _name = std::move(name); } const std::string &get_name() { return _name; diff --git a/panda/src/pipeline/externalThread.cxx b/panda/src/pipeline/externalThread.cxx index d77fc194ea7..ffa2af70233 100644 --- a/panda/src/pipeline/externalThread.cxx +++ b/panda/src/pipeline/externalThread.cxx @@ -31,8 +31,8 @@ ExternalThread() : Thread("External", "External") { * external thread that is bound via Thread::bind_thread(). */ ExternalThread:: -ExternalThread(const std::string &name, const std::string &sync_name) : - Thread(name, sync_name) +ExternalThread(std::string name, std::string sync_name) : + Thread(std::move(name), std::move(sync_name)) { _started = true; } diff --git a/panda/src/pipeline/externalThread.h b/panda/src/pipeline/externalThread.h index 0b6add95b17..627ecbeb50d 100644 --- a/panda/src/pipeline/externalThread.h +++ b/panda/src/pipeline/externalThread.h @@ -24,7 +24,7 @@ class EXPCL_PANDA_PIPELINE ExternalThread : public Thread { private: ExternalThread(); - ExternalThread(const std::string &name, const std::string &sync_name); + ExternalThread(std::string name, std::string sync_name); virtual void thread_main(); PUBLISHED: diff --git a/panda/src/pipeline/genericThread.cxx b/panda/src/pipeline/genericThread.cxx index 3d5248667f1..711f4fcbe44 100644 --- a/panda/src/pipeline/genericThread.cxx +++ b/panda/src/pipeline/genericThread.cxx @@ -22,8 +22,8 @@ TypeHandle GenericThread::_type_handle; * */ GenericThread:: -GenericThread(const std::string &name, const std::string &sync_name) : - Thread(name, sync_name) +GenericThread(std::string name, std::string sync_name) : + Thread(std::move(name), std::move(sync_name)) { } @@ -31,8 +31,8 @@ GenericThread(const std::string &name, const std::string &sync_name) : * */ GenericThread:: -GenericThread(const std::string &name, const std::string &sync_name, GenericThread::ThreadFunc *function, void *user_data) : - Thread(name, sync_name), +GenericThread(std::string name, std::string sync_name, GenericThread::ThreadFunc *function, void *user_data) : + Thread(std::move(name), std::move(sync_name)), _function(std::bind(function, user_data)) { } @@ -41,8 +41,8 @@ GenericThread(const std::string &name, const std::string &sync_name, GenericThre * */ GenericThread:: -GenericThread(const std::string &name, const std::string &sync_name, std::function function) : - Thread(name, sync_name), +GenericThread(std::string name, std::string sync_name, std::function function) : + Thread(std::move(name), std::move(sync_name)), _function(std::move(function)) { } diff --git a/panda/src/pipeline/genericThread.h b/panda/src/pipeline/genericThread.h index b13185af1dc..41ee6bfcb94 100644 --- a/panda/src/pipeline/genericThread.h +++ b/panda/src/pipeline/genericThread.h @@ -28,9 +28,9 @@ class EXPCL_PANDA_PIPELINE GenericThread : public Thread { public: typedef void ThreadFunc(void *user_data); - GenericThread(const std::string &name, const std::string &sync_name); - GenericThread(const std::string &name, const std::string &sync_name, ThreadFunc *function, void *user_data); - GenericThread(const std::string &name, const std::string &sync_name, std::function function); + GenericThread(std::string name, std::string sync_name); + GenericThread(std::string name, std::string sync_name, ThreadFunc *function, void *user_data); + GenericThread(std::string name, std::string sync_name, std::function function); INLINE void set_function(std::function function); INLINE const std::function &get_function() const; diff --git a/panda/src/pipeline/lightMutex.I b/panda/src/pipeline/lightMutex.I index b76b743e346..63e569940de 100644 --- a/panda/src/pipeline/lightMutex.I +++ b/panda/src/pipeline/lightMutex.I @@ -28,21 +28,9 @@ LightMutex() */ INLINE LightMutex:: #ifdef DEBUG_THREADS -LightMutex(const char *name) : MutexDebug(std::string(name), false, true) +LightMutex(std::string_view name) : MutexDebug(name, false, true) #else -LightMutex(const char *) -#endif // DEBUG_THREADS -{ -} - -/** - * - */ -INLINE LightMutex:: -#ifdef DEBUG_THREADS -LightMutex(const std::string &name) : MutexDebug(name, false, true) -#else -LightMutex(const std::string &) +LightMutex(std::string_view) #endif // DEBUG_THREADS { } diff --git a/panda/src/pipeline/lightMutex.h b/panda/src/pipeline/lightMutex.h index 4d8ae9a7853..9597f0faf5b 100644 --- a/panda/src/pipeline/lightMutex.h +++ b/panda/src/pipeline/lightMutex.h @@ -41,10 +41,7 @@ class EXPCL_PANDA_PIPELINE LightMutex : public LightMutexDirect { PUBLISHED: INLINE LightMutex(); -public: - INLINE explicit LightMutex(const char *name); -PUBLISHED: - INLINE explicit LightMutex(const std::string &name); + INLINE explicit LightMutex(std::string_view name); LightMutex(const LightMutex ©) = delete; ~LightMutex() = default; diff --git a/panda/src/pipeline/lightMutexDirect.h b/panda/src/pipeline/lightMutexDirect.h index e72bd808fec..2bf2450ecb2 100644 --- a/panda/src/pipeline/lightMutexDirect.h +++ b/panda/src/pipeline/lightMutexDirect.h @@ -38,7 +38,7 @@ class EXPCL_PANDA_PIPELINE LightMutexDirect { public: INLINE void lock(); - INLINE bool try_lock(); + [[nodiscard]] INLINE bool try_lock(); INLINE void unlock(); PUBLISHED: diff --git a/panda/src/pipeline/lightReMutex.I b/panda/src/pipeline/lightReMutex.I index bc27a5a7118..e000dd986dc 100644 --- a/panda/src/pipeline/lightReMutex.I +++ b/panda/src/pipeline/lightReMutex.I @@ -28,21 +28,9 @@ LightReMutex() */ INLINE LightReMutex:: #ifdef DEBUG_THREADS -LightReMutex(const char *name) : MutexDebug(std::string(name), true, true) +LightReMutex(std::string_view name) : MutexDebug(name, true, true) #else -LightReMutex(const char *) -#endif // DEBUG_THREADS -{ -} - -/** - * - */ -INLINE LightReMutex:: -#ifdef DEBUG_THREADS -LightReMutex(const std::string &name) : MutexDebug(name, true, true) -#else -LightReMutex(const std::string &) +LightReMutex(std::string_view) #endif // DEBUG_THREADS { } diff --git a/panda/src/pipeline/lightReMutex.h b/panda/src/pipeline/lightReMutex.h index b219d7d10cd..a0fc309e8f8 100644 --- a/panda/src/pipeline/lightReMutex.h +++ b/panda/src/pipeline/lightReMutex.h @@ -32,10 +32,7 @@ class EXPCL_PANDA_PIPELINE LightReMutex : public LightReMutexDirect { PUBLISHED: INLINE LightReMutex(); -public: - INLINE explicit LightReMutex(const char *name); -PUBLISHED: - INLINE explicit LightReMutex(const std::string &name); + INLINE explicit LightReMutex(std::string_view name); LightReMutex(const LightReMutex ©) = delete; ~LightReMutex() = default; diff --git a/panda/src/pipeline/lightReMutexDirect.h b/panda/src/pipeline/lightReMutexDirect.h index 384330587e8..4387bea4677 100644 --- a/panda/src/pipeline/lightReMutexDirect.h +++ b/panda/src/pipeline/lightReMutexDirect.h @@ -36,7 +36,7 @@ class EXPCL_PANDA_PIPELINE LightReMutexDirect { public: INLINE void lock(); - INLINE bool try_lock(); + [[nodiscard]] INLINE bool try_lock(); INLINE void unlock(); PUBLISHED: diff --git a/panda/src/pipeline/mutexDebug.cxx b/panda/src/pipeline/mutexDebug.cxx index d1e0194e6f9..1349adbbdef 100644 --- a/panda/src/pipeline/mutexDebug.cxx +++ b/panda/src/pipeline/mutexDebug.cxx @@ -27,8 +27,8 @@ MutexTrueImpl *MutexDebug::_global_lock; * */ MutexDebug:: -MutexDebug(const std::string &name, bool allow_recursion, bool lightweight) : - Namable(name), +MutexDebug(std::string_view name, bool allow_recursion, bool lightweight) : + Namable(std::string(name)), _allow_recursion(allow_recursion), _lightweight(lightweight), _locking_thread(nullptr), diff --git a/panda/src/pipeline/mutexDebug.h b/panda/src/pipeline/mutexDebug.h index 298fd9f7ca3..2b1d6334909 100644 --- a/panda/src/pipeline/mutexDebug.h +++ b/panda/src/pipeline/mutexDebug.h @@ -29,7 +29,7 @@ */ class EXPCL_PANDA_PIPELINE MutexDebug : public Namable { protected: - MutexDebug(const std::string &name, bool allow_recursion, bool lightweight); + MutexDebug(std::string_view name, bool allow_recursion, bool lightweight); MutexDebug(const MutexDebug ©) = delete; virtual ~MutexDebug(); @@ -37,12 +37,12 @@ class EXPCL_PANDA_PIPELINE MutexDebug : public Namable { public: INLINE void lock(); - INLINE bool try_lock(); + [[nodiscard]] INLINE bool try_lock(); INLINE void unlock(); PUBLISHED: BLOCKING INLINE void acquire(Thread *current_thread = Thread::get_current_thread()) const; - BLOCKING INLINE bool try_acquire(Thread *current_thread = Thread::get_current_thread()) const; + [[nodiscard]] BLOCKING INLINE bool try_acquire(Thread *current_thread = Thread::get_current_thread()) const; INLINE void elevate_lock() const; INLINE void release() const; INLINE bool debug_is_locked() const; diff --git a/panda/src/pipeline/mutexDirect.h b/panda/src/pipeline/mutexDirect.h index 9e578abd52a..8152049e4cc 100644 --- a/panda/src/pipeline/mutexDirect.h +++ b/panda/src/pipeline/mutexDirect.h @@ -37,12 +37,12 @@ class EXPCL_PANDA_PIPELINE MutexDirect { public: INLINE void lock(); - INLINE bool try_lock(); + [[nodiscard]] INLINE bool try_lock(); INLINE void unlock(); PUBLISHED: BLOCKING INLINE void acquire() const; - BLOCKING INLINE bool try_acquire() const; + [[nodiscard]] BLOCKING INLINE bool try_acquire() const; INLINE void release() const; INLINE bool debug_is_locked() const; diff --git a/panda/src/pipeline/mutexSimpleImpl.h b/panda/src/pipeline/mutexSimpleImpl.h index 3c194a08f1d..f0c004149fa 100644 --- a/panda/src/pipeline/mutexSimpleImpl.h +++ b/panda/src/pipeline/mutexSimpleImpl.h @@ -39,7 +39,7 @@ class EXPCL_PANDA_PIPELINE MutexSimpleImpl : public BlockerSimple { constexpr MutexSimpleImpl() = default; INLINE void lock(); - INLINE bool try_lock(); + [[nodiscard]] INLINE bool try_lock(); INLINE void unlock(); INLINE void unlock_quietly(); diff --git a/panda/src/pipeline/pipeline.cxx b/panda/src/pipeline/pipeline.cxx index e892a88ee75..f0aefde4ae1 100644 --- a/panda/src/pipeline/pipeline.cxx +++ b/panda/src/pipeline/pipeline.cxx @@ -22,8 +22,8 @@ Pipeline *Pipeline::_render_pipeline = nullptr; * */ Pipeline:: -Pipeline(const std::string &name, int num_stages) : - Namable(name), +Pipeline(std::string name, int num_stages) : + Namable(std::move(name)), #ifdef THREADED_PIPELINE _num_stages(num_stages), _next_cycle_seq(1), diff --git a/panda/src/pipeline/pipeline.h b/panda/src/pipeline/pipeline.h index 10fec52b609..09b292b72f9 100644 --- a/panda/src/pipeline/pipeline.h +++ b/panda/src/pipeline/pipeline.h @@ -37,7 +37,7 @@ struct PipelineCyclerTrueImpl; */ class EXPCL_PANDA_PIPELINE Pipeline : public Namable { public: - Pipeline(const std::string &name, int num_stages); + Pipeline(std::string name, int num_stages); ~Pipeline(); INLINE static Pipeline *get_render_pipeline(); diff --git a/panda/src/pipeline/pmutex.I b/panda/src/pipeline/pmutex.I index e148ce22e3f..3b4694d26ed 100644 --- a/panda/src/pipeline/pmutex.I +++ b/panda/src/pipeline/pmutex.I @@ -28,21 +28,9 @@ Mutex() */ INLINE Mutex:: #ifdef DEBUG_THREADS -Mutex(const char *name) : MutexDebug(std::string(name), false, false) +Mutex(std::string_view name) : MutexDebug(name, false, false) #else -Mutex(const char *) -#endif // DEBUG_THREADS -{ -} - -/** - * - */ -INLINE Mutex:: -#ifdef DEBUG_THREADS -Mutex(const std::string &name) : MutexDebug(name, false, false) -#else -Mutex(const std::string &) +Mutex(std::string_view) #endif // DEBUG_THREADS { } diff --git a/panda/src/pipeline/pmutex.h b/panda/src/pipeline/pmutex.h index 539245073c6..18c12e8fee1 100644 --- a/panda/src/pipeline/pmutex.h +++ b/panda/src/pipeline/pmutex.h @@ -40,10 +40,7 @@ class EXPCL_PANDA_PIPELINE Mutex : public MutexDirect { PUBLISHED: INLINE Mutex(); -public: - INLINE Mutex(const char *name); -PUBLISHED: - INLINE explicit Mutex(const std::string &name); + INLINE explicit Mutex(std::string_view name); Mutex(const Mutex ©) = delete; ~Mutex() = default; diff --git a/panda/src/pipeline/psemaphore.h b/panda/src/pipeline/psemaphore.h index 306992b5d9f..6fb62058daa 100644 --- a/panda/src/pipeline/psemaphore.h +++ b/panda/src/pipeline/psemaphore.h @@ -37,7 +37,7 @@ class EXPCL_PANDA_PIPELINE Semaphore { PUBLISHED: BLOCKING INLINE void acquire(); - BLOCKING INLINE bool try_acquire(); + [[nodiscard]] BLOCKING INLINE bool try_acquire(); INLINE int release(); INLINE int get_count() const; diff --git a/panda/src/pipeline/pythonThread.cxx b/panda/src/pipeline/pythonThread.cxx index eff5728aafe..1a00f6f7296 100644 --- a/panda/src/pipeline/pythonThread.cxx +++ b/panda/src/pipeline/pythonThread.cxx @@ -24,8 +24,8 @@ TypeHandle PythonThread::_type_handle; */ PythonThread:: PythonThread(PyObject *function, PyObject *args, - const std::string &name, const std::string &sync_name) : - Thread(name, sync_name) + std::string name, std::string sync_name) : + Thread(std::move(name), std::move(sync_name)) { _function = Py_NewRef(function); _args = nullptr; diff --git a/panda/src/pipeline/pythonThread.h b/panda/src/pipeline/pythonThread.h index f9bf6c91e97..2106741fd6b 100644 --- a/panda/src/pipeline/pythonThread.h +++ b/panda/src/pipeline/pythonThread.h @@ -27,7 +27,7 @@ class PythonThread : public Thread { PUBLISHED: explicit PythonThread(PyObject *function, PyObject *args, - const std::string &name, const std::string &sync_name); + std::string name, std::string sync_name); virtual ~PythonThread(); BLOCKING PyObject *join(); diff --git a/panda/src/pipeline/reMutex.I b/panda/src/pipeline/reMutex.I index af2ea3d59ca..81ae7207be2 100644 --- a/panda/src/pipeline/reMutex.I +++ b/panda/src/pipeline/reMutex.I @@ -28,21 +28,9 @@ ReMutex() */ INLINE ReMutex:: #ifdef DEBUG_THREADS -ReMutex(const char *name) : MutexDebug(std::string(name), true, false) +ReMutex(std::string_view name) : MutexDebug(name, true, false) #else -ReMutex(const char *) -#endif // DEBUG_THREADS -{ -} - -/** - * - */ -INLINE ReMutex:: -#ifdef DEBUG_THREADS -ReMutex(const std::string &name) : MutexDebug(name, true, false) -#else -ReMutex(const std::string &) +ReMutex(std::string_view) #endif // DEBUG_THREADS { } diff --git a/panda/src/pipeline/reMutex.h b/panda/src/pipeline/reMutex.h index f5096268186..9522d7280b2 100644 --- a/panda/src/pipeline/reMutex.h +++ b/panda/src/pipeline/reMutex.h @@ -34,10 +34,7 @@ class EXPCL_PANDA_PIPELINE ReMutex : public ReMutexDirect { PUBLISHED: INLINE ReMutex(); -public: - INLINE explicit ReMutex(const char *name); -PUBLISHED: - INLINE explicit ReMutex(const std::string &name); + INLINE explicit ReMutex(std::string_view name); ReMutex(const ReMutex ©) = delete; ~ReMutex() = default; diff --git a/panda/src/pipeline/reMutexDirect.h b/panda/src/pipeline/reMutexDirect.h index 9a82b728bae..142dbda764d 100644 --- a/panda/src/pipeline/reMutexDirect.h +++ b/panda/src/pipeline/reMutexDirect.h @@ -36,14 +36,14 @@ class EXPCL_PANDA_PIPELINE ReMutexDirect { public: INLINE void lock(); - INLINE bool try_lock(); + [[nodiscard]] INLINE bool try_lock(); INLINE void unlock(); PUBLISHED: BLOCKING INLINE void acquire() const; BLOCKING INLINE void acquire(Thread *current_thread) const; - BLOCKING INLINE bool try_acquire() const; - BLOCKING INLINE bool try_acquire(Thread *current_thread) const; + [[nodiscard]] BLOCKING INLINE bool try_acquire() const; + [[nodiscard]] BLOCKING INLINE bool try_acquire(Thread *current_thread) const; INLINE void elevate_lock() const; INLINE void release() const; diff --git a/panda/src/pipeline/reMutexSpinlockImpl.h b/panda/src/pipeline/reMutexSpinlockImpl.h index 761159481b8..04a3a54a209 100644 --- a/panda/src/pipeline/reMutexSpinlockImpl.h +++ b/panda/src/pipeline/reMutexSpinlockImpl.h @@ -38,7 +38,7 @@ class EXPCL_PANDA_PIPELINE ReMutexSpinlockImpl { public: void lock(); - bool try_lock(); + [[nodiscard]] bool try_lock(); INLINE void unlock(); private: diff --git a/panda/src/pipeline/thread.cxx b/panda/src/pipeline/thread.cxx index 706eae2a750..3d4f4605d38 100644 --- a/panda/src/pipeline/thread.cxx +++ b/panda/src/pipeline/thread.cxx @@ -38,9 +38,9 @@ void (*Thread::_yield_func)() = &ThreadImpl::yield; * given the same sync_name, for the benefit of PStats. */ Thread:: -Thread(const std::string &name, const std::string &sync_name) : - Namable(name), - _sync_name(sync_name), +Thread(std::string name, std::string sync_name) : + Namable(std::move(name)), + _sync_name(std::move(sync_name)), _impl(this) { _started = false; diff --git a/panda/src/pipeline/thread.h b/panda/src/pipeline/thread.h index fcd4aea59e5..297677ff2da 100644 --- a/panda/src/pipeline/thread.h +++ b/panda/src/pipeline/thread.h @@ -46,7 +46,7 @@ class AsyncTask; // Due to a GCC bug, we can't use alignas() together with an attribute. class ALIGN_64BYTE EXPCL_PANDA_PIPELINE Thread : public TypedReferenceCount, public Namable { protected: - Thread(const std::string &name, const std::string &sync_name); + Thread(std::string name, std::string sync_name); Thread(const Thread ©) = delete; PUBLISHED: diff --git a/panda/src/pnmimage/pnmFileType.cxx b/panda/src/pnmimage/pnmFileType.cxx index af9cf89f4ad..bed7473ad15 100644 --- a/panda/src/pnmimage/pnmFileType.cxx +++ b/panda/src/pnmimage/pnmFileType.cxx @@ -82,7 +82,7 @@ has_magic_number() const { * otherwise. */ bool PNMFileType:: -matches_magic_number(const string &) const { +matches_magic_number(std::string_view) const { return false; } @@ -92,7 +92,7 @@ matches_magic_number(const string &) const { * returns NULL. */ PNMReader *PNMFileType:: -make_reader(std::istream *, bool, const string &) { +make_reader(std::istream *, bool, std::string_view) { return nullptr; } diff --git a/panda/src/pnmimage/pnmFileType.h b/panda/src/pnmimage/pnmFileType.h index 93e409390fd..72607e8c38d 100644 --- a/panda/src/pnmimage/pnmFileType.h +++ b/panda/src/pnmimage/pnmFileType.h @@ -50,10 +50,10 @@ class EXPCL_PANDA_PNMIMAGE PNMFileType : public TypedWritable { public: virtual bool has_magic_number() const; - virtual bool matches_magic_number(const std::string &magic_number) const; + virtual bool matches_magic_number(std::string_view magic_number) const; virtual PNMReader *make_reader(std::istream *file, bool owns_file = true, - const std::string &magic_number = std::string()); + std::string_view magic_number = std::string_view()); virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true); // The TypedWritable interface follows. diff --git a/panda/src/pnmimage/pnmFileTypeRegistry.cxx b/panda/src/pnmimage/pnmFileTypeRegistry.cxx index d290f52bdc4..92b716d3c24 100644 --- a/panda/src/pnmimage/pnmFileTypeRegistry.cxx +++ b/panda/src/pnmimage/pnmFileTypeRegistry.cxx @@ -144,7 +144,7 @@ get_type(int n) const { * or NULL if no type can be determined. */ PNMFileType *PNMFileTypeRegistry:: -get_type_from_extension(const string &filename) const { +get_type_from_extension(std::string_view filename) const { if (_requires_sort) { ((PNMFileTypeRegistry *)this)->sort_preferences(); } @@ -207,7 +207,7 @@ get_type_from_extension(const string &filename) const { * determined. */ PNMFileType *PNMFileTypeRegistry:: -get_type_from_magic_number(const string &magic_number) const { +get_type_from_magic_number(std::string_view magic_number) const { if (_requires_sort) { ((PNMFileTypeRegistry *)this)->sort_preferences(); } diff --git a/panda/src/pnmimage/pnmFileTypeRegistry.h b/panda/src/pnmimage/pnmFileTypeRegistry.h index ae4c6a76881..a80fb754bed 100644 --- a/panda/src/pnmimage/pnmFileTypeRegistry.h +++ b/panda/src/pnmimage/pnmFileTypeRegistry.h @@ -41,8 +41,8 @@ class EXPCL_PANDA_PNMIMAGE PNMFileTypeRegistry { MAKE_SEQ(get_types, get_num_types, get_type); MAKE_SEQ_PROPERTY(types, get_num_types, get_type); - PNMFileType *get_type_from_extension(const std::string &filename) const; - PNMFileType *get_type_from_magic_number(const std::string &magic_number) const; + PNMFileType *get_type_from_extension(std::string_view filename) const; + PNMFileType *get_type_from_magic_number(std::string_view magic_number) const; PNMFileType *get_type_by_handle(TypeHandle handle) const; void write(std::ostream &out, int indent_level = 0) const; @@ -55,7 +55,7 @@ class EXPCL_PANDA_PNMIMAGE PNMFileTypeRegistry { typedef pvector Types; Types _types; - typedef pmap Extensions; + typedef pmap> Extensions; Extensions _extensions; typedef pmap Handles; diff --git a/panda/src/pnmimage/pnmImage.cxx b/panda/src/pnmimage/pnmImage.cxx index c50193e137c..222f6c7b825 100644 --- a/panda/src/pnmimage/pnmImage.cxx +++ b/panda/src/pnmimage/pnmImage.cxx @@ -303,7 +303,7 @@ read(const Filename &filename, PNMFileType *type, bool report_unknown_type) { * Returns true if successful, false on error. */ bool PNMImage:: -read(std::istream &data, const std::string &filename, PNMFileType *type, +read(std::istream &data, std::string_view filename, PNMFileType *type, bool report_unknown_type) { PNMReader *reader = PNMImageHeader::make_reader (&data, false, filename, std::string(), type, report_unknown_type); @@ -412,7 +412,7 @@ write(const Filename &filename, PNMFileType *type) const { * write. */ bool PNMImage:: -write(std::ostream &data, const std::string &filename, PNMFileType *type) const { +write(std::ostream &data, std::string_view filename, PNMFileType *type) const { if (!is_valid()) { return false; } @@ -598,9 +598,9 @@ set_color_space(ColorSpace color_space) { for (int y = 0; y < _y_size; ++y) { LRGBColorf scaled = get_xel(x, y) * 8192.f + 4096.5f; xel &col = row(y)[x]; - col.r = min(max(0, (int)scaled[0]), 65535); - col.g = min(max(0, (int)scaled[1]), 65535); - col.b = min(max(0, (int)scaled[2]), 65535); + col.r = std::clamp((int)scaled[0], 0, 65535); + col.g = std::clamp((int)scaled[1], 0, 65535); + col.b = std::clamp((int)scaled[2], 0, 65535); } } _maxval = 65535; diff --git a/panda/src/pnmimage/pnmImage.h b/panda/src/pnmimage/pnmImage.h index 5e2599f3254..02e10b3301a 100644 --- a/panda/src/pnmimage/pnmImage.h +++ b/panda/src/pnmimage/pnmImage.h @@ -104,13 +104,13 @@ class EXPCL_PANDA_PNMIMAGE PNMImage : public PNMImageHeader { BLOCKING bool read(const Filename &filename, PNMFileType *type = nullptr, bool report_unknown_type = true); - BLOCKING bool read(std::istream &data, const std::string &filename = std::string(), + BLOCKING bool read(std::istream &data, std::string_view filename = std::string_view(), PNMFileType *type = nullptr, bool report_unknown_type = true); BLOCKING bool read(PNMReader *reader); BLOCKING bool write(const Filename &filename, PNMFileType *type = nullptr) const; - BLOCKING bool write(std::ostream &data, const std::string &filename = std::string(), + BLOCKING bool write(std::ostream &data, std::string_view filename = std::string_view(), PNMFileType *type = nullptr) const; BLOCKING bool write(PNMWriter *writer) const; diff --git a/panda/src/pnmimage/pnmImageHeader.I b/panda/src/pnmimage/pnmImageHeader.I index 630e41ff2a2..2ecc88f7844 100644 --- a/panda/src/pnmimage/pnmImageHeader.I +++ b/panda/src/pnmimage/pnmImageHeader.I @@ -175,8 +175,8 @@ get_comment() const { * Writes a user comment string to the image (header). */ INLINE void PNMImageHeader:: -set_comment(const std::string& comment) { - _comment = comment; +set_comment(std::string comment) { + _comment = std::move(comment); } /** diff --git a/panda/src/pnmimage/pnmImageHeader.cxx b/panda/src/pnmimage/pnmImageHeader.cxx index 0eae5285cca..8f22f14bbf2 100644 --- a/panda/src/pnmimage/pnmImageHeader.cxx +++ b/panda/src/pnmimage/pnmImageHeader.cxx @@ -81,7 +81,7 @@ read_header(const Filename &filename, PNMFileType *type, * Returns true if successful, false on error. */ bool PNMImageHeader:: -read_header(istream &data, const string &filename, PNMFileType *type, +read_header(istream &data, std::string_view filename, PNMFileType *type, bool report_unknown_type) { PNMReader *reader = PNMImageHeader::make_reader (&data, false, filename, string(), type, report_unknown_type); diff --git a/panda/src/pnmimage/pnmImageHeader.h b/panda/src/pnmimage/pnmImageHeader.h index ce2a624aa55..799be36dab4 100644 --- a/panda/src/pnmimage/pnmImageHeader.h +++ b/panda/src/pnmimage/pnmImageHeader.h @@ -77,7 +77,7 @@ class EXPCL_PANDA_PNMIMAGE PNMImageHeader : public MemoryBase { MAKE_PROPERTY(size, get_size); INLINE std::string get_comment() const; - INLINE void set_comment(const std::string &comment); + INLINE void set_comment(std::string comment); MAKE_PROPERTY(comment, get_comment, set_comment); INLINE bool has_type() const; @@ -87,7 +87,7 @@ class EXPCL_PANDA_PNMIMAGE PNMImageHeader : public MemoryBase { BLOCKING bool read_header(const Filename &filename, PNMFileType *type = nullptr, bool report_unknown_type = true); - BLOCKING bool read_header(std::istream &data, const std::string &filename = std::string(), + BLOCKING bool read_header(std::istream &data, std::string_view filename = std::string_view(), PNMFileType *type = nullptr, bool report_unknown_type = true); PNMReader *make_reader(const Filename &filename, diff --git a/panda/src/pnmimagetypes/pnmFileTypeBMP.cxx b/panda/src/pnmimagetypes/pnmFileTypeBMP.cxx index 13baa23d1f9..34024e16a74 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeBMP.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeBMP.cxx @@ -87,7 +87,7 @@ has_magic_number() const { * otherwise. */ bool PNMFileTypeBMP:: -matches_magic_number(const string &magic_number) const { +matches_magic_number(std::string_view magic_number) const { nassertr(magic_number.size() >= 2, false); return (magic_number.substr(0, 2) == "BM"); } @@ -98,8 +98,8 @@ matches_magic_number(const string &magic_number) const { * returns NULL. */ PNMReader *PNMFileTypeBMP:: -make_reader(std::istream *file, bool owns_file, const string &magic_number) { - return new Reader(this, file, owns_file, magic_number); +make_reader(std::istream *file, bool owns_file, std::string_view magic_number) { + return new Reader(this, file, owns_file, std::string(magic_number)); } /** diff --git a/panda/src/pnmimagetypes/pnmFileTypeBMP.h b/panda/src/pnmimagetypes/pnmFileTypeBMP.h index 8de56662089..ec461cbe6dc 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeBMP.h +++ b/panda/src/pnmimagetypes/pnmFileTypeBMP.h @@ -36,10 +36,10 @@ class PNMFileTypeBMP : public PNMFileType { virtual std::string get_suggested_extension() const; virtual bool has_magic_number() const; - virtual bool matches_magic_number(const std::string &magic_number) const; + virtual bool matches_magic_number(std::string_view magic_number) const; virtual PNMReader *make_reader(std::istream *file, bool owns_file = true, - const std::string &magic_number = std::string()); + std::string_view magic_number = std::string_view()); virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true); public: diff --git a/panda/src/pnmimagetypes/pnmFileTypeEXR.cxx b/panda/src/pnmimagetypes/pnmFileTypeEXR.cxx index 7541d41a8fb..d4eff297c2e 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeEXR.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeEXR.cxx @@ -79,9 +79,9 @@ class ImfStdOstream : public IMF::OStream { // A wrapper class to map OpenEXR's IStream class onto std::istream. class ImfStdIstream : public IMF::IStream { public: - ImfStdIstream(std::istream &strm, const std::string &magic_number) : IMF::IStream("istream"), _strm(strm) { + ImfStdIstream(std::istream &strm, std::string_view magic_number) : IMF::IStream("istream"), _strm(strm) { // Start by putting back the magic number. - for (std::string::const_reverse_iterator mi = magic_number.rbegin(); + for (auto mi = magic_number.rbegin(); mi != magic_number.rend(); mi++) { _strm.putback(*mi); @@ -183,7 +183,7 @@ has_magic_number() const { * otherwise. */ bool PNMFileTypeEXR:: -matches_magic_number(const string &magic_number) const { +matches_magic_number(std::string_view magic_number) const { nassertr(magic_number.size() >= 2, false); if (magic_number.size() >= 4) { @@ -203,7 +203,7 @@ matches_magic_number(const string &magic_number) const { * returns NULL. */ PNMReader *PNMFileTypeEXR:: -make_reader(istream *file, bool owns_file, const string &magic_number) { +make_reader(istream *file, bool owns_file, std::string_view magic_number) { return new Reader(this, file, owns_file, magic_number); } @@ -221,7 +221,7 @@ make_writer(ostream *file, bool owns_file) { * */ PNMFileTypeEXR::Reader:: -Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number) : +Reader(PNMFileType *type, istream *file, bool owns_file, std::string_view magic_number) : PNMReader(type, file, owns_file), _strm(new ImfStdIstream(*_file, magic_number)), _imf_file(*_strm) diff --git a/panda/src/pnmimagetypes/pnmFileTypeEXR.h b/panda/src/pnmimagetypes/pnmFileTypeEXR.h index a1a095aeff9..d94b265d807 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeEXR.h +++ b/panda/src/pnmimagetypes/pnmFileTypeEXR.h @@ -47,16 +47,17 @@ class PNMFileTypeEXR : public PNMFileType { virtual std::string get_suggested_extension() const; virtual bool has_magic_number() const; - virtual bool matches_magic_number(const std::string &magic_number) const; + virtual bool matches_magic_number(std::string_view magic_number) const; virtual PNMReader *make_reader(std::istream *file, bool owns_file = true, - const std::string &magic_number = std::string()); + std::string_view magic_number = std::string_view()); virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true); public: class Reader : public PNMReader { public: - Reader(PNMFileType *type, std::istream *file, bool owns_file, std::string magic_number); + Reader(PNMFileType *type, std::istream *file, bool owns_file, + std::string_view magic_number); virtual ~Reader(); virtual bool is_floating_point(); diff --git a/panda/src/pnmimagetypes/pnmFileTypeIMG.cxx b/panda/src/pnmimagetypes/pnmFileTypeIMG.cxx index a46e82cc857..75b356f288d 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeIMG.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeIMG.cxx @@ -85,8 +85,8 @@ get_suggested_extension() const { * returns NULL. */ PNMReader *PNMFileTypeIMG:: -make_reader(istream *file, bool owns_file, const string &magic_number) { - return new Reader(this, file, owns_file, magic_number); +make_reader(istream *file, bool owns_file, std::string_view magic_number) { + return new Reader(this, file, owns_file, std::string(magic_number)); } /** diff --git a/panda/src/pnmimagetypes/pnmFileTypeIMG.h b/panda/src/pnmimagetypes/pnmFileTypeIMG.h index 8fb465af3c9..1cf850fb401 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeIMG.h +++ b/panda/src/pnmimagetypes/pnmFileTypeIMG.h @@ -36,7 +36,7 @@ class PNMFileTypeIMG : public PNMFileType { virtual std::string get_suggested_extension() const; virtual PNMReader *make_reader(std::istream *file, bool owns_file = true, - const std::string &magic_number = std::string()); + std::string_view magic_number = std::string_view()); virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true); public: diff --git a/panda/src/pnmimagetypes/pnmFileTypeJPG.cxx b/panda/src/pnmimagetypes/pnmFileTypeJPG.cxx index abc857e69e3..c6242f1255a 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeJPG.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeJPG.cxx @@ -87,7 +87,7 @@ has_magic_number() const { * otherwise. */ bool PNMFileTypeJPG:: -matches_magic_number(const string &magic_number) const { +matches_magic_number(std::string_view magic_number) const { nassertr(magic_number.size() >= 2, false); return ((char)magic_number[0] == (char)0xff && (char)magic_number[1] == (char)0xd8); @@ -99,7 +99,7 @@ matches_magic_number(const string &magic_number) const { * returns NULL. */ PNMReader *PNMFileTypeJPG:: -make_reader(std::istream *file, bool owns_file, const string &magic_number) { +make_reader(std::istream *file, bool owns_file, std::string_view magic_number) { return new Reader(this, file, owns_file, magic_number); } diff --git a/panda/src/pnmimagetypes/pnmFileTypeJPG.h b/panda/src/pnmimagetypes/pnmFileTypeJPG.h index f1e4268d8f6..d8cf87f162e 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeJPG.h +++ b/panda/src/pnmimagetypes/pnmFileTypeJPG.h @@ -66,16 +66,16 @@ class PNMFileTypeJPG : public PNMFileType { virtual std::string get_suggested_extension() const; virtual bool has_magic_number() const; - virtual bool matches_magic_number(const std::string &magic_number) const; + virtual bool matches_magic_number(std::string_view magic_number) const; virtual PNMReader *make_reader(std::istream *file, bool owns_file = true, - const std::string &magic_number = std::string()); + std::string_view magic_number = std::string_view()); virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true); public: class Reader : public PNMReader { public: - Reader(PNMFileType *type, std::istream *file, bool owns_file, std::string magic_number); + Reader(PNMFileType *type, std::istream *file, bool owns_file, std::string_view magic_number); ~Reader(); virtual void prepare_read(); diff --git a/panda/src/pnmimagetypes/pnmFileTypeJPGReader.cxx b/panda/src/pnmimagetypes/pnmFileTypeJPGReader.cxx index 2789583e7fe..603805ed41e 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeJPGReader.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeJPGReader.cxx @@ -245,13 +245,11 @@ jpeg_istream_src (j_decompress_ptr cinfo, std::istream * infile) * */ PNMFileTypeJPG::Reader:: -Reader(PNMFileType *type, std::istream *file, bool owns_file, std::string magic_number) : +Reader(PNMFileType *type, std::istream *file, bool owns_file, std::string_view magic_number) : PNMReader(type, file, owns_file) { // Hope we can putback() more than one character. - for (std::string::reverse_iterator mi = magic_number.rbegin(); - mi != magic_number.rend(); - ++mi) { + for (auto mi = magic_number.rbegin(); mi != magic_number.rend(); ++mi) { _file->putback(*mi); } if (_file->fail()) { diff --git a/panda/src/pnmimagetypes/pnmFileTypePNG.cxx b/panda/src/pnmimagetypes/pnmFileTypePNG.cxx index dd4f4eaeb6e..264f0b60f54 100644 --- a/panda/src/pnmimagetypes/pnmFileTypePNG.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypePNG.cxx @@ -111,7 +111,7 @@ has_magic_number() const { * otherwise. */ bool PNMFileTypePNG:: -matches_magic_number(const string &magic_number) const { +matches_magic_number(std::string_view magic_number) const { return png_sig_cmp((png_bytep)magic_number.data(), 0, magic_number.length()) == 0; } @@ -121,7 +121,7 @@ matches_magic_number(const string &magic_number) const { * returns NULL. */ PNMReader *PNMFileTypePNG:: -make_reader(istream *file, bool owns_file, const string &magic_number) { +make_reader(istream *file, bool owns_file, std::string_view magic_number) { return new Reader(this, file, owns_file, magic_number); } @@ -161,7 +161,7 @@ make_from_bam(const FactoryParams ¶ms) { * */ PNMFileTypePNG::Reader:: -Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number) : +Reader(PNMFileType *type, istream *file, bool owns_file, std::string_view magic_number) : PNMReader(type, file, owns_file) { _png = nullptr; diff --git a/panda/src/pnmimagetypes/pnmFileTypePNG.h b/panda/src/pnmimagetypes/pnmFileTypePNG.h index e423e26a217..9a4dc95baa5 100644 --- a/panda/src/pnmimagetypes/pnmFileTypePNG.h +++ b/panda/src/pnmimagetypes/pnmFileTypePNG.h @@ -39,16 +39,16 @@ class PNMFileTypePNG : public PNMFileType { virtual std::string get_suggested_extension() const; virtual bool has_magic_number() const; - virtual bool matches_magic_number(const std::string &magic_number) const; + virtual bool matches_magic_number(std::string_view magic_number) const; virtual PNMReader *make_reader(std::istream *file, bool owns_file = true, - const std::string &magic_number = std::string()); + std::string_view magic_number = std::string_view()); virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true); public: class Reader : public PNMReader { public: - Reader(PNMFileType *type, std::istream *file, bool owns_file, std::string magic_number); + Reader(PNMFileType *type, std::istream *file, bool owns_file, std::string_view magic_number); virtual ~Reader(); virtual int read_data(xel *array, xelval *alpha_data); diff --git a/panda/src/pnmimagetypes/pnmFileTypePNM.cxx b/panda/src/pnmimagetypes/pnmFileTypePNM.cxx index c61e0faf758..2ffbcb9550a 100644 --- a/panda/src/pnmimagetypes/pnmFileTypePNM.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypePNM.cxx @@ -1014,7 +1014,7 @@ has_magic_number() const { * otherwise. */ bool PNMFileTypePNM:: -matches_magic_number(const string &magic_number) const { +matches_magic_number(std::string_view magic_number) const { return (magic_number.size() >= 2) && magic_number[0] == 'P' && (magic_number[1] >= '1' && magic_number[1] <= '6'); @@ -1026,8 +1026,8 @@ matches_magic_number(const string &magic_number) const { * returns NULL. */ PNMReader *PNMFileTypePNM:: -make_reader(istream *file, bool owns_file, const string &magic_number) { - return new Reader(this, file, owns_file, magic_number); +make_reader(istream *file, bool owns_file, std::string_view magic_number) { + return new Reader(this, file, owns_file, std::string(magic_number)); } /** diff --git a/panda/src/pnmimagetypes/pnmFileTypePNM.h b/panda/src/pnmimagetypes/pnmFileTypePNM.h index ab42fe1ee0d..30188e6a675 100644 --- a/panda/src/pnmimagetypes/pnmFileTypePNM.h +++ b/panda/src/pnmimagetypes/pnmFileTypePNM.h @@ -36,10 +36,10 @@ class PNMFileTypePNM : public PNMFileType { virtual std::string get_suggested_extension() const; virtual bool has_magic_number() const; - virtual bool matches_magic_number(const std::string &magic_number) const; + virtual bool matches_magic_number(std::string_view magic_number) const; virtual PNMReader *make_reader(std::istream *file, bool owns_file = true, - const std::string &magic_number = std::string()); + std::string_view magic_number = std::string_view()); virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true); public: diff --git a/panda/src/pnmimagetypes/pnmFileTypePfm.cxx b/panda/src/pnmimagetypes/pnmFileTypePfm.cxx index 1933515785a..5ba0aa18747 100644 --- a/panda/src/pnmimagetypes/pnmFileTypePfm.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypePfm.cxx @@ -81,7 +81,7 @@ has_magic_number() const { * otherwise. */ bool PNMFileTypePfm:: -matches_magic_number(const string &magic_number) const { +matches_magic_number(std::string_view magic_number) const { return (magic_number.size() >= 2) && (magic_number.substr(0, 2) == "PF" || magic_number.substr(0, 2) == "Pf" || @@ -94,8 +94,8 @@ matches_magic_number(const string &magic_number) const { * returns NULL. */ PNMReader *PNMFileTypePfm:: -make_reader(istream *file, bool owns_file, const string &magic_number) { - return new Reader(this, file, owns_file, magic_number); +make_reader(istream *file, bool owns_file, std::string_view magic_number) { + return new Reader(this, file, owns_file, std::string(magic_number)); } /** @@ -156,7 +156,7 @@ Reader(PNMFileType *type, istream *file, bool owns_file, string magic_number) : return; } - // Skip the last newlinewhitespace character before the raw data begins. + // Skip the last newline/whitespace character before the raw data begins. (*_file).get(); } diff --git a/panda/src/pnmimagetypes/pnmFileTypePfm.h b/panda/src/pnmimagetypes/pnmFileTypePfm.h index 096c1fc4da6..b3041d06adf 100644 --- a/panda/src/pnmimagetypes/pnmFileTypePfm.h +++ b/panda/src/pnmimagetypes/pnmFileTypePfm.h @@ -36,10 +36,10 @@ class PNMFileTypePfm : public PNMFileType { virtual std::string get_suggested_extension() const; virtual bool has_magic_number() const; - virtual bool matches_magic_number(const std::string &magic_number) const; + virtual bool matches_magic_number(std::string_view magic_number) const; virtual PNMReader *make_reader(std::istream *file, bool owns_file = true, - const std::string &magic_number = std::string()); + std::string_view magic_number = std::string_view()); virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true); public: diff --git a/panda/src/pnmimagetypes/pnmFileTypeSGI.cxx b/panda/src/pnmimagetypes/pnmFileTypeSGI.cxx index eba81e8ccde..a34303cb8c3 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeSGI.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeSGI.cxx @@ -88,7 +88,7 @@ has_magic_number() const { * otherwise. */ bool PNMFileTypeSGI:: -matches_magic_number(const string &magic_number) const { +matches_magic_number(std::string_view magic_number) const { nassertr(magic_number.size() >= 2, false); int mn = ((unsigned char)magic_number[0] << 8) | @@ -102,8 +102,8 @@ matches_magic_number(const string &magic_number) const { * returns NULL. */ PNMReader *PNMFileTypeSGI:: -make_reader(std::istream *file, bool owns_file, const string &magic_number) { - return new Reader(this, file, owns_file, magic_number); +make_reader(std::istream *file, bool owns_file, std::string_view magic_number) { + return new Reader(this, file, owns_file, std::string(magic_number)); } /** diff --git a/panda/src/pnmimagetypes/pnmFileTypeSGI.h b/panda/src/pnmimagetypes/pnmFileTypeSGI.h index 0152354251f..7124094424f 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeSGI.h +++ b/panda/src/pnmimagetypes/pnmFileTypeSGI.h @@ -36,10 +36,10 @@ class PNMFileTypeSGI : public PNMFileType { virtual std::string get_suggested_extension() const; virtual bool has_magic_number() const; - virtual bool matches_magic_number(const std::string &magic_number) const; + virtual bool matches_magic_number(std::string_view magic_number) const; virtual PNMReader *make_reader(std::istream *file, bool owns_file = true, - const std::string &magic_number = std::string()); + std::string_view magic_number = std::string_view()); virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true); public: diff --git a/panda/src/pnmimagetypes/pnmFileTypeSGIReader.cxx b/panda/src/pnmimagetypes/pnmFileTypeSGIReader.cxx index 03f846b5cdf..0bf26228fd7 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeSGIReader.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeSGIReader.cxx @@ -62,7 +62,7 @@ static void * xmalloc (int bytes); #define MALLOC(n, type) (type *)xmalloc((n) * sizeof(type)) static const char * compression_name (char compr); static void read_bytes (istream *ifp, int n, char *buf); -static bool read_header(istream *ifp, Header *head, const string &magic_number); +static bool read_header(istream *ifp, Header *head, std::string_view magic_number); static TabEntry * read_table (istream *ifp, int tablen); static void read_channel (istream *ifp, int xsize, int ysize, int zsize, int bpc, TabEntry *table, @@ -220,7 +220,7 @@ read_row(xel *row_data, xelval *alpha_data, int x_size, int y_size) { static bool -read_header(istream *ifp, Header *head, const string &magic_number) { +read_header(istream *ifp, Header *head, std::string_view magic_number) { nassertr(magic_number.size() == 4, false); head->magic = ((unsigned char)magic_number[0] << 8) | diff --git a/panda/src/pnmimagetypes/pnmFileTypeSoftImage.cxx b/panda/src/pnmimagetypes/pnmFileTypeSoftImage.cxx index bb7fba20e8d..14fefa0e5e5 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeSoftImage.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeSoftImage.cxx @@ -262,7 +262,7 @@ has_magic_number() const { * otherwise. */ bool PNMFileTypeSoftImage:: -matches_magic_number(const string &magic_number) const { +matches_magic_number(std::string_view magic_number) const { nassertr(magic_number.size() >= 2, false); int mn = ((unsigned char)magic_number[0] << 8) | @@ -276,8 +276,8 @@ matches_magic_number(const string &magic_number) const { * returns NULL. */ PNMReader *PNMFileTypeSoftImage:: -make_reader(istream *file, bool owns_file, const string &magic_number) { - return new Reader(this, file, owns_file, magic_number); +make_reader(istream *file, bool owns_file, std::string_view magic_number) { + return new Reader(this, file, owns_file, std::string(magic_number)); } /** diff --git a/panda/src/pnmimagetypes/pnmFileTypeSoftImage.h b/panda/src/pnmimagetypes/pnmFileTypeSoftImage.h index 2597e777132..3da9d7f9c47 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeSoftImage.h +++ b/panda/src/pnmimagetypes/pnmFileTypeSoftImage.h @@ -36,10 +36,10 @@ class PNMFileTypeSoftImage : public PNMFileType { virtual std::string get_suggested_extension() const; virtual bool has_magic_number() const; - virtual bool matches_magic_number(const std::string &magic_number) const; + virtual bool matches_magic_number(std::string_view magic_number) const; virtual PNMReader *make_reader(std::istream *file, bool owns_file = true, - const std::string &magic_number = std::string()); + std::string_view magic_number = std::string_view()); virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true); public: diff --git a/panda/src/pnmimagetypes/pnmFileTypeStbImage.cxx b/panda/src/pnmimagetypes/pnmFileTypeStbImage.cxx index 612e8da6416..beaba5bf73a 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeStbImage.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeStbImage.cxx @@ -134,7 +134,8 @@ static stbi_io_callbacks io_callbacks = {cb_read, cb_skip, cb_eof}; */ class StbImageReader : public PNMReader { public: - StbImageReader(PNMFileType *type, istream *file, bool owns_file, string magic_number); + StbImageReader(PNMFileType *type, istream *file, bool owns_file, + std::string_view magic_number); virtual bool is_floating_point(); virtual bool read_pfm(PfmFile &pfm); @@ -197,7 +198,7 @@ has_magic_number() const { * otherwise. */ bool PNMFileTypeStbImage:: -matches_magic_number(const string &magic_number) const { +matches_magic_number(std::string_view magic_number) const { return false; } @@ -207,7 +208,7 @@ matches_magic_number(const string &magic_number) const { * returns NULL. */ PNMReader *PNMFileTypeStbImage:: -make_reader(istream *file, bool owns_file, const string &magic_number) { +make_reader(istream *file, bool owns_file, std::string_view magic_number) { return new StbImageReader(this, file, owns_file, magic_number); } @@ -215,7 +216,7 @@ make_reader(istream *file, bool owns_file, const string &magic_number) { * */ StbImageReader:: -StbImageReader(PNMFileType *type, istream *file, bool owns_file, string magic_number) : +StbImageReader(PNMFileType *type, istream *file, bool owns_file, std::string_view magic_number) : PNMReader(type, file, owns_file), _is_float(false) { diff --git a/panda/src/pnmimagetypes/pnmFileTypeStbImage.h b/panda/src/pnmimagetypes/pnmFileTypeStbImage.h index ecfd73ebaf4..562226d5a06 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeStbImage.h +++ b/panda/src/pnmimagetypes/pnmFileTypeStbImage.h @@ -37,10 +37,10 @@ class PNMFileTypeStbImage : public PNMFileType { virtual std::string get_extension(int n) const; virtual bool has_magic_number() const; - virtual bool matches_magic_number(const std::string &magic_number) const; + virtual bool matches_magic_number(std::string_view magic_number) const; virtual PNMReader *make_reader(std::istream *file, bool owns_file = true, - const std::string &magic_number = std::string()); + std::string_view magic_number = std::string_view()); public: static void register_with_read_factory(); diff --git a/panda/src/pnmimagetypes/pnmFileTypeTGA.cxx b/panda/src/pnmimagetypes/pnmFileTypeTGA.cxx index c881c1f0852..5063ab17c5d 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeTGA.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeTGA.cxx @@ -153,8 +153,8 @@ get_suggested_extension() const { * returns NULL. */ PNMReader *PNMFileTypeTGA:: -make_reader(istream *file, bool owns_file, const string &magic_number) { - return new Reader(this, file, owns_file, magic_number); +make_reader(istream *file, bool owns_file, std::string_view magic_number) { + return new Reader(this, file, owns_file, std::string(magic_number)); } /** @@ -574,7 +574,7 @@ make_from_bam(const FactoryParams ¶ms) { } void PNMFileTypeTGA::Reader:: -readtga( istream *ifp, struct ImageHeader *tgaP, const string &magic_number ) { +readtga( istream *ifp, struct ImageHeader *tgaP, std::string_view magic_number ) { unsigned char flags; ImageIDField junk; diff --git a/panda/src/pnmimagetypes/pnmFileTypeTGA.h b/panda/src/pnmimagetypes/pnmFileTypeTGA.h index 4181a2a3561..87e3d526130 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeTGA.h +++ b/panda/src/pnmimagetypes/pnmFileTypeTGA.h @@ -40,7 +40,7 @@ class PNMFileTypeTGA : public PNMFileType { virtual std::string get_suggested_extension() const; virtual PNMReader *make_reader(std::istream *file, bool owns_file = true, - const std::string &magic_number = std::string()); + std::string_view magic_number = std::string_view()); virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true); public: @@ -52,7 +52,7 @@ class PNMFileTypeTGA : public PNMFileType { virtual int read_data(xel *array, xelval *alpha); private: - void readtga ( std::istream* ifp, struct ImageHeader* tgaP, const std::string &magic_number ); + void readtga ( std::istream* ifp, struct ImageHeader* tgaP, std::string_view magic_number ); void get_map_entry ( std::istream* ifp, pixel* Value, int Size, gray* Alpha); void get_pixel ( std::istream* ifp, pixel* dest, int Size, gray* alpha_p); diff --git a/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx b/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx index 74216fa48fe..9c9fbb6757d 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypeTIFF.cxx @@ -277,7 +277,7 @@ has_magic_number() const { * otherwise. */ bool PNMFileTypeTIFF:: -matches_magic_number(const string &magic_number) const { +matches_magic_number(std::string_view magic_number) const { nassertr(magic_number.size() >= 2, false); int mn = ((unsigned char)magic_number[0] << 8) | @@ -291,9 +291,9 @@ matches_magic_number(const string &magic_number) const { * returns NULL. */ PNMReader *PNMFileTypeTIFF:: -make_reader(istream *file, bool owns_file, const string &magic_number) { +make_reader(istream *file, bool owns_file, std::string_view magic_number) { install_error_handlers(); - return new Reader(this, file, owns_file, magic_number); + return new Reader(this, file, owns_file, std::string(magic_number)); } /** diff --git a/panda/src/pnmimagetypes/pnmFileTypeTIFF.h b/panda/src/pnmimagetypes/pnmFileTypeTIFF.h index 7de62bf0f34..48978e2c83e 100644 --- a/panda/src/pnmimagetypes/pnmFileTypeTIFF.h +++ b/panda/src/pnmimagetypes/pnmFileTypeTIFF.h @@ -41,10 +41,10 @@ class PNMFileTypeTIFF : public PNMFileType { virtual std::string get_suggested_extension() const; virtual bool has_magic_number() const; - virtual bool matches_magic_number(const std::string &magic_number) const; + virtual bool matches_magic_number(std::string_view magic_number) const; virtual PNMReader *make_reader(std::istream *file, bool owns_file = true, - const std::string &magic_number = std::string()); + std::string_view magic_number = std::string_view()); virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true); public: diff --git a/panda/src/pnmtext/freetypeFont.cxx b/panda/src/pnmtext/freetypeFont.cxx index bab27344640..3fbe72be689 100644 --- a/panda/src/pnmtext/freetypeFont.cxx +++ b/panda/src/pnmtext/freetypeFont.cxx @@ -198,7 +198,7 @@ unload_font() { * WindingOrder value. */ FreetypeFont::WindingOrder FreetypeFont:: -string_winding_order(const string &string) { +string_winding_order(std::string_view string) { if (cmp_nocase_uh(string, "default") == 0) { return WO_default; } else if (cmp_nocase_uh(string, "left") == 0) { diff --git a/panda/src/pnmtext/freetypeFont.h b/panda/src/pnmtext/freetypeFont.h index dc89b09218b..f94c69978db 100644 --- a/panda/src/pnmtext/freetypeFont.h +++ b/panda/src/pnmtext/freetypeFont.h @@ -85,7 +85,7 @@ class EXPCL_PANDA_PNMTEXT FreetypeFont : public Namable { MAKE_PROPERTY(winding_order, get_winding_order, set_winding_order); public: - static WindingOrder string_winding_order(const std::string &string); + static WindingOrder string_winding_order(std::string_view string); protected: INLINE FT_Face acquire_face() const; diff --git a/panda/src/pnmtext/pnmTextMaker.I b/panda/src/pnmtext/pnmTextMaker.I index 96eb3809763..f6a27b994b6 100644 --- a/panda/src/pnmtext/pnmTextMaker.I +++ b/panda/src/pnmtext/pnmTextMaker.I @@ -122,7 +122,7 @@ get_distance_field_radius() const { * position; the return value is the total width in pixels. */ INLINE int PNMTextMaker:: -generate_into(const std::string &text, PNMImage &dest_image, int x, int y) { +generate_into(std::string_view text, PNMImage &dest_image, int x, int y) { TextEncoder encoder; encoder.set_text(text); return generate_into(encoder.get_wtext(), dest_image, x, y); @@ -132,7 +132,7 @@ generate_into(const std::string &text, PNMImage &dest_image, int x, int y) { * Returns the width in pixels of the indicated line of text. */ INLINE int PNMTextMaker:: -calc_width(const std::string &text) { +calc_width(std::string_view text) { TextEncoder encoder; encoder.set_text(text); return calc_width(encoder.get_wtext()); diff --git a/panda/src/pnmtext/pnmTextMaker.cxx b/panda/src/pnmtext/pnmTextMaker.cxx index 8a22fff510e..b832bdda4f4 100644 --- a/panda/src/pnmtext/pnmTextMaker.cxx +++ b/panda/src/pnmtext/pnmTextMaker.cxx @@ -80,7 +80,7 @@ PNMTextMaker:: * position; the return value is the total width in pixels. */ int PNMTextMaker:: -generate_into(const wstring &text, PNMImage &dest_image, int x, int y) { +generate_into(std::wstring_view text, PNMImage &dest_image, int x, int y) { // First, measure the total width in pixels. int width = calc_width(text); @@ -102,9 +102,7 @@ generate_into(const wstring &text, PNMImage &dest_image, int x, int y) { } // Now place the text. - wstring::const_iterator ti; - for (ti = text.begin(); ti != text.end(); ++ti) { - int ch = (*ti); + for (int ch : text) { PNMTextGlyph *glyph = get_glyph(ch); if (_interior_flag) { glyph->place(dest_image, xp, yp, _fg, _interior); @@ -121,11 +119,9 @@ generate_into(const wstring &text, PNMImage &dest_image, int x, int y) { * Returns the width in pixels of the indicated line of text. */ int PNMTextMaker:: -calc_width(const wstring &text) { +calc_width(std::wstring_view text) { int width = 0; - wstring::const_iterator ti; - for (ti = text.begin(); ti != text.end(); ++ti) { - int ch = (*ti); + for (int ch : text) { PNMTextGlyph *glyph = get_glyph(ch); width += glyph->get_advance(); } diff --git a/panda/src/pnmtext/pnmTextMaker.h b/panda/src/pnmtext/pnmTextMaker.h index 213298f81c3..acdccec0ced 100644 --- a/panda/src/pnmtext/pnmTextMaker.h +++ b/panda/src/pnmtext/pnmTextMaker.h @@ -63,12 +63,12 @@ class EXPCL_PANDA_PNMTEXT PNMTextMaker : public FreetypeFont { INLINE void set_distance_field_radius(int radius); INLINE int get_distance_field_radius() const; - INLINE int generate_into(const std::string &text, + INLINE int generate_into(std::string_view text, PNMImage &dest_image, int x, int y); - int generate_into(const std::wstring &text, + int generate_into(std::wstring_view text, PNMImage &dest_image, int x, int y); - INLINE int calc_width(const std::string &text); - int calc_width(const std::wstring &text); + INLINE int calc_width(std::string_view text); + int calc_width(std::wstring_view text); PNMTextGlyph *get_glyph(int character); diff --git a/panda/src/pstatclient/pStatClient.I b/panda/src/pstatclient/pStatClient.I index 2f5433d5582..1fe4ac7d6cb 100644 --- a/panda/src/pstatclient/pStatClient.I +++ b/panda/src/pstatclient/pStatClient.I @@ -70,8 +70,8 @@ get_thread_object(int index) const { * true if successful, false on failure. */ INLINE bool PStatClient:: -connect(const std::string &hostname, int port) { - return get_global_pstats()->client_connect(hostname, port); +connect(std::string hostname, int port) { + return get_global_pstats()->client_connect(std::move(hostname), port); } /** @@ -161,10 +161,10 @@ get_thread_ptr(int thread_index) const { * */ INLINE PStatClient::Collector:: -Collector(int parent_index, const std::string &name) : +Collector(int parent_index, std::string name) : _def(nullptr), _parent_index(parent_index), - _name(name) + _name(std::move(name)) { } diff --git a/panda/src/pstatclient/pStatClient.cxx b/panda/src/pstatclient/pStatClient.cxx index 809dd0828af..43b38d88fc5 100644 --- a/panda/src/pstatclient/pStatClient.cxx +++ b/panda/src/pstatclient/pStatClient.cxx @@ -105,8 +105,8 @@ PStatClient:: * will presumably be written in the title bar or something. */ void PStatClient:: -set_client_name(const string &name) { - get_impl()->set_client_name(name); +set_client_name(std::string name) { + get_impl()->set_client_name(std::move(name)); } /** @@ -388,7 +388,7 @@ thread_tick() { * indicated sync_name */ void PStatClient:: -thread_tick(const string &sync_name) { +thread_tick(std::string_view sync_name) { get_global_pstats()->client_thread_tick(sync_name); } @@ -443,7 +443,7 @@ client_thread_tick() { * indicated sync name. */ void PStatClient:: -client_thread_tick(const string &sync_name) { +client_thread_tick(std::string_view sync_name) { ReMutexHolder holder(_lock); if (has_impl()) { @@ -556,7 +556,7 @@ make_impl() const { * the client indicated by the parent index. */ PStatCollector PStatClient:: -make_collector_with_relname(int parent_index, string relname) { +make_collector_with_relname(int parent_index, std::string_view relname) { ReMutexHolder holder(_lock); if (relname.empty()) { @@ -572,18 +572,16 @@ make_collector_with_relname(int parent_index, string relname) { // If the name contains a colon (after the initial colon), it means we are // making a nested collector. size_t colon = relname.find(':', start); - while (colon != string::npos) { - string parent_name = relname.substr(start, colon - start); + while (colon != std::string_view::npos) { PStatCollector parent_collector = - make_collector_with_name(parent_index, parent_name); + make_collector_with_name(parent_index, relname.substr(start, colon - start)); parent_index = parent_collector._index; relname = relname.substr(colon + 1); start = 0; colon = relname.find(':'); } - string name = relname.substr(start); - return make_collector_with_name(parent_index, name); + return make_collector_with_name(parent_index, relname.substr(start)); } /** @@ -593,7 +591,7 @@ make_collector_with_relname(int parent_index, string relname) { * The name should not contain colons. */ PStatCollector PStatClient:: -make_collector_with_name(int parent_index, const string &name) { +make_collector_with_name(int parent_index, std::string_view name) { ReMutexHolder holder(_lock); int num_collectors = get_num_collectors(); @@ -619,9 +617,10 @@ make_collector_with_name(int parent_index, const string &name) { } // Create a new collector for this name. - parent->_children.insert(ThingsByName::value_type(name, num_collectors)); + std::string name_str(name); + parent->_children.insert(ThingsByName::value_type(name_str, num_collectors)); - Collector *collector = new Collector(parent_index, name); + Collector *collector = new Collector(parent_index, std::move(name_str)); // collector->_def = new PStatCollectorDef(num_collectors, name); // collector->_def->set_parent(*_collectors[parent_index]._def); // initialize_collector_def(this, collector->_def); @@ -720,11 +719,11 @@ do_make_thread(Thread *thread) { * GSG only. */ PStatThread PStatClient:: -make_gpu_thread(const string &name) { +make_gpu_thread(std::string name) { ReMutexHolder holder(_lock); int new_index = get_num_threads(); - InternalThread *pthread = new InternalThread(name, "GPU"); + InternalThread *pthread = new InternalThread(std::move(name), "GPU"); add_thread(pthread); return PStatThread(this, new_index); @@ -1333,22 +1332,22 @@ InternalThread(Thread *thread) : * */ PStatClient::InternalThread:: -InternalThread(const string &name, const string &sync_name) : +InternalThread(std::string name, std::string sync_name) : _thread(nullptr), - _name(name), - _sync_name(sync_name), + _name(std::move(name)), + _sync_name(std::move(sync_name)), _is_active(false), _frame_number(0), _next_packet(0.0), _thread_active(true), - _thread_lock(string("PStatClient::InternalThread ") + name) + _thread_lock(string("PStatClient::InternalThread ") + _name) { } #else // DO_PSTATS void PStatClient:: -set_client_name(const std::string &name) { +set_client_name(std::string name) { } std::string PStatClient:: @@ -1401,7 +1400,7 @@ get_current_thread() const { } PStatCollector PStatClient:: -make_collector_with_relname(int parent_index, std::string relname) { +make_collector_with_relname(int parent_index, std::string_view relname) { return PStatCollector(); } @@ -1419,7 +1418,7 @@ thread_tick() { } void PStatClient:: -thread_tick(const std::string &) { +thread_tick(std::string_view) { } void PStatClient:: @@ -1431,7 +1430,7 @@ client_thread_tick() { } void PStatClient:: -client_thread_tick(const std::string &sync_name) { +client_thread_tick(std::string_view sync_name) { } bool PStatClient:: diff --git a/panda/src/pstatclient/pStatClient.h b/panda/src/pstatclient/pStatClient.h index 4548d29d01f..56a0d8d0c36 100644 --- a/panda/src/pstatclient/pStatClient.h +++ b/panda/src/pstatclient/pStatClient.h @@ -57,7 +57,7 @@ class EXPCL_PANDA_PSTATCLIENT PStatClient : public Thread::PStatsCallback { ~PStatClient(); PUBLISHED: - void set_client_name(const std::string &name); + void set_client_name(std::string name); std::string get_client_name() const; void set_max_rate(double rate); double get_max_rate() const; @@ -89,7 +89,7 @@ class EXPCL_PANDA_PSTATCLIENT PStatClient : public Thread::PStatsCallback { MAKE_PROPERTY(current_thread, get_current_thread); MAKE_PROPERTY(real_time, get_real_time); - EXTEND INLINE static bool connect(const std::string &hostname = std::string(), int port = -1); + EXTEND INLINE static bool connect(std::string hostname = std::string(), int port = -1); EXTEND INLINE static void disconnect(); INLINE static bool is_connected(); @@ -97,11 +97,11 @@ class EXPCL_PANDA_PSTATCLIENT PStatClient : public Thread::PStatsCallback { static void main_tick(); static void thread_tick(); - static void thread_tick(const std::string &sync_name); + static void thread_tick(std::string_view sync_name); void client_main_tick(); void client_thread_tick(); - void client_thread_tick(const std::string &sync_name); + void client_thread_tick(std::string_view sync_name); EXTEND bool client_connect(std::string hostname, int port); EXTEND void client_disconnect(); bool client_is_connected() const; @@ -116,12 +116,12 @@ class EXPCL_PANDA_PSTATCLIENT PStatClient : public Thread::PStatsCallback { INLINE const PStatClientImpl *get_impl() const; void make_impl() const; - PStatCollector make_collector_with_relname(int parent_index, std::string relname); - PStatCollector make_collector_with_name(int parent_index, const std::string &name); + PStatCollector make_collector_with_relname(int parent_index, std::string_view relname); + PStatCollector make_collector_with_name(int parent_index, std::string_view name); PStatThread do_get_current_thread() const; PStatThread make_thread(Thread *thread); PStatThread do_make_thread(Thread *thread); - PStatThread make_gpu_thread(const std::string &name); + PStatThread make_gpu_thread(std::string name); bool is_active(int collector_index, int thread_index) const; bool is_started(int collector_index, int thread_index) const; @@ -157,8 +157,8 @@ class EXPCL_PANDA_PSTATCLIENT PStatClient : public Thread::PStatsCallback { // This mutex protects everything in this class. ReMutex _lock; - typedef pmap ThingsByName; - typedef pmap MultiThingsByName; + typedef pmap> ThingsByName; + typedef pmap> MultiThingsByName; MultiThingsByName _threads_by_name, _threads_by_sync_name; // This is for the data that is per-collector, per-thread. A vector of @@ -176,7 +176,7 @@ class EXPCL_PANDA_PSTATCLIENT PStatClient : public Thread::PStatsCallback { // in PStatCollector and PStatCollectorDef is just fluff.) class EXPCL_PANDA_PSTATCLIENT Collector { public: - INLINE Collector(int parent_index, const std::string &name); + INLINE Collector(int parent_index, std::string name); INLINE int get_parent_index() const; INLINE const std::string &get_name() const; INLINE bool is_active() const; @@ -210,7 +210,7 @@ class EXPCL_PANDA_PSTATCLIENT PStatClient : public Thread::PStatsCallback { class InternalThread { public: InternalThread(Thread *thread); - InternalThread(const std::string &name, const std::string &sync_name = "Main"); + InternalThread(std::string name, std::string sync_name = "Main"); WPT(Thread) _thread; std::string _name; @@ -276,7 +276,7 @@ class EXPCL_PANDA_PSTATCLIENT PStatClient { PStatClient() { } ~PStatClient() { } - void set_client_name(const std::string &name); + void set_client_name(std::string name); std::string get_client_name() const; void set_max_rate(double rate); double get_max_rate() const; @@ -297,19 +297,19 @@ class EXPCL_PANDA_PSTATCLIENT PStatClient { double get_real_time() const; PUBLISHED: - INLINE static bool connect(const std::string & = std::string(), int = -1) { return false; } + INLINE static bool connect(std::string_view = std::string_view(), int = -1) { return false; } INLINE static void disconnect() { } INLINE static bool is_connected() { return false; } INLINE static void resume_after_pause() { } static void main_tick(); static void thread_tick(); - static void thread_tick(const std::string &); + static void thread_tick(std::string_view); public: void client_main_tick(); void client_thread_tick(); - void client_thread_tick(const std::string &sync_name); + void client_thread_tick(std::string_view sync_name); bool client_connect(std::string hostname, int port); void client_disconnect(); bool client_is_connected() const; @@ -321,7 +321,7 @@ class EXPCL_PANDA_PSTATCLIENT PStatClient { private: // These are used by inline PStatCollector methods, so they need to be // stubbed out for ABI compatibility. - PStatCollector make_collector_with_relname(int parent_index, std::string relname); + PStatCollector make_collector_with_relname(int parent_index, std::string_view relname); PStatThread make_thread(Thread *thread); bool is_active(int collector_index, int thread_index) const; diff --git a/panda/src/pstatclient/pStatClientImpl.I b/panda/src/pstatclient/pStatClientImpl.I index 97bf6ddce76..7b499925fb6 100644 --- a/panda/src/pstatclient/pStatClientImpl.I +++ b/panda/src/pstatclient/pStatClientImpl.I @@ -16,8 +16,8 @@ * will presumably be written in the title bar or something. */ INLINE void PStatClientImpl:: -set_client_name(const std::string &name) { - _client_name = name; +set_client_name(std::string name) { + _client_name = std::move(name); } /** diff --git a/panda/src/pstatclient/pStatClientImpl.h b/panda/src/pstatclient/pStatClientImpl.h index 3cc57deb43e..c3c656e1e8c 100644 --- a/panda/src/pstatclient/pStatClientImpl.h +++ b/panda/src/pstatclient/pStatClientImpl.h @@ -53,7 +53,7 @@ class EXPCL_PANDA_PSTATCLIENT PStatClientImpl : public ConnectionManager { PStatClientImpl(PStatClient *client); ~PStatClientImpl(); - INLINE void set_client_name(const std::string &name); + INLINE void set_client_name(std::string name); INLINE std::string get_client_name() const; INLINE void set_max_rate(double rate); INLINE double get_max_rate() const; diff --git a/panda/src/pstatclient/pStatClient_ext.I b/panda/src/pstatclient/pStatClient_ext.I index c1c255d4185..8030dc6629c 100644 --- a/panda/src/pstatclient/pStatClient_ext.I +++ b/panda/src/pstatclient/pStatClient_ext.I @@ -16,9 +16,9 @@ * true if successful, false on failure. */ INLINE bool Extension:: -connect(const std::string &hostname, int port) { +connect(std::string hostname, int port) { PStatClient *client = PStatClient::get_global_pstats(); - return invoke_extension(client).client_connect(hostname, port); + return invoke_extension(client).client_connect(std::move(hostname), port); } /** diff --git a/panda/src/pstatclient/pStatClient_ext.h b/panda/src/pstatclient/pStatClient_ext.h index 47c43b178d3..64c2bb9f6a0 100644 --- a/panda/src/pstatclient/pStatClient_ext.h +++ b/panda/src/pstatclient/pStatClient_ext.h @@ -31,7 +31,7 @@ typedef struct _frame PyFrameObject; template<> class Extension : public ExtensionBase { public: - INLINE static bool connect(const std::string &hostname = std::string(), int port = -1); + INLINE static bool connect(std::string hostname = std::string(), int port = -1); INLINE static void disconnect(); bool client_connect(std::string hostname, int port); diff --git a/panda/src/pstatclient/pStatCollector.I b/panda/src/pstatclient/pStatCollector.I index cb88cb90b8a..65ee42fb14b 100644 --- a/panda/src/pstatclient/pStatCollector.I +++ b/panda/src/pstatclient/pStatCollector.I @@ -40,7 +40,7 @@ PStatCollector(PStatClient *client, int index) : * register the collector with; otherwise, the global client is used. */ INLINE PStatCollector:: -PStatCollector(const std::string &name, PStatClient *client) : +PStatCollector(std::string_view name, PStatClient *client) : _level(0.0f) { if (client == nullptr) { @@ -66,7 +66,7 @@ PStatCollector(const std::string &name, PStatClient *client) : * collector on the same client as its parent. */ INLINE PStatCollector:: -PStatCollector(const PStatCollector &parent, const std::string &name) : +PStatCollector(const PStatCollector &parent, std::string_view name) : _level(0.0f) { nassertv(parent._client != nullptr); @@ -485,7 +485,7 @@ PStatCollector() * defined, meaning all these functions should compile to nothing. */ INLINE PStatCollector:: -PStatCollector(const std::string &, PStatClient *client) { +PStatCollector(std::string_view, PStatClient *client) { // We need this bogus comparison just to prevent the SGI compiler from // dumping core. It's perfectly meaningless. #ifdef mips @@ -500,7 +500,7 @@ PStatCollector(const std::string &, PStatClient *client) { * defined, meaning all these functions should compile to nothing. */ INLINE PStatCollector:: -PStatCollector(const PStatCollector &parent, const std::string &) { +PStatCollector(const PStatCollector &parent, std::string_view) { // We need this bogus comparison just to prevent the SGI compiler from // dumping core. It's perfectly meaningless. #ifdef mips diff --git a/panda/src/pstatclient/pStatCollector.h b/panda/src/pstatclient/pStatCollector.h index 2fa98c68cf2..6283cfcc8a0 100644 --- a/panda/src/pstatclient/pStatCollector.h +++ b/panda/src/pstatclient/pStatCollector.h @@ -48,10 +48,10 @@ class EXPCL_PANDA_PSTATCLIENT PStatCollector { INLINE PStatCollector(PStatClient *client, int index); PUBLISHED: - INLINE explicit PStatCollector(const std::string &name, + INLINE explicit PStatCollector(std::string_view name, PStatClient *client = nullptr); INLINE explicit PStatCollector(const PStatCollector &parent, - const std::string &name); + std::string_view name); INLINE PStatCollector(const PStatCollector ©); INLINE void operator = (const PStatCollector ©); @@ -108,10 +108,10 @@ friend class PStatClient; INLINE PStatCollector(); PUBLISHED: - INLINE PStatCollector(const std::string &name, + INLINE PStatCollector(std::string_view name, PStatClient *client = nullptr); INLINE PStatCollector(const PStatCollector &parent, - const std::string &name); + std::string_view name); INLINE bool is_active() { return false; } INLINE bool is_started() { return false; } diff --git a/panda/src/pstatclient/pStatCollectorDef.cxx b/panda/src/pstatclient/pStatCollectorDef.cxx index bdd0035bba7..509feaf0715 100644 --- a/panda/src/pstatclient/pStatCollectorDef.cxx +++ b/panda/src/pstatclient/pStatCollectorDef.cxx @@ -38,9 +38,9 @@ PStatCollectorDef() { * */ PStatCollectorDef:: -PStatCollectorDef(int index, const std::string &name) : +PStatCollectorDef(int index, std::string name) : _index(index), - _name(name) + _name(std::move(name)) { _parent_index = 0; _suggested_color.r = 0.0; diff --git a/panda/src/pstatclient/pStatCollectorDef.h b/panda/src/pstatclient/pStatCollectorDef.h index 87a99df834f..113c93df26f 100644 --- a/panda/src/pstatclient/pStatCollectorDef.h +++ b/panda/src/pstatclient/pStatCollectorDef.h @@ -29,7 +29,7 @@ class PStatClientVersion; class EXPCL_PANDA_PSTATCLIENT PStatCollectorDef { public: PStatCollectorDef(); - PStatCollectorDef(int index, const std::string &name); + PStatCollectorDef(int index, std::string name); void set_parent(const PStatCollectorDef &parent); void write_datagram(Datagram &destination) const; diff --git a/panda/src/pstatclient/pStatProperties.cxx b/panda/src/pstatclient/pStatProperties.cxx index 8ebc8b0d37c..13b49eba55b 100644 --- a/panda/src/pstatclient/pStatProperties.cxx +++ b/panda/src/pstatclient/pStatProperties.cxx @@ -224,7 +224,7 @@ static LevelCollectorProperties level_properties[] = { * properties appropriately if it is found. */ static void -initialize_collector_def_from_table(const string &fullname, PStatCollectorDef *def) { +initialize_collector_def_from_table(std::string_view fullname, PStatCollectorDef *def) { int i; for (i = 0; diff --git a/panda/src/putil/animInterface.cxx b/panda/src/putil/animInterface.cxx index 304e4f95af4..a2b3407b262 100644 --- a/panda/src/putil/animInterface.cxx +++ b/panda/src/putil/animInterface.cxx @@ -232,7 +232,7 @@ loop(bool restart, double from, double to) { _paused_f = 0.0; if (!restart) { - fframe = min(max(fframe, from), to); + fframe = std::clamp(fframe, from, to); if (_paused) { _paused_f = fframe - _start_frame; } else { @@ -263,7 +263,7 @@ pingpong(bool restart, double from, double to) { _paused_f = 0.0; if (!restart) { - fframe = min(max(fframe, from), to); + fframe = std::clamp(fframe, from, to); if (_paused) { _paused_f = fframe - _start_frame; } else { @@ -302,7 +302,7 @@ get_full_frame(int increment) const { if (_play_mode == PM_play) { // In play mode, we never let the return value exceed (_from_frame, // _to_frame). - frame = min(max(frame, _from_frame), _to_frame); + frame = std::clamp(frame, _from_frame, _to_frame); } return frame; } @@ -326,7 +326,7 @@ get_full_fframe() const { return _start_frame; case PM_play: - return min(max(get_f(), 0.0), _play_frames) + _start_frame; + return std::clamp(get_f(), 0.0, _play_frames) + _start_frame; case PM_loop: nassertr(_play_frames >= 0.0, 0.0); diff --git a/panda/src/putil/bamCache.cxx b/panda/src/putil/bamCache.cxx index 47ec79a9cef..92f12d38e0d 100644 --- a/panda/src/putil/bamCache.cxx +++ b/panda/src/putil/bamCache.cxx @@ -162,7 +162,7 @@ set_root(const Filename &root) { * record to disk. */ PT(BamCacheRecord) BamCache:: -lookup(const Filename &source_filename, const string &cache_extension) { +lookup(const Filename &source_filename, std::string_view cache_extension) { ReMutexHolder holder(_lock); consider_flush_index(); @@ -1047,7 +1047,7 @@ reset_in_memory_index() { * fullpath string to the source filename. */ string BamCache:: -hash_filename(const string &filename) { +hash_filename(std::string_view filename) { // Use the MD5 hash of the filename. HashVal hv; hv.hash_string(filename); diff --git a/panda/src/putil/bamCache.h b/panda/src/putil/bamCache.h index 28a81f8d31a..691671f05bb 100644 --- a/panda/src/putil/bamCache.h +++ b/panda/src/putil/bamCache.h @@ -72,7 +72,7 @@ class EXPCL_PANDA_PUTIL BamCache { INLINE bool get_read_only() const; PT(BamCacheRecord) lookup(const Filename &source_filename, - const std::string &cache_extension); + std::string_view cache_extension); bool store(BamCacheRecord *record); void consider_flush_index(); @@ -125,7 +125,7 @@ class EXPCL_PANDA_PUTIL BamCache { static PT(BamCacheRecord) do_read_record(const Filename &cache_pathname, bool read_data); - static std::string hash_filename(const std::string &filename); + static std::string hash_filename(std::string_view filename); static void make_global(); bool _active; diff --git a/panda/src/putil/bamReader.cxx b/panda/src/putil/bamReader.cxx index 2d6fb3e211a..8a3047a2000 100644 --- a/panda/src/putil/bamReader.cxx +++ b/panda/src/putil/bamReader.cxx @@ -169,19 +169,22 @@ init() { * will be replaced (and deleted). */ void BamReader:: -set_aux_data(TypedWritable *obj, const string &name, BamReader::AuxData *data) { +set_aux_data(TypedWritable *obj, std::string name, BamReader::AuxData *data) { if (data == nullptr) { AuxDataTable::iterator ti = _aux_data.find(obj); if (ti != _aux_data.end()) { AuxDataNames &names = (*ti).second; - names.erase(name); + AuxDataNames::iterator ni = names.find(name); + if (ni != names.end()) { + names.erase(ni); + } if (names.empty()) { _aux_data.erase(ti); } } } else { - _aux_data[obj][name] = data; + _aux_data[obj][std::move(name)] = data; } } @@ -191,7 +194,7 @@ set_aux_data(TypedWritable *obj, const string &name, BamReader::AuxData *data) { * set. */ BamReader::AuxData *BamReader:: -get_aux_data(TypedWritable *obj, const string &name) const { +get_aux_data(TypedWritable *obj, std::string_view name) const { AuxDataTable::const_iterator ti = _aux_data.find(obj); if (ti != _aux_data.end()) { const AuxDataNames &names = (*ti).second; @@ -777,12 +780,12 @@ read_cdata(DatagramIterator &scan, PipelineCyclerBase &cycler, * be unique between an object and its CData object(s). */ void BamReader:: -set_int_tag(const string &tag, int value) { +set_int_tag(std::string tag, int value) { nassertv(_now_creating != _created_objs.end()); int requestor_id = (*_now_creating).first; PointerReference &pref = _object_pointers[requestor_id]; - pref._int_tags[tag] = value; + pref._int_tags[std::move(tag)] = value; } /** @@ -790,7 +793,7 @@ set_int_tag(const string &tag, int value) { * value has been set. */ int BamReader:: -get_int_tag(const string &tag) const { +get_int_tag(std::string_view tag) const { nassertr(_now_creating != _created_objs.end(), 0); int requestor_id = (*_now_creating).first; @@ -818,12 +821,12 @@ get_int_tag(const string &tag) const { * be unique between an object and its CData object(s). */ void BamReader:: -set_aux_tag(const string &tag, BamReaderAuxData *value) { +set_aux_tag(std::string tag, BamReaderAuxData *value) { nassertv(_now_creating != _created_objs.end()); int requestor_id = (*_now_creating).first; PointerReference &pref = _object_pointers[requestor_id]; - pref._aux_tags[tag] = value; + pref._aux_tags[std::move(tag)] = value; } /** @@ -831,7 +834,7 @@ set_aux_tag(const string &tag, BamReaderAuxData *value) { * value has been set. */ BamReaderAuxData *BamReader:: -get_aux_tag(const string &tag) const { +get_aux_tag(std::string_view tag) const { nassertr(_now_creating != _created_objs.end(), nullptr); int requestor_id = (*_now_creating).first; diff --git a/panda/src/putil/bamReader.h b/panda/src/putil/bamReader.h index dce156d9acf..7ed690edc21 100644 --- a/panda/src/putil/bamReader.h +++ b/panda/src/putil/bamReader.h @@ -124,8 +124,8 @@ class EXPCL_PANDA_PUTIL BamReader : public BamEnums { bool init(); class AuxData; - void set_aux_data(TypedWritable *obj, const std::string &name, AuxData *data); - AuxData *get_aux_data(TypedWritable *obj, const std::string &name) const; + void set_aux_data(TypedWritable *obj, std::string name, AuxData *data); + AuxData *get_aux_data(TypedWritable *obj, std::string_view name) const; INLINE const Filename &get_filename() const; @@ -176,11 +176,11 @@ class EXPCL_PANDA_PUTIL BamReader : public BamEnums { void read_cdata(DatagramIterator &scan, PipelineCyclerBase &cycler, void *extra_data); - void set_int_tag(const std::string &tag, int value); - int get_int_tag(const std::string &tag) const; + void set_int_tag(std::string tag, int value); + int get_int_tag(std::string_view tag) const; - void set_aux_tag(const std::string &tag, BamReaderAuxData *value); - BamReaderAuxData *get_aux_tag(const std::string &tag) const; + void set_aux_tag(std::string tag, BamReaderAuxData *value); + BamReaderAuxData *get_aux_tag(std::string_view tag) const; void register_finalize(TypedWritable *whom); @@ -292,8 +292,8 @@ class EXPCL_PANDA_PUTIL BamReader : public BamEnums { // which read_pointer() was called, so that we may call the appropriate // complete_pointers() later. typedef phash_map CyclerPointers; - typedef pmap IntTags; - typedef pmap AuxTags; + typedef pmap> IntTags; + typedef pmap> AuxTags; class PointerReference { public: vector_int _objects; @@ -338,7 +338,7 @@ class EXPCL_PANDA_PUTIL BamReader : public BamEnums { static NewTypes _new_types; // This is used in support of set_aux_data() and get_aux_data(). - typedef pmap AuxDataNames; + typedef pmap> AuxDataNames; typedef phash_map AuxDataTable; AuxDataTable _aux_data; diff --git a/panda/src/putil/bitMask.I b/panda/src/putil/bitMask.I index 8c85f6c46bd..57a6b8e2f1a 100644 --- a/panda/src/putil/bitMask.I +++ b/panda/src/putil/bitMask.I @@ -637,7 +637,7 @@ generate_hash(ChecksumHashGenerator &hashgen) const { */ template void BitMask:: -init_type(const std::string &name) { +init_type(std::string_view name) { register_type(_type_handle, name); } diff --git a/panda/src/putil/bitMask.cxx b/panda/src/putil/bitMask.cxx index cd200ab5656..d695a0ea4fb 100644 --- a/panda/src/putil/bitMask.cxx +++ b/panda/src/putil/bitMask.cxx @@ -20,7 +20,9 @@ template class BitMask; #if !defined(CPPPARSER) && !defined(__APPLE__) #include +#if __cplusplus < 201703L static_assert(std::is_literal_type::value, "BitMask16 is not a literal type"); static_assert(std::is_literal_type::value, "BitMask32 is not a literal type"); static_assert(std::is_literal_type::value, "BitMask64 is not a literal type"); #endif +#endif diff --git a/panda/src/putil/bitMask.h b/panda/src/putil/bitMask.h index 7f3b9e0858b..983e3a7ffbc 100644 --- a/panda/src/putil/bitMask.h +++ b/panda/src/putil/bitMask.h @@ -139,7 +139,7 @@ class BitMask { static TypeHandle get_class_type() { return _type_handle; } - static void init_type(const std::string &name); + static void init_type(std::string_view name); private: static TypeHandle _type_handle; diff --git a/panda/src/putil/buttonHandle.cxx b/panda/src/putil/buttonHandle.cxx index 4ce3cd5a911..7ee4cbeeefe 100644 --- a/panda/src/putil/buttonHandle.cxx +++ b/panda/src/putil/buttonHandle.cxx @@ -24,7 +24,7 @@ TypeHandle ButtonHandle::_type_handle; * ButtonRegistry::register_button(). */ ButtonHandle:: -ButtonHandle(const std::string &name) { +ButtonHandle(std::string_view name) { _index = ButtonRegistry::ptr()->get_button(name)._index; } diff --git a/panda/src/putil/buttonHandle.h b/panda/src/putil/buttonHandle.h index 6c47a7df2df..3fc3d20880e 100644 --- a/panda/src/putil/buttonHandle.h +++ b/panda/src/putil/buttonHandle.h @@ -31,7 +31,7 @@ class EXPCL_PANDA_PUTIL ButtonHandle final { // previously by another static initializer! INLINE ButtonHandle() = default; explicit constexpr ButtonHandle(int index); - ButtonHandle(const std::string &name); + ButtonHandle(std::string_view name); PUBLISHED: INLINE bool operator == (const ButtonHandle &other) const; diff --git a/panda/src/putil/buttonMap.I b/panda/src/putil/buttonMap.I index 49cb2f9931b..0af135e1ca0 100644 --- a/panda/src/putil/buttonMap.I +++ b/panda/src/putil/buttonMap.I @@ -67,7 +67,7 @@ get_mapped_button(ButtonHandle raw) const { * given raw button. */ INLINE ButtonHandle ButtonMap:: -get_mapped_button(const std::string &raw_name) const { +get_mapped_button(std::string_view raw_name) const { ButtonHandle raw_button = ButtonRegistry::ptr()->find_button(raw_name); if (raw_button == ButtonHandle::none()) { return ButtonHandle::none(); @@ -105,7 +105,7 @@ get_mapped_button_label(ButtonHandle raw) const { * returns the name of the Panda event associated with the button. */ INLINE const std::string &ButtonMap:: -get_mapped_button_label(const std::string &raw_name) const { +get_mapped_button_label(std::string_view raw_name) const { ButtonHandle raw_button = ButtonRegistry::ptr()->find_button(raw_name); if (raw_button == ButtonHandle::none()) { static const std::string empty = ""; diff --git a/panda/src/putil/buttonMap.cxx b/panda/src/putil/buttonMap.cxx index 2e74d929ce9..008065c358e 100644 --- a/panda/src/putil/buttonMap.cxx +++ b/panda/src/putil/buttonMap.cxx @@ -20,7 +20,7 @@ TypeHandle ButtonMap::_type_handle; * Registers a new button mapping. */ void ButtonMap:: -map_button(ButtonHandle raw_button, ButtonHandle button, const std::string &label) { +map_button(ButtonHandle raw_button, ButtonHandle button, std::string label) { int index = raw_button.get_index(); if (_button_map.find(index) != _button_map.end()) { // A button with this index was already mapped. @@ -30,8 +30,8 @@ map_button(ButtonHandle raw_button, ButtonHandle button, const std::string &labe ButtonNode bnode; bnode._raw = raw_button; bnode._mapped = button; - bnode._label = label; - _button_map[index] = bnode; + bnode._label = std::move(label); + _button_map[index] = std::move(bnode); _buttons.push_back(&_button_map[index]); } diff --git a/panda/src/putil/buttonMap.h b/panda/src/putil/buttonMap.h index fca64c1146a..2b5ee1f8dd8 100644 --- a/panda/src/putil/buttonMap.h +++ b/panda/src/putil/buttonMap.h @@ -35,15 +35,15 @@ class EXPCL_PANDA_PUTIL ButtonMap : public TypedReferenceCount { INLINE const std::string &get_mapped_button_label(size_t i) const; INLINE ButtonHandle get_mapped_button(ButtonHandle raw) const; - INLINE ButtonHandle get_mapped_button(const std::string &raw_name) const; + INLINE ButtonHandle get_mapped_button(std::string_view raw_name) const; INLINE const std::string &get_mapped_button_label(ButtonHandle raw) const; - INLINE const std::string &get_mapped_button_label(const std::string &raw_name) const; + INLINE const std::string &get_mapped_button_label(std::string_view raw_name) const; void output(std::ostream &out) const; void write(std::ostream &out, int indent_level = 0) const; public: - void map_button(ButtonHandle raw_button, ButtonHandle button, const std::string &label = ""); + void map_button(ButtonHandle raw_button, ButtonHandle button, std::string label = ""); private: struct ButtonNode { diff --git a/panda/src/putil/buttonRegistry.I b/panda/src/putil/buttonRegistry.I index 74fe89471cf..f7b8c70632e 100644 --- a/panda/src/putil/buttonRegistry.I +++ b/panda/src/putil/buttonRegistry.I @@ -17,8 +17,8 @@ * */ INLINE ButtonRegistry::RegistryNode:: -RegistryNode(ButtonHandle handle, ButtonHandle alias, const std::string &name) : - _handle(handle), _alias(alias), _name(name) +RegistryNode(ButtonHandle handle, ButtonHandle alias, std::string name) : + _handle(handle), _alias(alias), _name(std::move(name)) { } diff --git a/panda/src/putil/buttonRegistry.cxx b/panda/src/putil/buttonRegistry.cxx index 1800d9e88ac..2dd12b5e0c3 100644 --- a/panda/src/putil/buttonRegistry.cxx +++ b/panda/src/putil/buttonRegistry.cxx @@ -41,7 +41,7 @@ ButtonRegistry *ButtonRegistry::_global_pointer = nullptr; * right. */ bool ButtonRegistry:: -register_button(ButtonHandle &button_handle, const std::string &name, +register_button(ButtonHandle &button_handle, std::string name, ButtonHandle alias, char ascii_equivalent) { NameRegistry::iterator ri; ri = _name_registry.find(name); @@ -79,9 +79,9 @@ register_button(ButtonHandle &button_handle, const std::string &name, ButtonHandle new_handle; new_handle._index = index; - RegistryNode *rnode = new RegistryNode(new_handle, alias, name); + RegistryNode *rnode = new RegistryNode(new_handle, alias, std::move(name)); _handle_registry[index] = rnode; - _name_registry[name] = rnode; + _name_registry[rnode->_name] = rnode; button_handle = new_handle; return true; @@ -109,7 +109,7 @@ register_button(ButtonHandle &button_handle, const std::string &name, * is no such ButtonHandle, registers a new one and returns it. */ ButtonHandle ButtonRegistry:: -get_button(const std::string &name) { +get_button(std::string_view name) { NameRegistry::const_iterator ri; ri = _name_registry.find(name); @@ -118,7 +118,7 @@ get_button(const std::string &name) { } ButtonHandle button; - register_button(button, name); + register_button(button, std::string(name)); return button; } @@ -127,7 +127,7 @@ get_button(const std::string &name) { * is no such ButtonHandle, returns ButtonHandle::none(). */ ButtonHandle ButtonRegistry:: -find_button(const std::string &name) { +find_button(std::string_view name) { NameRegistry::const_iterator ri; ri = _name_registry.find(name); diff --git a/panda/src/putil/buttonRegistry.h b/panda/src/putil/buttonRegistry.h index 19a315ae901..23d30c94698 100644 --- a/panda/src/putil/buttonRegistry.h +++ b/panda/src/putil/buttonRegistry.h @@ -31,7 +31,7 @@ class EXPCL_PANDA_PUTIL ButtonRegistry { class EXPCL_PANDA_PUTIL RegistryNode { public: INLINE RegistryNode(ButtonHandle handle, ButtonHandle alias, - const std::string &name); + std::string name); ButtonHandle _handle; ButtonHandle _alias; @@ -39,13 +39,13 @@ class EXPCL_PANDA_PUTIL ButtonRegistry { }; public: - bool register_button(ButtonHandle &button_handle, const std::string &name, + bool register_button(ButtonHandle &button_handle, std::string name, ButtonHandle alias = ButtonHandle::none(), char ascii_equivalent = '\0'); PUBLISHED: - ButtonHandle get_button(const std::string &name); - ButtonHandle find_button(const std::string &name); + ButtonHandle get_button(std::string_view name); + ButtonHandle find_button(std::string_view name); ButtonHandle find_ascii_button(char ascii_equivalent) const; void write(std::ostream &out) const; @@ -69,7 +69,7 @@ class EXPCL_PANDA_PUTIL ButtonRegistry { typedef pvector HandleRegistry; HandleRegistry _handle_registry; - typedef pmap NameRegistry; + typedef pmap> NameRegistry; NameRegistry _name_registry; static ButtonRegistry *_global_pointer; diff --git a/panda/src/putil/colorSpace.cxx b/panda/src/putil/colorSpace.cxx index 3a244a68eb9..95722776b9d 100644 --- a/panda/src/putil/colorSpace.cxx +++ b/panda/src/putil/colorSpace.cxx @@ -27,7 +27,7 @@ using std::ostringstream; using std::string; ColorSpace -parse_color_space_string(const string &str) { +parse_color_space_string(std::string_view str) { if (cmp_nocase_uh(str, "linear") == 0 || cmp_nocase_uh(str, "linear-rgb") == 0 || cmp_nocase_uh(str, "lrgb") == 0) { diff --git a/panda/src/putil/colorSpace.h b/panda/src/putil/colorSpace.h index 569ee2f8b83..cdc033d1683 100644 --- a/panda/src/putil/colorSpace.h +++ b/panda/src/putil/colorSpace.h @@ -40,7 +40,7 @@ enum ColorSpace { CS_scRGB, }; -EXPCL_PANDA_PUTIL ColorSpace parse_color_space_string(const std::string &str); +EXPCL_PANDA_PUTIL ColorSpace parse_color_space_string(std::string_view str); EXPCL_PANDA_PUTIL std::string format_color_space(ColorSpace cs); END_PUBLISH diff --git a/panda/src/putil/completionCounter.I b/panda/src/putil/completionCounter.I index 6d591433607..07ef0418e1c 100644 --- a/panda/src/putil/completionCounter.I +++ b/panda/src/putil/completionCounter.I @@ -83,7 +83,7 @@ then(Callable callable) && { return; } - Callable *callable = (Callable *)data->_storage; + Callable *callable = std::launder(reinterpret_cast(data->_storage)); std::move(*callable)(success && (prev_count & ~0xffff) == 0); callable->~Callable(); delete data; diff --git a/panda/src/putil/datagramBuffer.cxx b/panda/src/putil/datagramBuffer.cxx index 7b1acb4ba1c..e4368a5d2a8 100644 --- a/panda/src/putil/datagramBuffer.cxx +++ b/panda/src/putil/datagramBuffer.cxx @@ -20,7 +20,7 @@ * written. */ bool DatagramBuffer:: -write_header(const std::string &header) { +write_header(std::string_view header) { nassertr(!_wrote_first_datagram, false); _data.insert(_data.end(), header.begin(), header.end()); diff --git a/panda/src/putil/datagramBuffer.h b/panda/src/putil/datagramBuffer.h index 7990b36e716..59e07fc2db7 100644 --- a/panda/src/putil/datagramBuffer.h +++ b/panda/src/putil/datagramBuffer.h @@ -35,7 +35,7 @@ class EXPCL_PANDA_PUTIL DatagramBuffer : public DatagramSink, public DatagramGen INLINE void clear(); public: - bool write_header(const std::string &header); + bool write_header(std::string_view header); virtual bool put_datagram(const Datagram &data) override; virtual void flush() override; diff --git a/panda/src/putil/datagramOutputFile.cxx b/panda/src/putil/datagramOutputFile.cxx index 73c816fdd73..930ac4c5df4 100644 --- a/panda/src/putil/datagramOutputFile.cxx +++ b/panda/src/putil/datagramOutputFile.cxx @@ -109,7 +109,7 @@ write_header(const vector_uchar &header) { * written. */ bool DatagramOutputFile:: -write_header(const std::string &header) { +write_header(std::string_view header) { nassertr(_out != nullptr, false); nassertr(!_wrote_first_datagram, false); diff --git a/panda/src/putil/datagramOutputFile.h b/panda/src/putil/datagramOutputFile.h index fbc88e0bcd5..3a42ff896a1 100644 --- a/panda/src/putil/datagramOutputFile.h +++ b/panda/src/putil/datagramOutputFile.h @@ -39,7 +39,7 @@ class EXPCL_PANDA_PUTIL DatagramOutputFile : public DatagramSink { void close(); bool write_header(const vector_uchar &header); - bool write_header(const std::string &header); + bool write_header(std::string_view header); virtual bool put_datagram(const Datagram &data); virtual bool copy_datagram(SubfileInfo &result, const Filename &filename); virtual bool copy_datagram(SubfileInfo &result, const SubfileInfo &source); diff --git a/panda/src/putil/doubleBitMask.cxx b/panda/src/putil/doubleBitMask.cxx index ff651eea613..29778e29dd6 100644 --- a/panda/src/putil/doubleBitMask.cxx +++ b/panda/src/putil/doubleBitMask.cxx @@ -19,6 +19,8 @@ template class DoubleBitMask; #if !defined(CPPPARSER) && !defined(__APPLE__) #include +#if __cplusplus < 201703L static_assert(std::is_literal_type::value, "DoubleBitMaskNative is not a literal type"); static_assert(std::is_literal_type::value, "QuadBitMaskNative is not a literal type"); #endif +#endif diff --git a/panda/src/putil/factory.I b/panda/src/putil/factory.I index bfd170af40a..1543d40363f 100644 --- a/panda/src/putil/factory.I +++ b/panda/src/putil/factory.I @@ -34,7 +34,7 @@ make_instance(TypeHandle handle, const FactoryParams ¶ms) { */ template INLINE Type *Factory:: -make_instance(const std::string &type_name, const FactoryParams ¶ms) { +make_instance(std::string_view type_name, const FactoryParams ¶ms) { return (Type *)FactoryBase::make_instance(type_name, params); } @@ -60,7 +60,7 @@ make_instance_more_general(TypeHandle handle, const FactoryParams ¶ms) { */ template INLINE Type *Factory:: -make_instance_more_general(const std::string &type_name, +make_instance_more_general(std::string_view type_name, const FactoryParams ¶ms) { return (Type *)FactoryBase::make_instance_more_general(type_name, params); } diff --git a/panda/src/putil/factory.h b/panda/src/putil/factory.h index 03c1fb6f376..2c79cab1f5a 100644 --- a/panda/src/putil/factory.h +++ b/panda/src/putil/factory.h @@ -38,7 +38,7 @@ class Factory : public FactoryBase { INLINE Type *make_instance(TypeHandle handle, const FactoryParams ¶ms = FactoryParams()); - INLINE Type *make_instance(const std::string &type_name, + INLINE Type *make_instance(std::string_view type_name, const FactoryParams ¶ms = FactoryParams()); INLINE Type * @@ -46,7 +46,7 @@ class Factory : public FactoryBase { const FactoryParams ¶ms = FactoryParams()); INLINE Type * - make_instance_more_general(const std::string &type_name, + make_instance_more_general(std::string_view type_name, const FactoryParams ¶ms = FactoryParams()); INLINE void register_factory(TypeHandle handle, CreateFunc *func, diff --git a/panda/src/putil/factoryBase.I b/panda/src/putil/factoryBase.I index 3d93306a4ea..5fac4224b73 100644 --- a/panda/src/putil/factoryBase.I +++ b/panda/src/putil/factoryBase.I @@ -21,7 +21,7 @@ * desired type. It must be the name of some already-registered type. */ INLINE TypedObject *FactoryBase:: -make_instance(const std::string &type_name, const FactoryParams ¶ms) { +make_instance(std::string_view type_name, const FactoryParams ¶ms) { TypeHandle handle = TypeRegistry::ptr()->find_type(type_name); nassertr(handle != TypeHandle::none(), nullptr); @@ -39,7 +39,7 @@ make_instance(const std::string &type_name, const FactoryParams ¶ms) { * type. */ INLINE TypedObject *FactoryBase:: -make_instance_more_general(const std::string &type_name, +make_instance_more_general(std::string_view type_name, const FactoryParams ¶ms) { TypeHandle handle = TypeRegistry::ptr()->find_type(type_name); nassertr(handle != TypeHandle::none(), nullptr); diff --git a/panda/src/putil/factoryBase.h b/panda/src/putil/factoryBase.h index 65617f254b0..93a135968ab 100644 --- a/panda/src/putil/factoryBase.h +++ b/panda/src/putil/factoryBase.h @@ -48,13 +48,13 @@ class EXPCL_PANDA_PUTIL FactoryBase { TypedObject *make_instance(TypeHandle handle, const FactoryParams ¶ms); - INLINE TypedObject *make_instance(const std::string &type_name, + INLINE TypedObject *make_instance(std::string_view type_name, const FactoryParams ¶ms); TypedObject *make_instance_more_general(TypeHandle handle, const FactoryParams ¶ms); - INLINE TypedObject *make_instance_more_general(const std::string &type_name, + INLINE TypedObject *make_instance_more_general(std::string_view type_name, const FactoryParams ¶ms); TypeHandle find_registered_type(TypeHandle handle); diff --git a/panda/src/putil/load_prc_file.cxx b/panda/src/putil/load_prc_file.cxx index e2755185bba..863cfa6a364 100644 --- a/panda/src/putil/load_prc_file.cxx +++ b/panda/src/putil/load_prc_file.cxx @@ -78,12 +78,12 @@ load_prc_file(const Filename &filename) { * loaded prc files is listed. */ EXPCL_PANDA_PUTIL ConfigPage * -load_prc_file_data(const std::string &name, const std::string &data) { +load_prc_file_data(std::string name, const std::string &data) { std::istringstream strm(data); ConfigPageManager *cp_mgr = ConfigPageManager::get_global_ptr(); - ConfigPage *page = cp_mgr->make_explicit_page(name); + ConfigPage *page = cp_mgr->make_explicit_page(std::move(name)); bool read_ok = page->read_prc(strm); if (read_ok) { diff --git a/panda/src/putil/load_prc_file.h b/panda/src/putil/load_prc_file.h index 5a67e4fd455..7f8d8b34bd1 100644 --- a/panda/src/putil/load_prc_file.h +++ b/panda/src/putil/load_prc_file.h @@ -47,7 +47,7 @@ load_prc_file(const Filename &filename); * loaded prc files is listed. */ EXPCL_PANDA_PUTIL ConfigPage * -load_prc_file_data(const std::string &name, const std::string &data); +load_prc_file_data(std::string name, const std::string &data); /** * Unloads (and deletes) a ConfigPage that represents a prc file that was diff --git a/panda/src/putil/loaderOptions.cxx b/panda/src/putil/loaderOptions.cxx index adaa6783dd7..7c0b55aa01f 100644 --- a/panda/src/putil/loaderOptions.cxx +++ b/panda/src/putil/loaderOptions.cxx @@ -107,7 +107,7 @@ output(std::ostream &out) const { */ void LoaderOptions:: write_flag(std::ostream &out, string &sep, - const string &flag_name, int flag) const { + std::string_view flag_name, int flag) const { if ((_flags & flag) == flag) { out << sep << flag_name; sep = " | "; @@ -119,7 +119,7 @@ write_flag(std::ostream &out, string &sep, */ void LoaderOptions:: write_texture_flag(std::ostream &out, string &sep, - const string &flag_name, int flag) const { + std::string_view flag_name, int flag) const { if ((_texture_flags & flag) == flag) { out << sep << flag_name; sep = " | "; diff --git a/panda/src/putil/loaderOptions.h b/panda/src/putil/loaderOptions.h index a8e39e00664..369b2fbdade 100644 --- a/panda/src/putil/loaderOptions.h +++ b/panda/src/putil/loaderOptions.h @@ -81,9 +81,9 @@ class EXPCL_PANDA_PUTIL LoaderOptions { private: void write_flag(std::ostream &out, std::string &sep, - const std::string &flag_name, int flag) const; + std::string_view flag_name, int flag) const; void write_texture_flag(std::ostream &out, std::string &sep, - const std::string &flag_name, int flag) const; + std::string_view flag_name, int flag) const; int _flags; int _texture_flags; int _texture_format; diff --git a/panda/src/putil/nameUniquifier.I b/panda/src/putil/nameUniquifier.I index 760dad2dfc8..faa3b6168fa 100644 --- a/panda/src/putil/nameUniquifier.I +++ b/panda/src/putil/nameUniquifier.I @@ -25,7 +25,7 @@ * NameUniquifier's "separator" string, followed by a number. */ INLINE std::string NameUniquifier:: -add_name(const std::string &name) { +add_name(std::string_view name) { return add_name_body(name, name); } @@ -43,6 +43,6 @@ add_name(const std::string &name) { * NameUniquifier's "separator" string, followed by a number. */ INLINE std::string NameUniquifier:: -add_name(const std::string &name, const std::string &prefix) { +add_name(std::string_view name, std::string_view prefix) { return add_name_body(name, prefix); } diff --git a/panda/src/putil/nameUniquifier.cxx b/panda/src/putil/nameUniquifier.cxx index e6ab3f69170..26945576c3a 100644 --- a/panda/src/putil/nameUniquifier.cxx +++ b/panda/src/putil/nameUniquifier.cxx @@ -30,10 +30,10 @@ using std::string; * generated number. */ NameUniquifier:: -NameUniquifier(const string &separator, - const string &empty) : - _separator(separator), - _empty(empty) +NameUniquifier(std::string separator, + std::string empty) : + _separator(std::move(separator)), + _empty(std::move(empty)) { _counter = 0; @@ -65,12 +65,14 @@ NameUniquifier:: * NameUniquifier's "separator" string, followed by a number. */ string NameUniquifier:: -add_name_body(const string &name, const string &prefix) { +add_name_body(std::string_view name, std::string_view prefix) { if (!name.empty()) { - if (_names.insert(name).second) { + std::string str(name); + auto result = _names.insert(std::move(str)); + if (result.second) { // The name was successfully inserted into the set; therefore, it's // unique. Return it. - return name; + return *result.first; } } @@ -88,7 +90,10 @@ add_name_body(const string &name, const string &prefix) { if (prefix.empty()) { temp_name = _empty + num_str; } else { - temp_name = prefix + _separator + num_str; + temp_name.clear(); + temp_name += prefix; + temp_name += _separator; + temp_name += num_str; } } while (!_names.insert(temp_name).second); diff --git a/panda/src/putil/nameUniquifier.h b/panda/src/putil/nameUniquifier.h index 1d3c3e25605..68d23e0f28d 100644 --- a/panda/src/putil/nameUniquifier.h +++ b/panda/src/putil/nameUniquifier.h @@ -27,15 +27,15 @@ */ class EXPCL_PANDA_PUTIL NameUniquifier { public: - NameUniquifier(const std::string &separator = std::string(), - const std::string &empty = std::string()); + NameUniquifier(std::string separator = std::string(), + std::string empty = std::string()); ~NameUniquifier(); - INLINE std::string add_name(const std::string &name); - INLINE std::string add_name(const std::string &name, const std::string &prefix); + INLINE std::string add_name(std::string_view name); + INLINE std::string add_name(std::string_view name, std::string_view prefix); private: - std::string add_name_body(const std::string &name, const std::string &prefix); + std::string add_name_body(std::string_view name, std::string_view prefix); typedef pset Names; Names _names; diff --git a/panda/src/putil/paramValue.I b/panda/src/putil/paramValue.I index 0f44d4d54e7..2f30713687c 100644 --- a/panda/src/putil/paramValue.I +++ b/panda/src/putil/paramValue.I @@ -70,8 +70,8 @@ ParamValue() {} */ template INLINE ParamValue:: -ParamValue(const Type &value) : - _value(value) +ParamValue(Type value) : + _value(std::move(value)) { } diff --git a/panda/src/putil/paramValue.h b/panda/src/putil/paramValue.h index f98e76d3f14..9bfa11ec9a3 100644 --- a/panda/src/putil/paramValue.h +++ b/panda/src/putil/paramValue.h @@ -105,7 +105,7 @@ class ParamValue : public ParamValueBase { INLINE ParamValue(); PUBLISHED: - INLINE ParamValue(const Type &value); + INLINE ParamValue(Type value); INLINE virtual ~ParamValue(); INLINE virtual TypeHandle get_value_type() const; @@ -131,7 +131,7 @@ class ParamValue : public ParamValueBase { static TypeHandle get_class_type() { return _type_handle; } - static void init_type(const std::string &type_name = "UndefinedParamValue") { + static void init_type(std::string_view type_name = "UndefinedParamValue") { ParamValueBase::init_type(); _type_handle = register_dynamic_type (type_name, ParamValueBase::get_class_type()); diff --git a/panda/src/putil/test_bam.h b/panda/src/putil/test_bam.h index 1570f1541ac..44259f7bd59 100644 --- a/panda/src/putil/test_bam.h +++ b/panda/src/putil/test_bam.h @@ -53,8 +53,8 @@ class Person : public TypedWritableReferenceCount { public: Person() {} - Person(const std::string &name, const sex Gender) : - _name(name), myGender(Gender), _bro(nullptr), _sis(nullptr) { + Person(std::string name, const sex Gender) : + _name(std::move(name)), myGender(Gender), _bro(nullptr), _sis(nullptr) { } virtual ~Person() { @@ -100,7 +100,7 @@ class Parent : public Person { public: Parent() {} - Parent(const std::string &name, const sex Gender) : Person(name, Gender) { + Parent(std::string name, const sex Gender) : Person(std::move(name), Gender) { } virtual ~Parent() { @@ -146,7 +146,7 @@ class Child : public Person { public: Child() {} - Child(const std::string &name, const sex Gender) : Person(name, Gender) { + Child(std::string name, const sex Gender) : Person(std::move(name), Gender) { } virtual ~Child() { diff --git a/panda/src/putil/updateSeq.I b/panda/src/putil/updateSeq.I index 42f6fa4c83f..d3a41779af6 100644 --- a/panda/src/putil/updateSeq.I +++ b/panda/src/putil/updateSeq.I @@ -14,14 +14,14 @@ /** * Creates an UpdateSeq in the given state. */ -INLINE UpdateSeq:: +constexpr UpdateSeq:: UpdateSeq(unsigned int seq) : _seq(seq) { } /** * Creates an UpdateSeq in the 'initial' state. */ -INLINE UpdateSeq:: +constexpr UpdateSeq:: UpdateSeq() : _seq((unsigned int)SC_initial) { } diff --git a/panda/src/putil/updateSeq.h b/panda/src/putil/updateSeq.h index 3332490f634..8fc8aa3280a 100644 --- a/panda/src/putil/updateSeq.h +++ b/panda/src/putil/updateSeq.h @@ -36,13 +36,13 @@ */ class EXPCL_PANDA_PUTIL UpdateSeq { private: - INLINE UpdateSeq(unsigned int seq); + constexpr UpdateSeq(unsigned int seq); PUBLISHED: - INLINE UpdateSeq(); - INLINE static UpdateSeq initial() { return UpdateSeq(SC_initial); } - INLINE static UpdateSeq old() { return UpdateSeq(SC_old); } - INLINE static UpdateSeq fresh() { return UpdateSeq(SC_fresh); } + constexpr UpdateSeq(); + constexpr static UpdateSeq initial() { return UpdateSeq(SC_initial); } + constexpr static UpdateSeq old() { return UpdateSeq(SC_old); } + constexpr static UpdateSeq fresh() { return UpdateSeq(SC_fresh); } INLINE UpdateSeq(const UpdateSeq ©); INLINE UpdateSeq(const UpdateSeq &&from) noexcept; diff --git a/panda/src/recorder/mouseRecorder.cxx b/panda/src/recorder/mouseRecorder.cxx index 04b2e8c4467..74a1be622c8 100644 --- a/panda/src/recorder/mouseRecorder.cxx +++ b/panda/src/recorder/mouseRecorder.cxx @@ -23,8 +23,8 @@ TypeHandle MouseRecorder::_type_handle; * */ MouseRecorder:: -MouseRecorder(const std::string &name) : - DataNode(name) +MouseRecorder(std::string name) : + DataNode(std::move(name)) { _pixel_xy_input = define_input("pixel_xy", EventStoreVec2::get_class_type()); _pixel_size_input = define_input("pixel_size", EventStoreVec2::get_class_type()); diff --git a/panda/src/recorder/mouseRecorder.h b/panda/src/recorder/mouseRecorder.h index 1c29a42152e..43f01da721c 100644 --- a/panda/src/recorder/mouseRecorder.h +++ b/panda/src/recorder/mouseRecorder.h @@ -33,7 +33,7 @@ class BamWriter; */ class EXPCL_PANDA_RECORDER MouseRecorder : public DataNode, public RecorderBase { PUBLISHED: - explicit MouseRecorder(const std::string &name); + explicit MouseRecorder(std::string name); virtual ~MouseRecorder(); public: diff --git a/panda/src/recorder/recorderController.I b/panda/src/recorder/recorderController.I index 7960a78ea1b..f4c2ea1cc00 100644 --- a/panda/src/recorder/recorderController.I +++ b/panda/src/recorder/recorderController.I @@ -115,8 +115,8 @@ get_frame_offset() const { * recorder will begin receiving data. */ INLINE void RecorderController:: -add_recorder(const std::string &name, RecorderBase *recorder) { - _user_table->add_recorder(name, recorder); +add_recorder(std::string name, RecorderBase *recorder) { + _user_table->add_recorder(std::move(name), recorder); _user_table_modified = true; // We can only add the state flag immediately if we are in recording mode. @@ -137,7 +137,7 @@ add_recorder(const std::string &name, RecorderBase *recorder) { * via add_recorder(); see get_recorder(). */ INLINE bool RecorderController:: -has_recorder(const std::string &name) const { +has_recorder(std::string_view name) const { return (_user_table->get_recorder(name) != nullptr); } @@ -151,7 +151,7 @@ has_recorder(const std::string &name) const { * return false, but get_recorder() will return a non-NULL value. */ INLINE RecorderBase *RecorderController:: -get_recorder(const std::string &name) const { +get_recorder(std::string_view name) const { RecorderBase *recorder = _user_table->get_recorder(name); if (is_playing() && recorder == nullptr) { recorder = _active_table->get_recorder(name); @@ -170,7 +170,7 @@ get_recorder(const std::string &name) const { * the data from the session file). */ INLINE bool RecorderController:: -remove_recorder(const std::string &name) { +remove_recorder(std::string_view name) { // If we are playing or recording, immediately remove the state flag from // the recorder. (When we are playing, the state flag will get removed // automatically at the next call to play_frame(), but we might as well be diff --git a/panda/src/recorder/recorderController.h b/panda/src/recorder/recorderController.h index d3d8ccd1fd1..824e27374d9 100644 --- a/panda/src/recorder/recorderController.h +++ b/panda/src/recorder/recorderController.h @@ -52,10 +52,10 @@ class EXPCL_PANDA_RECORDER RecorderController : public TypedReferenceCount { INLINE double get_clock_offset() const; INLINE int get_frame_offset() const; - INLINE void add_recorder(const std::string &name, RecorderBase *recorder); - INLINE bool has_recorder(const std::string &name) const; - INLINE RecorderBase *get_recorder(const std::string &name) const; - INLINE bool remove_recorder(const std::string &name); + INLINE void add_recorder(std::string name, RecorderBase *recorder); + INLINE bool has_recorder(std::string_view name) const; + INLINE RecorderBase *get_recorder(std::string_view name) const; + INLINE bool remove_recorder(std::string_view name); INLINE void set_frame_tie(bool frame_tie); INLINE bool get_frame_tie() const; diff --git a/panda/src/recorder/recorderTable.I b/panda/src/recorder/recorderTable.I index 18e66bc3ee3..d76689249e7 100644 --- a/panda/src/recorder/recorderTable.I +++ b/panda/src/recorder/recorderTable.I @@ -45,12 +45,12 @@ operator = (const RecorderTable ©) { * Adds the named recorder to the set of recorders. */ INLINE void RecorderTable:: -add_recorder(const std::string &name, RecorderBase *recorder) { +add_recorder(std::string name, RecorderBase *recorder) { nassertv(recorder != nullptr); recorder->ref(); std::pair result = - _recorders.insert(Recorders::value_type(name, recorder)); + _recorders.insert(Recorders::value_type(std::move(name), recorder)); if (!result.second) { // Take out the previous one first. @@ -64,7 +64,7 @@ add_recorder(const std::string &name, RecorderBase *recorder) { * recorder. */ INLINE RecorderBase *RecorderTable:: -get_recorder(const std::string &name) const { +get_recorder(std::string_view name) const { Recorders::const_iterator ri = _recorders.find(name); if (ri != _recorders.end()) { return (*ri).second; @@ -77,7 +77,7 @@ get_recorder(const std::string &name) const { * false if there was no such recorder. */ INLINE bool RecorderTable:: -remove_recorder(const std::string &name) { +remove_recorder(std::string_view name) { Recorders::iterator ri = _recorders.find(name); if (ri != _recorders.end()) { unref_delete(ri->second); diff --git a/panda/src/recorder/recorderTable.h b/panda/src/recorder/recorderTable.h index 8c6d1bf4123..842bc6b8629 100644 --- a/panda/src/recorder/recorderTable.h +++ b/panda/src/recorder/recorderTable.h @@ -38,9 +38,9 @@ class EXPCL_PANDA_RECORDER RecorderTable : public TypedWritable { void merge_from(const RecorderTable &other); - INLINE void add_recorder(const std::string &name, RecorderBase *recorder); - INLINE RecorderBase *get_recorder(const std::string &name) const; - INLINE bool remove_recorder(const std::string &name); + INLINE void add_recorder(std::string name, RecorderBase *recorder); + INLINE RecorderBase *get_recorder(std::string_view name) const; + INLINE bool remove_recorder(std::string_view name); void record_frame(BamWriter *manager, Datagram &dg); void play_frame(DatagramIterator &scan, BamReader *manager); @@ -52,7 +52,7 @@ class EXPCL_PANDA_RECORDER RecorderTable : public TypedWritable { // RecorderBase itself doesn't inherit from ReferenceCount, so we can't put // a PT() around it. Instead, we manage the reference count using calls to // ref() and unref(). - typedef pmap Recorders; + typedef pmap> Recorders; Recorders _recorders; bool _error; diff --git a/panda/src/testbed/pview.cxx b/panda/src/testbed/pview.cxx index 367736e095d..f9c9fd0ca35 100644 --- a/panda/src/testbed/pview.cxx +++ b/panda/src/testbed/pview.cxx @@ -251,8 +251,8 @@ report_version() { // class AdjustCameraClipPlanesTask : public AsyncTask { public: - AdjustCameraClipPlanesTask(const std::string &name, Camera *camera) : - AsyncTask(name), _camera(camera), _lens(camera->get_lens(0)), _sphere(nullptr) + AdjustCameraClipPlanesTask(std::string name, Camera *camera) : + AsyncTask(std::move(name)), _camera(camera), _lens(camera->get_lens(0)), _sphere(nullptr) { NodePath np = framework.get_models(); PT(BoundingVolume) volume = np.get_bounds(); diff --git a/panda/src/text/fontPool.I b/panda/src/text/fontPool.I index 319d12905b4..87309ed4f9a 100644 --- a/panda/src/text/fontPool.I +++ b/panda/src/text/fontPool.I @@ -15,7 +15,7 @@ * Returns true if the font has ever been loaded, false otherwise. */ INLINE bool FontPool:: -has_font(const std::string &filename) { +has_font(std::string_view filename) { return get_ptr()->ns_has_font(filename); } @@ -26,7 +26,7 @@ has_font(const std::string &filename) { * with the same font name will return a valid Font pointer. */ INLINE bool FontPool:: -verify_font(const std::string &filename) { +verify_font(std::string_view filename) { return load_font(filename) != nullptr; } @@ -37,7 +37,7 @@ verify_font(const std::string &filename) { * returns NULL. */ INLINE TextFont *FontPool:: -load_font(const std::string &filename) { +load_font(std::string_view filename) { return get_ptr()->ns_load_font(filename); } @@ -46,7 +46,7 @@ load_font(const std::string &filename) { * replace any previously-loaded font in the pool that had the same filename. */ INLINE void FontPool:: -add_font(const std::string &filename, TextFont *font) { +add_font(std::string_view filename, TextFont *font) { get_ptr()->ns_add_font(filename, font); } @@ -57,7 +57,7 @@ add_font(const std::string &filename, TextFont *font) { * and fonts will never be freed. */ INLINE void FontPool:: -release_font(const std::string &filename) { +release_font(std::string_view filename) { get_ptr()->ns_release_font(filename); } diff --git a/panda/src/text/fontPool.cxx b/panda/src/text/fontPool.cxx index 3f012437710..3351e55d1d1 100644 --- a/panda/src/text/fontPool.cxx +++ b/panda/src/text/fontPool.cxx @@ -37,7 +37,7 @@ write(std::ostream &out) { * The nonstatic implementation of has_font(). */ bool FontPool:: -ns_has_font(const string &str) { +ns_has_font(std::string_view str) { LightMutexHolder holder(_lock); string index_str; @@ -59,7 +59,7 @@ ns_has_font(const string &str) { * The nonstatic implementation of load_font(). */ TextFont *FontPool:: -ns_load_font(const string &str) { +ns_load_font(std::string_view str) { string index_str; Filename filename; int face_index; @@ -140,7 +140,7 @@ ns_load_font(const string &str) { * The nonstatic implementation of add_font(). */ void FontPool:: -ns_add_font(const string &str, TextFont *font) { +ns_add_font(std::string_view str, TextFont *font) { LightMutexHolder holder(_lock); string index_str; @@ -156,7 +156,7 @@ ns_add_font(const string &str, TextFont *font) { * The nonstatic implementation of release_font(). */ void FontPool:: -ns_release_font(const string &str) { +ns_release_font(std::string_view str) { LightMutexHolder holder(_lock); string index_str; @@ -234,7 +234,7 @@ ns_list_contents(std::ostream &out) const { * normalized to contain the full path.) */ void FontPool:: -lookup_filename(const string &str, string &index_str, +lookup_filename(std::string_view str, string &index_str, Filename &filename, int &face_index) { int colon = (int)str.length() - 1; // Scan backwards over digits for a colon. @@ -242,7 +242,7 @@ lookup_filename(const string &str, string &index_str, --colon; } if (colon >= 0 && str[colon] == ':') { - string digits = str.substr(colon + 1); + string digits(str.substr(colon + 1)); filename = str.substr(0, colon); face_index = atoi(digits.c_str()); } else { diff --git a/panda/src/text/fontPool.h b/panda/src/text/fontPool.h index 8852a83b0c8..076d5bed0dc 100644 --- a/panda/src/text/fontPool.h +++ b/panda/src/text/fontPool.h @@ -33,11 +33,11 @@ class EXPCL_PANDA_TEXT FontPool { // parameters may not be entirely an actual filename: they may be a filename // followed by a face index. - INLINE static bool has_font(const std::string &filename); - INLINE static bool verify_font(const std::string &filename); - BLOCKING INLINE static TextFont *load_font(const std::string &filename); - INLINE static void add_font(const std::string &filename, TextFont *font); - INLINE static void release_font(const std::string &filename); + INLINE static bool has_font(std::string_view filename); + INLINE static bool verify_font(std::string_view filename); + BLOCKING INLINE static TextFont *load_font(std::string_view filename); + INLINE static void add_font(std::string_view filename, TextFont *font); + INLINE static void release_font(std::string_view filename); INLINE static void release_all_fonts(); INLINE static int garbage_collect(); @@ -48,15 +48,15 @@ class EXPCL_PANDA_TEXT FontPool { private: INLINE FontPool(); - bool ns_has_font(const std::string &str); - TextFont *ns_load_font(const std::string &str); - void ns_add_font(const std::string &str, TextFont *font); - void ns_release_font(const std::string &str); + bool ns_has_font(std::string_view str); + TextFont *ns_load_font(std::string_view str); + void ns_add_font(std::string_view str, TextFont *font); + void ns_release_font(std::string_view str); void ns_release_all_fonts(); int ns_garbage_collect(); void ns_list_contents(std::ostream &out) const; - static void lookup_filename(const std::string &str, std::string &index_str, + static void lookup_filename(std::string_view str, std::string &index_str, Filename &filename, int &face_index); static FontPool *get_ptr(); diff --git a/panda/src/text/textFont.cxx b/panda/src/text/textFont.cxx index bf6e9c5397f..d4d6f34e055 100644 --- a/panda/src/text/textFont.cxx +++ b/panda/src/text/textFont.cxx @@ -102,7 +102,7 @@ get_invalid_glyph() { * RenderMode value. */ TextFont::RenderMode TextFont:: -string_render_mode(const string &string) { +string_render_mode(std::string_view string) { if (cmp_nocase_uh(string, "texture") == 0) { return RM_texture; } else if (cmp_nocase_uh(string, "wireframe") == 0) { diff --git a/panda/src/text/textFont.h b/panda/src/text/textFont.h index 1fb30a970c1..05cb5d50dbf 100644 --- a/panda/src/text/textFont.h +++ b/panda/src/text/textFont.h @@ -86,7 +86,7 @@ class EXPCL_PANDA_TEXT TextFont : public TypedReferenceCount, public Namable { virtual bool get_glyph(int character, CPT(TextGlyph) &glyph)=0; TextGlyph *get_invalid_glyph(); - static RenderMode string_render_mode(const std::string &string); + static RenderMode string_render_mode(std::string_view string); private: void make_invalid_glyph(); diff --git a/panda/src/text/textNode.I b/panda/src/text/textNode.I index 4ba8ead2acb..2b79726044d 100644 --- a/panda/src/text/textNode.I +++ b/panda/src/text/textNode.I @@ -856,9 +856,9 @@ clear_shadow() { * "fixed". */ INLINE void TextNode:: -set_bin(const std::string &bin) { +set_bin(std::string bin) { CDWriter cdata(_cycler, true); - TextProperties::set_bin(bin); + TextProperties::set_bin(std::move(bin)); invalidate_no_measure(cdata); } @@ -983,7 +983,7 @@ get_wordwrapped_text() const { * should not include the newline character. */ INLINE PN_stdfloat TextNode:: -calc_width(const std::string &line) const { +calc_width(std::string_view line) const { return calc_width(decode_text(line)); } diff --git a/panda/src/text/textNode.cxx b/panda/src/text/textNode.cxx index e0fa8db2828..a2375eb622e 100644 --- a/panda/src/text/textNode.cxx +++ b/panda/src/text/textNode.cxx @@ -59,7 +59,7 @@ PStatCollector TextNode::_text_generate_pcollector("*:Generate Text"); * */ TextNode:: -TextNode(const string &name) : PandaNode(name) { +TextNode(std::string name) : PandaNode(std::move(name)) { set_cull_callback(); set_renderable(); @@ -73,8 +73,8 @@ TextNode(const string &name) : PandaNode(name) { * without copying a complete TextNode. */ TextNode:: -TextNode(const string &name, const TextProperties ©) : - PandaNode(name), TextProperties(copy) +TextNode(std::string name, const TextProperties ©) : + PandaNode(std::move(name)), TextProperties(copy) { } @@ -613,7 +613,7 @@ do_generate(CData *cdata) { if (newline != string::npos) { name = name.substr(0, newline); } - PT(PandaNode) root = new PandaNode(name); + PT(PandaNode) root = new PandaNode(std::move(name)); if (cdata->_wtext.empty()) { return root; diff --git a/panda/src/text/textNode.h b/panda/src/text/textNode.h index 10fc38f1dfc..eaf70362844 100644 --- a/panda/src/text/textNode.h +++ b/panda/src/text/textNode.h @@ -51,8 +51,8 @@ */ class EXPCL_PANDA_TEXT TextNode : public PandaNode, public TextEncoder, public TextProperties { PUBLISHED: - explicit TextNode(const std::string &name); - explicit TextNode(const std::string &name, const TextProperties ©); + explicit TextNode(std::string name); + explicit TextNode(std::string name, const TextProperties ©); protected: TextNode(const TextNode ©); virtual PandaNode *make_copy() const; @@ -171,7 +171,7 @@ class EXPCL_PANDA_TEXT TextNode : public PandaNode, public TextEncoder, public T INLINE void set_shadow(const LVecBase2 &shadow_offset); INLINE void clear_shadow(); - INLINE void set_bin(const std::string &bin); + INLINE void set_bin(std::string bin); INLINE void clear_bin(); INLINE int set_draw_order(int draw_order); @@ -193,7 +193,7 @@ class EXPCL_PANDA_TEXT TextNode : public PandaNode, public TextEncoder, public T // These methods calculate the width of a single character or a line of text // in the current font. PN_stdfloat calc_width(wchar_t character) const; - INLINE PN_stdfloat calc_width(const std::string &line) const; + INLINE PN_stdfloat calc_width(std::string_view line) const; bool has_exact_character(wchar_t character) const; bool has_character(wchar_t character) const; diff --git a/panda/src/text/textProperties.I b/panda/src/text/textProperties.I index c31cd883de2..5b63cac8d3f 100644 --- a/panda/src/text/textProperties.I +++ b/panda/src/text/textProperties.I @@ -566,8 +566,8 @@ get_shadow() const { * "fixed". */ INLINE void TextProperties:: -set_bin(const std::string &bin) { - _bin = bin; +set_bin(std::string bin) { + _bin = std::move(bin); _specified |= F_has_bin; _text_state.clear(); _shadow_state.clear(); diff --git a/panda/src/text/textProperties.h b/panda/src/text/textProperties.h index cc6c0b49920..fe68deecc7b 100644 --- a/panda/src/text/textProperties.h +++ b/panda/src/text/textProperties.h @@ -136,7 +136,7 @@ class EXPCL_PANDA_TEXT TextProperties : public MemoryBase { INLINE bool has_shadow() const; INLINE LVector2 get_shadow() const; - INLINE void set_bin(const std::string &bin); + INLINE void set_bin(std::string bin); INLINE void clear_bin(); INLINE bool has_bin() const; INLINE const std::string &get_bin() const; diff --git a/panda/src/text/textPropertiesManager.cxx b/panda/src/text/textPropertiesManager.cxx index 1c589499ccc..2fbef389d30 100644 --- a/panda/src/text/textPropertiesManager.cxx +++ b/panda/src/text/textPropertiesManager.cxx @@ -45,8 +45,8 @@ TextPropertiesManager:: * it is quietly replaced with the new definition. */ void TextPropertiesManager:: -set_properties(const string &name, const TextProperties &properties) { - _properties[name] = properties; +set_properties(std::string_view name, const TextProperties &properties) { + _properties[std::string(name)] = properties; } /** @@ -59,7 +59,7 @@ set_properties(const string &name, const TextProperties &properties) { * defined. */ TextProperties TextPropertiesManager:: -get_properties(const string &name) { +get_properties(std::string_view name) { Properties::const_iterator pi; pi = _properties.find(name); if (pi != _properties.end()) { @@ -70,7 +70,7 @@ get_properties(const string &name) { << "Creating default TextProperties for name '" << name << "'\n"; TextProperties default_properties; - _properties[name] = default_properties; + _properties[std::string(name)] = default_properties; return default_properties; } @@ -82,7 +82,7 @@ get_properties(const string &name) { * get_properties() has been called with the indicated name. */ bool TextPropertiesManager:: -has_properties(const string &name) const { +has_properties(std::string_view name) const { Properties::const_iterator pi; pi = _properties.find(name); return (pi != _properties.end()); @@ -92,8 +92,11 @@ has_properties(const string &name) const { * Removes the named TextProperties structure from the manager. */ void TextPropertiesManager:: -clear_properties(const string &name) { - _properties.erase(name); +clear_properties(std::string_view name) { + Properties::iterator pi = _properties.find(name); + if (pi != _properties.end()) { + _properties.erase(pi); + } } /** @@ -106,8 +109,8 @@ clear_properties(const string &name) { * is quietly replaced with the new definition. */ void TextPropertiesManager:: -set_graphic(const string &name, const TextGraphic &graphic) { - _graphics[name] = graphic; +set_graphic(std::string_view name, const TextGraphic &graphic) { + _graphics[std::string(name)] = graphic; } /** @@ -117,7 +120,7 @@ set_graphic(const string &name, const TextGraphic &graphic) { * want to have explicit control of the frame. */ void TextPropertiesManager:: -set_graphic(const string &name, const NodePath &model) { +set_graphic(std::string_view name, const NodePath &model) { LPoint3 min_point, max_point; model.calc_tight_bounds(min_point, max_point); @@ -127,7 +130,7 @@ set_graphic(const string &name, const NodePath &model) { min_point.dot(LVector3::up()), max_point.dot(LVector3::up())); - _graphics[name] = graphic; + _graphics[std::string(name)] = graphic; } /** @@ -140,7 +143,7 @@ set_graphic(const string &name, const NodePath &model) { * defined. */ TextGraphic TextPropertiesManager:: -get_graphic(const string &name) { +get_graphic(std::string_view name) { Graphics::const_iterator pi; pi = _graphics.find(name); if (pi != _graphics.end()) { @@ -151,7 +154,7 @@ get_graphic(const string &name) { << "Creating default TextGraphic for name '" << name << "'\n"; TextGraphic default_graphic; - _graphics[name] = default_graphic; + _graphics[std::string(name)] = default_graphic; return default_graphic; } @@ -163,7 +166,7 @@ get_graphic(const string &name) { * get_graphic() has been called with the indicated name. */ bool TextPropertiesManager:: -has_graphic(const string &name) const { +has_graphic(std::string_view name) const { Graphics::const_iterator pi; pi = _graphics.find(name); return (pi != _graphics.end()); @@ -173,8 +176,11 @@ has_graphic(const string &name) const { * Removes the named TextGraphic structure from the manager. */ void TextPropertiesManager:: -clear_graphic(const string &name) { - _graphics.erase(name); +clear_graphic(std::string_view name) { + Graphics::iterator pi = _graphics.find(name); + if (pi != _graphics.end()) { + _graphics.erase(pi); + } } /** @@ -206,7 +212,7 @@ get_global_ptr() { * there is no properties with that name. */ const TextProperties *TextPropertiesManager:: -get_properties_ptr(const string &name) { +get_properties_ptr(std::string_view name) { Properties::const_iterator pi; pi = _properties.find(name); if (pi != _properties.end()) { @@ -220,7 +226,7 @@ get_properties_ptr(const string &name) { * there is no graphic with that name. */ const TextGraphic *TextPropertiesManager:: -get_graphic_ptr(const string &name) { +get_graphic_ptr(std::string_view name) { Graphics::const_iterator pi; pi = _graphics.find(name); if (pi != _graphics.end()) { diff --git a/panda/src/text/textPropertiesManager.h b/panda/src/text/textPropertiesManager.h index bae0c86e781..6d3bcbeb8f1 100644 --- a/panda/src/text/textPropertiesManager.h +++ b/panda/src/text/textPropertiesManager.h @@ -47,30 +47,30 @@ class EXPCL_PANDA_TEXT TextPropertiesManager { ~TextPropertiesManager(); PUBLISHED: - void set_properties(const std::string &name, const TextProperties &properties); - TextProperties get_properties(const std::string &name); - bool has_properties(const std::string &name) const; - void clear_properties(const std::string &name); + void set_properties(std::string_view name, const TextProperties &properties); + TextProperties get_properties(std::string_view name); + bool has_properties(std::string_view name) const; + void clear_properties(std::string_view name); - void set_graphic(const std::string &name, const TextGraphic &graphic); - void set_graphic(const std::string &name, const NodePath &model); - TextGraphic get_graphic(const std::string &name); - bool has_graphic(const std::string &name) const; - void clear_graphic(const std::string &name); + void set_graphic(std::string_view name, const TextGraphic &graphic); + void set_graphic(std::string_view name, const NodePath &model); + TextGraphic get_graphic(std::string_view name); + bool has_graphic(std::string_view name) const; + void clear_graphic(std::string_view name); void write(std::ostream &out, int indent_level = 0) const; static TextPropertiesManager *get_global_ptr(); public: - const TextProperties *get_properties_ptr(const std::string &name); - const TextGraphic *get_graphic_ptr(const std::string &name); + const TextProperties *get_properties_ptr(std::string_view name); + const TextGraphic *get_graphic_ptr(std::string_view name); private: - typedef pmap Properties; + typedef pmap> Properties; Properties _properties; - typedef pmap Graphics; + typedef pmap> Graphics; Graphics _graphics; static TextPropertiesManager *_global_ptr; diff --git a/panda/src/tform/buttonThrower.I b/panda/src/tform/buttonThrower.I index 2e0fc4c57f0..1004d71ebbd 100644 --- a/panda/src/tform/buttonThrower.I +++ b/panda/src/tform/buttonThrower.I @@ -24,8 +24,8 @@ * See also set_keystroke_event(). */ INLINE void ButtonThrower:: -set_button_down_event(const std::string &button_down_event) { - _button_down_event = button_down_event; +set_button_down_event(std::string button_down_event) { + _button_down_event = std::move(button_down_event); } /** @@ -42,8 +42,8 @@ get_button_down_event() const { * button is released. See set_button_down_event(). */ INLINE void ButtonThrower:: -set_button_up_event(const std::string &button_up_event) { - _button_up_event = button_up_event; +set_button_up_event(std::string button_up_event) { + _button_up_event = std::move(button_up_event); } /** @@ -68,8 +68,8 @@ get_button_up_event() const { * See also set_keystroke_event(). */ INLINE void ButtonThrower:: -set_button_repeat_event(const std::string &button_repeat_event) { - _button_repeat_event = button_repeat_event; +set_button_repeat_event(std::string button_repeat_event) { + _button_repeat_event = std::move(button_repeat_event); } /** @@ -100,8 +100,8 @@ get_button_repeat_event() const { * See also set_button_down_event(). */ INLINE void ButtonThrower:: -set_keystroke_event(const std::string &keystroke_event) { - _keystroke_event = keystroke_event; +set_keystroke_event(std::string keystroke_event) { + _keystroke_event = std::move(keystroke_event); } /** @@ -129,8 +129,8 @@ get_keystroke_event() const { * which to end the highlight, and the current cursor position. */ INLINE void ButtonThrower:: -set_candidate_event(const std::string &candidate_event) { - _candidate_event = candidate_event; +set_candidate_event(std::string candidate_event) { + _candidate_event = std::move(candidate_event); } /** @@ -147,8 +147,8 @@ get_candidate_event() const { * within the window. */ INLINE void ButtonThrower:: -set_move_event(const std::string &move_event) { - _move_event = move_event; +set_move_event(std::string move_event) { + _move_event = std::move(move_event); } /** @@ -166,8 +166,8 @@ get_move_event() const { * selected keyboard layout. */ INLINE void ButtonThrower:: -set_raw_button_down_event(const std::string &raw_button_down_event) { - _raw_button_down_event = raw_button_down_event; +set_raw_button_down_event(std::string raw_button_down_event) { + _raw_button_down_event = std::move(raw_button_down_event); } /** @@ -184,8 +184,8 @@ get_raw_button_down_event() const { * button is released. See set_raw_button_down_event(). */ INLINE void ButtonThrower:: -set_raw_button_up_event(const std::string &raw_button_up_event) { - _raw_button_up_event = raw_button_up_event; +set_raw_button_up_event(std::string raw_button_up_event) { + _raw_button_up_event = std::move(raw_button_up_event); } /** @@ -203,8 +203,8 @@ get_raw_button_up_event() const { * generic event names like set_button_down_event) thrown by this object. */ INLINE void ButtonThrower:: -set_prefix(const std::string &prefix) { - _prefix = prefix; +set_prefix(std::string prefix) { + _prefix = std::move(prefix); } /** diff --git a/panda/src/tform/buttonThrower.cxx b/panda/src/tform/buttonThrower.cxx index 2446c1929a2..69bdc9cdb88 100644 --- a/panda/src/tform/buttonThrower.cxx +++ b/panda/src/tform/buttonThrower.cxx @@ -30,8 +30,8 @@ TypeHandle ButtonThrower::_type_handle; * */ ButtonThrower:: -ButtonThrower(const string &name) : - DataNode(name) +ButtonThrower(std::string name) : + DataNode(std::move(name)) { _button_events_input = define_input("button_events", ButtonEventList::get_class_type()); _button_events_output = define_output("button_events", ButtonEventList::get_class_type()); @@ -230,9 +230,9 @@ write(std::ostream &out, int indent_level) const { * requested parameters. */ void ButtonThrower:: -do_specific_event(const string &event_name, double time) { +do_specific_event(std::string_view event_name, double time) { if (_specific_flag) { - PT(Event) event = new Event(_prefix + event_name); + PT(Event) event = new Event(_prefix + std::string(event_name)); if (_time_flag) { event->add_parameter(time); @@ -251,7 +251,7 @@ do_specific_event(const string &event_name, double time) { * Generates an appropriate general event, if one is configured. */ void ButtonThrower:: -do_general_event(const ButtonEvent &button_event, const string &button_name) { +do_general_event(const ButtonEvent &button_event, std::string_view button_name) { string event_name; switch (button_event._type) { case ButtonEvent::T_down: @@ -308,7 +308,7 @@ do_general_event(const ButtonEvent &button_event, const string &button_name) { case ButtonEvent::T_repeat: case ButtonEvent::T_raw_down: case ButtonEvent::T_raw_up: - event->add_parameter(button_name); + event->add_parameter(std::string(button_name)); break; case ButtonEvent::T_keystroke: diff --git a/panda/src/tform/buttonThrower.h b/panda/src/tform/buttonThrower.h index a83cd54b3bb..6a0d5b4ba85 100644 --- a/panda/src/tform/buttonThrower.h +++ b/panda/src/tform/buttonThrower.h @@ -35,24 +35,24 @@ */ class EXPCL_PANDA_TFORM ButtonThrower : public DataNode { PUBLISHED: - explicit ButtonThrower(const std::string &name); + explicit ButtonThrower(std::string name); ~ButtonThrower(); - INLINE void set_button_down_event(const std::string &button_down_event); + INLINE void set_button_down_event(std::string button_down_event); INLINE const std::string &get_button_down_event() const; - INLINE void set_button_up_event(const std::string &button_up_event); + INLINE void set_button_up_event(std::string button_up_event); INLINE const std::string &get_button_up_event() const; - INLINE void set_button_repeat_event(const std::string &button_repeat_event); + INLINE void set_button_repeat_event(std::string button_repeat_event); INLINE const std::string &get_button_repeat_event() const; - INLINE void set_keystroke_event(const std::string &keystroke_event); + INLINE void set_keystroke_event(std::string keystroke_event); INLINE const std::string &get_keystroke_event() const; - INLINE void set_candidate_event(const std::string &candidate_event); + INLINE void set_candidate_event(std::string candidate_event); INLINE const std::string &get_candidate_event() const; - INLINE void set_move_event(const std::string &move_event); + INLINE void set_move_event(std::string move_event); INLINE const std::string &get_move_event() const; - INLINE void set_raw_button_down_event(const std::string &raw_button_down_event); + INLINE void set_raw_button_down_event(std::string raw_button_down_event); INLINE const std::string &get_raw_button_down_event() const; - INLINE void set_raw_button_up_event(const std::string &raw_button_up_event); + INLINE void set_raw_button_up_event(std::string raw_button_up_event); INLINE const std::string &get_raw_button_up_event() const; MAKE_PROPERTY(button_down_event, get_button_down_event, set_button_down_event); MAKE_PROPERTY(button_up_event, get_button_up_event, set_button_up_event); @@ -63,7 +63,7 @@ class EXPCL_PANDA_TFORM ButtonThrower : public DataNode { MAKE_PROPERTY(raw_button_down_event, get_raw_button_down_event, set_raw_button_down_event); MAKE_PROPERTY(raw_button_up_event, get_raw_button_up_event, set_raw_button_up_event); - INLINE void set_prefix(const std::string &prefix); + INLINE void set_prefix(std::string prefix); INLINE const std::string &get_prefix() const; INLINE void set_specific_flag(bool specific_flag); INLINE bool get_specific_flag() const; @@ -98,9 +98,9 @@ class EXPCL_PANDA_TFORM ButtonThrower : public DataNode { virtual void write(std::ostream &out, int indent_level = 0) const; private: - void do_specific_event(const std::string &event_name, double time); + void do_specific_event(std::string_view event_name, double time); void do_general_event(const ButtonEvent &button_event, - const std::string &event_name); + std::string_view event_name); private: std::string _button_down_event; diff --git a/panda/src/tform/driveInterface.cxx b/panda/src/tform/driveInterface.cxx index 22a23135f51..9fd1ea42806 100644 --- a/panda/src/tform/driveInterface.cxx +++ b/panda/src/tform/driveInterface.cxx @@ -98,8 +98,8 @@ operator < (const DriveInterface::KeyHeld &other) const { * */ DriveInterface:: -DriveInterface(const std::string &name) : - MouseInterfaceNode(name) +DriveInterface(std::string name) : + MouseInterfaceNode(std::move(name)) { _xy_input = define_input("xy", EventStoreVec2::get_class_type()); _button_events_input = define_input("button_events", ButtonEventList::get_class_type()); diff --git a/panda/src/tform/driveInterface.h b/panda/src/tform/driveInterface.h index 516cc6be430..c0e5e2da4c0 100644 --- a/panda/src/tform/driveInterface.h +++ b/panda/src/tform/driveInterface.h @@ -30,7 +30,7 @@ */ class EXPCL_PANDA_TFORM DriveInterface : public MouseInterfaceNode { PUBLISHED: - explicit DriveInterface(const std::string &name = ""); + explicit DriveInterface(std::string name = ""); ~DriveInterface(); INLINE void set_forward_speed(PN_stdfloat speed); diff --git a/panda/src/tform/mouseInterfaceNode.cxx b/panda/src/tform/mouseInterfaceNode.cxx index f9c25475394..5ed603167d2 100644 --- a/panda/src/tform/mouseInterfaceNode.cxx +++ b/panda/src/tform/mouseInterfaceNode.cxx @@ -23,8 +23,8 @@ TypeHandle MouseInterfaceNode::_type_handle; * */ MouseInterfaceNode:: -MouseInterfaceNode(const std::string &name) : - DataNode(name) +MouseInterfaceNode(std::string name) : + DataNode(std::move(name)) { _button_events_input = define_input("button_events", ButtonEventList::get_class_type()); } diff --git a/panda/src/tform/mouseInterfaceNode.h b/panda/src/tform/mouseInterfaceNode.h index b1540e6aba2..064a2818dcc 100644 --- a/panda/src/tform/mouseInterfaceNode.h +++ b/panda/src/tform/mouseInterfaceNode.h @@ -30,7 +30,7 @@ class ButtonEventList; */ class EXPCL_PANDA_TFORM MouseInterfaceNode : public DataNode { public: - explicit MouseInterfaceNode(const std::string &name); + explicit MouseInterfaceNode(std::string name); virtual ~MouseInterfaceNode(); PUBLISHED: diff --git a/panda/src/tform/mouseSubregion.cxx b/panda/src/tform/mouseSubregion.cxx index 89a5fcca943..79f5c5731ba 100644 --- a/panda/src/tform/mouseSubregion.cxx +++ b/panda/src/tform/mouseSubregion.cxx @@ -20,8 +20,8 @@ TypeHandle MouseSubregion::_type_handle; * */ MouseSubregion:: -MouseSubregion(const std::string &name) : - MouseInterfaceNode(name) +MouseSubregion(std::string name) : + MouseInterfaceNode(std::move(name)) { _pixel_xy_input = define_input("pixel_xy", EventStoreVec2::get_class_type()); _pixel_size_input = define_input("pixel_size", EventStoreVec2::get_class_type()); diff --git a/panda/src/tform/mouseSubregion.h b/panda/src/tform/mouseSubregion.h index 105dda96f91..5af0603e3de 100644 --- a/panda/src/tform/mouseSubregion.h +++ b/panda/src/tform/mouseSubregion.h @@ -32,7 +32,7 @@ */ class EXPCL_PANDA_TFORM MouseSubregion : public MouseInterfaceNode { PUBLISHED: - explicit MouseSubregion(const std::string &name); + explicit MouseSubregion(std::string name); ~MouseSubregion(); INLINE PN_stdfloat get_left() const; diff --git a/panda/src/tform/mouseWatcher.I b/panda/src/tform/mouseWatcher.I index 6626454a634..7060ea6b1cd 100644 --- a/panda/src/tform/mouseWatcher.I +++ b/panda/src/tform/mouseWatcher.I @@ -168,8 +168,8 @@ is_raw_button_down(ButtonHandle button) const { * values. */ INLINE void MouseWatcher:: -set_button_down_pattern(const std::string &pattern) { - _button_down_pattern = pattern; +set_button_down_pattern(std::string pattern) { + _button_down_pattern = std::move(pattern); } /** @@ -186,8 +186,8 @@ get_button_down_pattern() const { * when a button is released. See set_button_down_pattern(). */ INLINE void MouseWatcher:: -set_button_up_pattern(const std::string &pattern) { - _button_up_pattern = pattern; +set_button_up_pattern(std::string pattern) { + _button_up_pattern = std::move(pattern); } /** @@ -212,8 +212,8 @@ get_button_up_pattern() const { * values. */ INLINE void MouseWatcher:: -set_button_repeat_pattern(const std::string &pattern) { - _button_repeat_pattern = pattern; +set_button_repeat_pattern(std::string pattern) { + _button_repeat_pattern = std::move(pattern); } /** @@ -233,8 +233,8 @@ get_button_repeat_pattern() const { * it might be "within" multiple nested regions. */ INLINE void MouseWatcher:: -set_enter_pattern(const std::string &pattern) { - _enter_pattern = pattern; +set_enter_pattern(std::string pattern) { + _enter_pattern = std::move(pattern); } /** @@ -255,8 +255,8 @@ get_enter_pattern() const { * it might be "within" multiple nested regions. */ INLINE void MouseWatcher:: -set_leave_pattern(const std::string &pattern) { - _leave_pattern = pattern; +set_leave_pattern(std::string pattern) { + _leave_pattern = std::move(pattern); } /** @@ -277,8 +277,8 @@ get_leave_pattern() const { * given time, while it might be "within" multiple nested regions. */ INLINE void MouseWatcher:: -set_within_pattern(const std::string &pattern) { - _within_pattern = pattern; +set_within_pattern(std::string pattern) { + _within_pattern = std::move(pattern); } /** @@ -299,8 +299,8 @@ get_within_pattern() const { * given time, while it might be "within" multiple nested regions. */ INLINE void MouseWatcher:: -set_without_pattern(const std::string &pattern) { - _without_pattern = pattern; +set_without_pattern(std::string pattern) { + _without_pattern = std::move(pattern); } /** @@ -483,8 +483,8 @@ clear_inactivity_timeout() { * timeout counter expires. See set_inactivity_timeout(). */ INLINE void MouseWatcher:: -set_inactivity_timeout_event(const std::string &event) { - _inactivity_timeout_event = event; +set_inactivity_timeout_event(std::string event) { + _inactivity_timeout_event = std::move(event); } /** diff --git a/panda/src/tform/mouseWatcher.cxx b/panda/src/tform/mouseWatcher.cxx index 8a3cba522d3..30e70cdcfa7 100644 --- a/panda/src/tform/mouseWatcher.cxx +++ b/panda/src/tform/mouseWatcher.cxx @@ -43,8 +43,8 @@ TypeHandle MouseWatcher::_type_handle; * */ MouseWatcher:: -MouseWatcher(const string &name) : - DataNode(name) +MouseWatcher(std::string name) : + DataNode(std::move(name)) { _pixel_xy_input = define_input("pixel_xy", EventStoreVec2::get_class_type()); _pixel_size_input = define_input("pixel_size", EventStoreVec2::get_class_type()); @@ -849,7 +849,7 @@ has_region_in(const MouseWatcher::Regions ®ions, * pattern. */ void MouseWatcher:: -throw_event_pattern(const string &pattern, const MouseWatcherRegion *region, +throw_event_pattern(std::string_view pattern, const MouseWatcherRegion *region, const ButtonHandle &button) { if (pattern.empty()) { return; @@ -873,7 +873,7 @@ throw_event_pattern(const string &pattern, const MouseWatcherRegion *region, string event; for (size_t p = 0; p < pattern.size(); ++p) { if (pattern[p] == '%') { - string cmd = pattern.substr(p + 1, 1); + std::string_view cmd = pattern.substr(p + 1, 1); p++; if (cmd == "r") { if (region != nullptr) { @@ -1382,7 +1382,7 @@ do_transmit_data(DataGraphTraverser *trav, const DataNodeTransmit &input, break; } // The button was already depressed, so this is really just keyrepeat. - // Fall through. + [[fallthrough]]; case ButtonEvent::T_repeat: _current_buttons_down.set_bit(be._button.get_index()); diff --git a/panda/src/tform/mouseWatcher.h b/panda/src/tform/mouseWatcher.h index d901e777ef2..5106161579c 100644 --- a/panda/src/tform/mouseWatcher.h +++ b/panda/src/tform/mouseWatcher.h @@ -60,7 +60,7 @@ class DisplayRegion; */ class EXPCL_PANDA_TFORM MouseWatcher : public DataNode, public MouseWatcherBase { PUBLISHED: - explicit MouseWatcher(const std::string &name = ""); + explicit MouseWatcher(std::string name = ""); ~MouseWatcher(); bool remove_region(MouseWatcherRegion *region); @@ -86,25 +86,25 @@ class EXPCL_PANDA_TFORM MouseWatcher : public DataNode, public MouseWatcherBase INLINE bool is_button_down(ButtonHandle button) const; INLINE bool is_raw_button_down(ButtonHandle button) const; - INLINE void set_button_down_pattern(const std::string &pattern); + INLINE void set_button_down_pattern(std::string pattern); INLINE const std::string &get_button_down_pattern() const; - INLINE void set_button_up_pattern(const std::string &pattern); + INLINE void set_button_up_pattern(std::string pattern); INLINE const std::string &get_button_up_pattern() const; - INLINE void set_button_repeat_pattern(const std::string &pattern); + INLINE void set_button_repeat_pattern(std::string pattern); INLINE const std::string &get_button_repeat_pattern() const; - INLINE void set_enter_pattern(const std::string &pattern); + INLINE void set_enter_pattern(std::string pattern); INLINE const std::string &get_enter_pattern() const; - INLINE void set_leave_pattern(const std::string &pattern); + INLINE void set_leave_pattern(std::string pattern); INLINE const std::string &get_leave_pattern() const; - INLINE void set_within_pattern(const std::string &pattern); + INLINE void set_within_pattern(std::string pattern); INLINE const std::string &get_within_pattern() const; - INLINE void set_without_pattern(const std::string &pattern); + INLINE void set_without_pattern(std::string pattern); INLINE const std::string &get_without_pattern() const; INLINE void set_geometry(PandaNode *node); @@ -135,7 +135,7 @@ class EXPCL_PANDA_TFORM MouseWatcher : public DataNode, public MouseWatcherBase INLINE double get_inactivity_timeout() const; INLINE void clear_inactivity_timeout(); - INLINE void set_inactivity_timeout_event(const std::string &event); + INLINE void set_inactivity_timeout_event(std::string event); INLINE const std::string &get_inactivity_timeout_event() const; INLINE CPT(PointerEventList) get_trail_log() const; @@ -172,7 +172,7 @@ class EXPCL_PANDA_TFORM MouseWatcher : public DataNode, public MouseWatcherBase static bool has_region_in(const Regions ®ions, MouseWatcherRegion *region); - void throw_event_pattern(const std::string &pattern, + void throw_event_pattern(std::string_view pattern, const MouseWatcherRegion *region, const ButtonHandle &button); diff --git a/panda/src/tform/mouseWatcherBase.cxx b/panda/src/tform/mouseWatcherBase.cxx index a0c88575311..7595e2242ef 100644 --- a/panda/src/tform/mouseWatcherBase.cxx +++ b/panda/src/tform/mouseWatcherBase.cxx @@ -105,7 +105,7 @@ remove_region(MouseWatcherRegion *region) { * indeterminate. */ MouseWatcherRegion *MouseWatcherBase:: -find_region(const std::string &name) const { +find_region(std::string_view name) const { LightMutexHolder holder(_lock); for (MouseWatcherRegion *region : _regions) { diff --git a/panda/src/tform/mouseWatcherBase.h b/panda/src/tform/mouseWatcherBase.h index 2811cb2664b..eb30e5d6f98 100644 --- a/panda/src/tform/mouseWatcherBase.h +++ b/panda/src/tform/mouseWatcherBase.h @@ -38,7 +38,7 @@ class EXPCL_PANDA_TFORM MouseWatcherBase { void add_region(PT(MouseWatcherRegion) region); bool has_region(MouseWatcherRegion *region) const; bool remove_region(MouseWatcherRegion *region); - MouseWatcherRegion *find_region(const std::string &name) const; + MouseWatcherRegion *find_region(std::string_view name) const; void clear_regions(); INLINE void sort_regions(); diff --git a/panda/src/tform/mouseWatcherRegion.I b/panda/src/tform/mouseWatcherRegion.I index 91ccbc70630..c832c5b73a4 100644 --- a/panda/src/tform/mouseWatcherRegion.I +++ b/panda/src/tform/mouseWatcherRegion.I @@ -15,9 +15,9 @@ * */ INLINE MouseWatcherRegion:: -MouseWatcherRegion(const std::string &name, PN_stdfloat left, PN_stdfloat right, +MouseWatcherRegion(std::string name, PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top) : - Namable(name) + Namable(std::move(name)) { _sort = 0; _flags = F_active; @@ -28,8 +28,8 @@ MouseWatcherRegion(const std::string &name, PN_stdfloat left, PN_stdfloat right, * */ INLINE MouseWatcherRegion:: -MouseWatcherRegion(const std::string &name, const LVecBase4 &frame) : - Namable(name), +MouseWatcherRegion(std::string name, const LVecBase4 &frame) : + Namable(std::move(name)), _frame(frame) { _sort = 0; diff --git a/panda/src/tform/mouseWatcherRegion.h b/panda/src/tform/mouseWatcherRegion.h index c3e668bf34c..35a9d36ea28 100644 --- a/panda/src/tform/mouseWatcherRegion.h +++ b/panda/src/tform/mouseWatcherRegion.h @@ -30,9 +30,9 @@ class MouseWatcherParameter; */ class EXPCL_PANDA_TFORM MouseWatcherRegion : public TypedWritableReferenceCount, public Namable { PUBLISHED: - INLINE explicit MouseWatcherRegion(const std::string &name, PN_stdfloat left, PN_stdfloat right, + INLINE explicit MouseWatcherRegion(std::string name, PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top); - INLINE explicit MouseWatcherRegion(const std::string &name, const LVecBase4 &frame); + INLINE explicit MouseWatcherRegion(std::string name, const LVecBase4 &frame); INLINE void set_frame(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top); INLINE void set_frame(const LVecBase4 &frame); diff --git a/panda/src/tform/trackball.cxx b/panda/src/tform/trackball.cxx index eee58bc13f2..5245e7b037f 100644 --- a/panda/src/tform/trackball.cxx +++ b/panda/src/tform/trackball.cxx @@ -34,8 +34,8 @@ TypeHandle Trackball::_type_handle; * */ Trackball:: -Trackball(const std::string &name) : - MouseInterfaceNode(name) +Trackball(std::string name) : + MouseInterfaceNode(std::move(name)) { _pixel_xy_input = define_input("pixel_xy", EventStoreVec2::get_class_type()); diff --git a/panda/src/tform/trackball.h b/panda/src/tform/trackball.h index 0ef01f6b8ee..c4a223852f3 100644 --- a/panda/src/tform/trackball.h +++ b/panda/src/tform/trackball.h @@ -34,7 +34,7 @@ */ class EXPCL_PANDA_TFORM Trackball : public MouseInterfaceNode { PUBLISHED: - explicit Trackball(const std::string &name); + explicit Trackball(std::string name); ~Trackball(); void reset(); diff --git a/panda/src/tform/transform2sg.cxx b/panda/src/tform/transform2sg.cxx index 61f734521f0..f0a363298cd 100644 --- a/panda/src/tform/transform2sg.cxx +++ b/panda/src/tform/transform2sg.cxx @@ -23,8 +23,8 @@ TypeHandle Transform2SG::_type_handle; * */ Transform2SG:: -Transform2SG(const std::string &name) : - DataNode(name) +Transform2SG(std::string name) : + DataNode(std::move(name)) { _transform_input = define_input("transform", TransformState::get_class_type()); diff --git a/panda/src/tform/transform2sg.h b/panda/src/tform/transform2sg.h index a385abb4289..b45c810582e 100644 --- a/panda/src/tform/transform2sg.h +++ b/panda/src/tform/transform2sg.h @@ -27,7 +27,7 @@ */ class EXPCL_PANDA_TFORM Transform2SG : public DataNode { PUBLISHED: - explicit Transform2SG(const std::string &name); + explicit Transform2SG(std::string name); void set_node(PandaNode *node); PandaNode *get_node() const; diff --git a/panda/src/tinydisplay/tinyCocoaGraphicsPipe.cxx b/panda/src/tinydisplay/tinyCocoaGraphicsPipe.cxx index 9090b0ec166..abbabecbdd7 100644 --- a/panda/src/tinydisplay/tinyCocoaGraphicsPipe.cxx +++ b/panda/src/tinydisplay/tinyCocoaGraphicsPipe.cxx @@ -62,7 +62,7 @@ pipe_constructor() { * Creates a new window on the pipe, if possible. */ PT(GraphicsOutput) TinyCocoaGraphicsPipe:: -make_output(const std::string &name, +make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -91,7 +91,7 @@ make_output(const std::string &name, (flags & BF_can_bind_every) != 0) { return nullptr; } - return new TinyCocoaGraphicsWindow(engine, this, name, fb_prop, win_prop, + return new TinyCocoaGraphicsWindow(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } @@ -104,7 +104,7 @@ make_output(const std::string &name, (flags & BF_require_window) != 0) { return nullptr; } - return new TinyGraphicsBuffer(engine, this, name, fb_prop, win_prop, flags, gsg, host); + return new TinyGraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } // Nothing else left to try. diff --git a/panda/src/tinydisplay/tinyCocoaGraphicsPipe.h b/panda/src/tinydisplay/tinyCocoaGraphicsPipe.h index e25aba60df9..52e52a651d2 100644 --- a/panda/src/tinydisplay/tinyCocoaGraphicsPipe.h +++ b/panda/src/tinydisplay/tinyCocoaGraphicsPipe.h @@ -35,7 +35,7 @@ class EXPCL_TINYDISPLAY TinyCocoaGraphicsPipe : public CocoaGraphicsPipe { static PT(GraphicsPipe) pipe_constructor(); protected: - virtual PT(GraphicsOutput) make_output(const std::string &name, + virtual PT(GraphicsOutput) make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/tinydisplay/tinyCocoaGraphicsWindow.h b/panda/src/tinydisplay/tinyCocoaGraphicsWindow.h index f2e55d1f5da..862601987f7 100644 --- a/panda/src/tinydisplay/tinyCocoaGraphicsWindow.h +++ b/panda/src/tinydisplay/tinyCocoaGraphicsWindow.h @@ -28,7 +28,7 @@ class EXPCL_TINYDISPLAY TinyCocoaGraphicsWindow : public CocoaGraphicsWindow { public: TinyCocoaGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/tinydisplay/tinyCocoaGraphicsWindow.mm b/panda/src/tinydisplay/tinyCocoaGraphicsWindow.mm index 6565eccac3f..c73605ad917 100644 --- a/panda/src/tinydisplay/tinyCocoaGraphicsWindow.mm +++ b/panda/src/tinydisplay/tinyCocoaGraphicsWindow.mm @@ -29,13 +29,13 @@ */ TinyCocoaGraphicsWindow:: TinyCocoaGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - CocoaGraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host), + CocoaGraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host), _color_space(CGColorSpaceCreateDeviceRGB()) { update_pixel_factor(); diff --git a/panda/src/tinydisplay/tinyGraphicsBuffer.cxx b/panda/src/tinydisplay/tinyGraphicsBuffer.cxx index 0fc76e492ce..4d4ae753b27 100644 --- a/panda/src/tinydisplay/tinyGraphicsBuffer.cxx +++ b/panda/src/tinydisplay/tinyGraphicsBuffer.cxx @@ -25,13 +25,13 @@ TypeHandle TinyGraphicsBuffer::_type_handle; */ TinyGraphicsBuffer:: TinyGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + GraphicsBuffer(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { _frame_buffer = nullptr; } diff --git a/panda/src/tinydisplay/tinyGraphicsBuffer.h b/panda/src/tinydisplay/tinyGraphicsBuffer.h index e1fe665959b..18f7969689d 100644 --- a/panda/src/tinydisplay/tinyGraphicsBuffer.h +++ b/panda/src/tinydisplay/tinyGraphicsBuffer.h @@ -24,7 +24,7 @@ class EXPCL_TINYDISPLAY TinyGraphicsBuffer : public GraphicsBuffer { public: TinyGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/tinydisplay/tinyOffscreenGraphicsPipe.cxx b/panda/src/tinydisplay/tinyOffscreenGraphicsPipe.cxx index 901d874c6d2..db37c76b1d0 100644 --- a/panda/src/tinydisplay/tinyOffscreenGraphicsPipe.cxx +++ b/panda/src/tinydisplay/tinyOffscreenGraphicsPipe.cxx @@ -61,7 +61,7 @@ pipe_constructor() { * Creates a new window on the pipe, if possible. */ PT(GraphicsOutput) TinyOffscreenGraphicsPipe:: -make_output(const std::string &name, +make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -77,7 +77,7 @@ make_output(const std::string &name, ((flags&BF_require_window)!=0)) { return nullptr; } - return new TinyGraphicsBuffer(engine, this, name, fb_prop, win_prop, flags, gsg, host); + return new TinyGraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } // Nothing else left to try. diff --git a/panda/src/tinydisplay/tinyOffscreenGraphicsPipe.h b/panda/src/tinydisplay/tinyOffscreenGraphicsPipe.h index 94d4eb8d738..999f5c19eac 100644 --- a/panda/src/tinydisplay/tinyOffscreenGraphicsPipe.h +++ b/panda/src/tinydisplay/tinyOffscreenGraphicsPipe.h @@ -35,7 +35,7 @@ class EXPCL_TINYDISPLAY TinyOffscreenGraphicsPipe : public GraphicsPipe { static PT(GraphicsPipe) pipe_constructor(); protected: - virtual PT(GraphicsOutput) make_output(const std::string &name, + virtual PT(GraphicsOutput) make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/tinydisplay/tinySDLGraphicsPipe.cxx b/panda/src/tinydisplay/tinySDLGraphicsPipe.cxx index 8a8ef6c54b3..d46427912f5 100644 --- a/panda/src/tinydisplay/tinySDLGraphicsPipe.cxx +++ b/panda/src/tinydisplay/tinySDLGraphicsPipe.cxx @@ -73,7 +73,7 @@ pipe_constructor() { * Creates a new window on the pipe, if possible. */ PT(GraphicsOutput) TinySDLGraphicsPipe:: -make_output(const std::string &name, +make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -103,7 +103,7 @@ make_output(const std::string &name, ((flags&BF_can_bind_every)!=0)) { return nullptr; } - return new TinySDLGraphicsWindow(engine, this, name, fb_prop, win_prop, + return new TinySDLGraphicsWindow(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } diff --git a/panda/src/tinydisplay/tinySDLGraphicsPipe.h b/panda/src/tinydisplay/tinySDLGraphicsPipe.h index a3fc009647f..388906fd450 100644 --- a/panda/src/tinydisplay/tinySDLGraphicsPipe.h +++ b/panda/src/tinydisplay/tinySDLGraphicsPipe.h @@ -36,7 +36,7 @@ class EXPCL_TINYDISPLAY TinySDLGraphicsPipe : public GraphicsPipe { static PT(GraphicsPipe) pipe_constructor(); protected: - virtual PT(GraphicsOutput) make_output(const std::string &name, + virtual PT(GraphicsOutput) make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/tinydisplay/tinySDLGraphicsWindow.cxx b/panda/src/tinydisplay/tinySDLGraphicsWindow.cxx index 54dd73fb15c..8de3b64e218 100644 --- a/panda/src/tinydisplay/tinySDLGraphicsWindow.cxx +++ b/panda/src/tinydisplay/tinySDLGraphicsWindow.cxx @@ -30,13 +30,13 @@ TypeHandle TinySDLGraphicsWindow::_type_handle; */ TinySDLGraphicsWindow:: TinySDLGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + GraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { _screen = nullptr; _frame_buffer = nullptr; diff --git a/panda/src/tinydisplay/tinySDLGraphicsWindow.h b/panda/src/tinydisplay/tinySDLGraphicsWindow.h index dc3695a6c0b..eb7fac5c8fa 100644 --- a/panda/src/tinydisplay/tinySDLGraphicsWindow.h +++ b/panda/src/tinydisplay/tinySDLGraphicsWindow.h @@ -31,7 +31,7 @@ class EXPCL_TINYDISPLAY TinySDLGraphicsWindow : public GraphicsWindow { public: TinySDLGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/tinydisplay/tinyWinGraphicsPipe.cxx b/panda/src/tinydisplay/tinyWinGraphicsPipe.cxx index 1347d406aab..ca9d51cc6c5 100644 --- a/panda/src/tinydisplay/tinyWinGraphicsPipe.cxx +++ b/panda/src/tinydisplay/tinyWinGraphicsPipe.cxx @@ -62,7 +62,7 @@ pipe_constructor() { * only called from GraphicsEngine::make_output. */ PT(GraphicsOutput) TinyWinGraphicsPipe:: -make_output(const std::string &name, +make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -100,7 +100,7 @@ make_output(const std::string &name, return nullptr; } } - return new TinyWinGraphicsWindow(engine, this, name, fb_prop, win_prop, + return new TinyWinGraphicsWindow(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } @@ -110,7 +110,7 @@ make_output(const std::string &name, ((flags&BF_require_window)!=0)) { return nullptr; } - return new TinyGraphicsBuffer(engine, this, name, fb_prop, win_prop, + return new TinyGraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } diff --git a/panda/src/tinydisplay/tinyWinGraphicsPipe.h b/panda/src/tinydisplay/tinyWinGraphicsPipe.h index 72d6e875a55..ea344519108 100644 --- a/panda/src/tinydisplay/tinyWinGraphicsPipe.h +++ b/panda/src/tinydisplay/tinyWinGraphicsPipe.h @@ -34,7 +34,7 @@ class EXPCL_TINYDISPLAY TinyWinGraphicsPipe : public WinGraphicsPipe { static PT(GraphicsPipe) pipe_constructor(); protected: - virtual PT(GraphicsOutput) make_output(const std::string &name, + virtual PT(GraphicsOutput) make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/tinydisplay/tinyWinGraphicsWindow.cxx b/panda/src/tinydisplay/tinyWinGraphicsWindow.cxx index 9f39a207238..be80e64ceae 100644 --- a/panda/src/tinydisplay/tinyWinGraphicsWindow.cxx +++ b/panda/src/tinydisplay/tinyWinGraphicsWindow.cxx @@ -31,13 +31,13 @@ TypeHandle TinyWinGraphicsWindow::_type_handle; */ TinyWinGraphicsWindow:: TinyWinGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - WinGraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + WinGraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { _frame_buffer = nullptr; _hdc = (HDC)0; diff --git a/panda/src/tinydisplay/tinyWinGraphicsWindow.h b/panda/src/tinydisplay/tinyWinGraphicsWindow.h index b234001540c..a6f4d392e6a 100644 --- a/panda/src/tinydisplay/tinyWinGraphicsWindow.h +++ b/panda/src/tinydisplay/tinyWinGraphicsWindow.h @@ -28,7 +28,7 @@ class EXPCL_TINYDISPLAY TinyWinGraphicsWindow : public WinGraphicsWindow { public: TinyWinGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/tinydisplay/tinyXGraphicsPipe.cxx b/panda/src/tinydisplay/tinyXGraphicsPipe.cxx index 76cf30050e3..da138b8d61d 100644 --- a/panda/src/tinydisplay/tinyXGraphicsPipe.cxx +++ b/panda/src/tinydisplay/tinyXGraphicsPipe.cxx @@ -27,7 +27,7 @@ TypeHandle TinyXGraphicsPipe::_type_handle; * */ TinyXGraphicsPipe:: -TinyXGraphicsPipe(const std::string &display) : x11GraphicsPipe(display) { +TinyXGraphicsPipe(std::string display) : x11GraphicsPipe(std::move(display)) { } /** @@ -61,7 +61,7 @@ pipe_constructor() { * Creates a new window on the pipe, if possible. */ PT(GraphicsOutput) TinyXGraphicsPipe:: -make_output(const std::string &name, +make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -90,7 +90,7 @@ make_output(const std::string &name, ((flags&BF_can_bind_every)!=0)) { return nullptr; } - return new TinyXGraphicsWindow(engine, this, name, fb_prop, win_prop, + return new TinyXGraphicsWindow(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } @@ -103,7 +103,7 @@ make_output(const std::string &name, ((flags&BF_require_window)!=0)) { return nullptr; } - return new TinyGraphicsBuffer(engine, this, name, fb_prop, win_prop, flags, gsg, host); + return new TinyGraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } // Nothing else left to try. diff --git a/panda/src/tinydisplay/tinyXGraphicsPipe.h b/panda/src/tinydisplay/tinyXGraphicsPipe.h index c0f7f69eeb2..825f14cd715 100644 --- a/panda/src/tinydisplay/tinyXGraphicsPipe.h +++ b/panda/src/tinydisplay/tinyXGraphicsPipe.h @@ -30,14 +30,14 @@ */ class EXPCL_TINYDISPLAY TinyXGraphicsPipe : public x11GraphicsPipe { public: - TinyXGraphicsPipe(const std::string &display = std::string()); + TinyXGraphicsPipe(std::string display = std::string()); virtual ~TinyXGraphicsPipe(); virtual std::string get_interface_name() const; static PT(GraphicsPipe) pipe_constructor(); protected: - virtual PT(GraphicsOutput) make_output(const std::string &name, + virtual PT(GraphicsOutput) make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/tinydisplay/tinyXGraphicsWindow.cxx b/panda/src/tinydisplay/tinyXGraphicsWindow.cxx index f2337536b03..8476f251a87 100644 --- a/panda/src/tinydisplay/tinyXGraphicsWindow.cxx +++ b/panda/src/tinydisplay/tinyXGraphicsWindow.cxx @@ -37,13 +37,13 @@ TypeHandle TinyXGraphicsWindow::_type_handle; */ TinyXGraphicsWindow:: TinyXGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - x11GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + x11GraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { _gc = (GC)nullptr; diff --git a/panda/src/tinydisplay/tinyXGraphicsWindow.h b/panda/src/tinydisplay/tinyXGraphicsWindow.h index da60c70eeb1..d4bbf3cc5e8 100644 --- a/panda/src/tinydisplay/tinyXGraphicsWindow.h +++ b/panda/src/tinydisplay/tinyXGraphicsWindow.h @@ -28,7 +28,7 @@ class EXPCL_TINYDISPLAY TinyXGraphicsWindow : public x11GraphicsWindow { public: TinyXGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/tinydisplay/zbuffer.cxx b/panda/src/tinydisplay/zbuffer.cxx index 21ac68aaeb1..28471c6ce8c 100644 --- a/panda/src/tinydisplay/zbuffer.cxx +++ b/panda/src/tinydisplay/zbuffer.cxx @@ -622,21 +622,21 @@ apply_wrap_border_color_magfilter(ZTextureDef *texture_def, int s, int t, unsign // functions instead saves two additional function calls per pixel. PIXEL apply_wrap_clamp_minfilter(ZTextureDef *texture_def, int s, int t, unsigned int level, unsigned int level_dx) { - s = min(max(s, 0), texture_def->s_max); - t = min(max(t, 0), texture_def->t_max); + s = std::clamp(s, 0, texture_def->s_max); + t = std::clamp(t, 0, texture_def->t_max); return (*texture_def->tex_minfilter_func_impl)(texture_def, s, t, level, level_dx); } PIXEL apply_wrap_clamp_magfilter(ZTextureDef *texture_def, int s, int t, unsigned int level, unsigned int level_dx) { - s = min(max(s, 0), texture_def->s_max); - t = min(max(t, 0), texture_def->t_max); + s = std::clamp(s, 0, texture_def->s_max); + t = std::clamp(t, 0, texture_def->t_max); return (*texture_def->tex_magfilter_func_impl)(texture_def, s, t, level, level_dx); } int texcoord_clamp(int coord, int max_coord) { - return min(max(coord, 0), max_coord); + return std::clamp(coord, 0, max_coord); } int diff --git a/panda/src/vision/openCVTexture.cxx b/panda/src/vision/openCVTexture.cxx index be85aa68665..2f11b2763e7 100644 --- a/panda/src/vision/openCVTexture.cxx +++ b/panda/src/vision/openCVTexture.cxx @@ -49,8 +49,8 @@ TypeHandle OpenCVTexture::_type_handle; * Sets up the texture to read frames from a camera */ OpenCVTexture:: -OpenCVTexture(const std::string &name) : - VideoTexture(name) +OpenCVTexture(std::string name) : + VideoTexture(std::move(name)) { } @@ -452,7 +452,7 @@ do_read_one(Texture::CData *cdata, */ bool OpenCVTexture:: do_load_one(Texture::CData *cdata, - const PNMImage &pnmimage, const std::string &name, + const PNMImage &pnmimage, std::string_view name, int z, int n, const LoaderOptions &options) { if (z <= (int)_pages.size()) { VideoPage &page = do_modify_page(cdata, z); diff --git a/panda/src/vision/openCVTexture.h b/panda/src/vision/openCVTexture.h index e3fa1a3edbf..8469c9e9c85 100644 --- a/panda/src/vision/openCVTexture.h +++ b/panda/src/vision/openCVTexture.h @@ -28,7 +28,7 @@ struct CvCapture; */ class EXPCL_VISION OpenCVTexture : public VideoTexture { PUBLISHED: - OpenCVTexture(const std::string &name = std::string()); + OpenCVTexture(std::string name = std::string()); OpenCVTexture(const OpenCVTexture ©) = delete; virtual ~OpenCVTexture(); @@ -54,7 +54,7 @@ class EXPCL_VISION OpenCVTexture : public VideoTexture { const LoaderOptions &options, bool header_only, BamCacheRecord *record); virtual bool do_load_one(Texture::CData *cdata, - const PNMImage &pnmimage, const std::string &name, + const PNMImage &pnmimage, std::string_view name, int z, int n, const LoaderOptions &options); private: diff --git a/panda/src/vision/webcamVideoV4L.cxx b/panda/src/vision/webcamVideoV4L.cxx index bc6cad7a1b8..792cb1b8c39 100644 --- a/panda/src/vision/webcamVideoV4L.cxx +++ b/panda/src/vision/webcamVideoV4L.cxx @@ -94,7 +94,7 @@ TypeHandle WebcamVideoV4L::_type_handle; * */ void WebcamVideoV4L:: -add_options_for_size(int fd, const std::string &dev, const char *name, unsigned width, unsigned height, unsigned pixelformat) { +add_options_for_size(int fd, std::string_view dev, const char *name, unsigned width, unsigned height, unsigned pixelformat) { struct v4l2_frmivalenum frmivalenum; for (int k = 0;; k++) { memset(&frmivalenum, 0, sizeof frmivalenum); diff --git a/panda/src/vision/webcamVideoV4L.h b/panda/src/vision/webcamVideoV4L.h index 40045ee402f..76ff333dea9 100644 --- a/panda/src/vision/webcamVideoV4L.h +++ b/panda/src/vision/webcamVideoV4L.h @@ -31,7 +31,7 @@ class WebcamVideoV4L : public WebcamVideo { friend class WebcamVideoCursorV4L; friend void find_all_webcams_v4l(); - static void add_options_for_size(int fd, const std::string &dev, const char *name, + static void add_options_for_size(int fd, std::string_view dev, const char *name, unsigned width, unsigned height, unsigned pixelformat); diff --git a/panda/src/vrpn/vrpnAnalog.cxx b/panda/src/vrpn/vrpnAnalog.cxx index b0b81c8867f..d57c44ca6fd 100644 --- a/panda/src/vrpn/vrpnAnalog.cxx +++ b/panda/src/vrpn/vrpnAnalog.cxx @@ -24,8 +24,8 @@ * */ VrpnAnalog:: -VrpnAnalog(const std::string &analog_name, vrpn_Connection *connection) : - _analog_name(analog_name) +VrpnAnalog(std::string analog_name, vrpn_Connection *connection) : + _analog_name(std::move(analog_name)) { _analog = new vrpn_Analog_Remote(_analog_name.c_str(), connection); diff --git a/panda/src/vrpn/vrpnAnalog.h b/panda/src/vrpn/vrpnAnalog.h index 34bc51f2773..a42bda659bd 100644 --- a/panda/src/vrpn/vrpnAnalog.h +++ b/panda/src/vrpn/vrpnAnalog.h @@ -37,7 +37,7 @@ class VrpnAnalogDevice; */ class VrpnAnalog { public: - VrpnAnalog(const std::string &analog_name, vrpn_Connection *connection); + VrpnAnalog(std::string analog_name, vrpn_Connection *connection); ~VrpnAnalog(); INLINE const std::string &get_analog_name() const; diff --git a/panda/src/vrpn/vrpnAnalogDevice.cxx b/panda/src/vrpn/vrpnAnalogDevice.cxx index 101f097c52e..9260cb00d9a 100644 --- a/panda/src/vrpn/vrpnAnalogDevice.cxx +++ b/panda/src/vrpn/vrpnAnalogDevice.cxx @@ -20,9 +20,9 @@ TypeHandle VrpnAnalogDevice::_type_handle; * */ VrpnAnalogDevice:: -VrpnAnalogDevice(VrpnClient *client, const std::string &device_name, +VrpnAnalogDevice(VrpnClient *client, std::string device_name, VrpnAnalog *vrpn_analog) : - ClientAnalogDevice(client, device_name), + ClientAnalogDevice(client, std::move(device_name)), _vrpn_analog(vrpn_analog) { } diff --git a/panda/src/vrpn/vrpnAnalogDevice.h b/panda/src/vrpn/vrpnAnalogDevice.h index a778857f603..189ce85f56f 100644 --- a/panda/src/vrpn/vrpnAnalogDevice.h +++ b/panda/src/vrpn/vrpnAnalogDevice.h @@ -29,7 +29,7 @@ class VrpnAnalog; */ class VrpnAnalogDevice : public ClientAnalogDevice { public: - VrpnAnalogDevice(VrpnClient *client, const std::string &device_name, + VrpnAnalogDevice(VrpnClient *client, std::string device_name, VrpnAnalog *vrpn_analog); virtual ~VrpnAnalogDevice(); diff --git a/panda/src/vrpn/vrpnButton.cxx b/panda/src/vrpn/vrpnButton.cxx index eefbcf10153..6e7e777c9bc 100644 --- a/panda/src/vrpn/vrpnButton.cxx +++ b/panda/src/vrpn/vrpnButton.cxx @@ -24,8 +24,8 @@ * */ VrpnButton:: -VrpnButton(const std::string &button_name, vrpn_Connection *connection) : - _button_name(button_name) +VrpnButton(std::string button_name, vrpn_Connection *connection) : + _button_name(std::move(button_name)) { _button = new vrpn_Button_Remote(_button_name.c_str(), connection); diff --git a/panda/src/vrpn/vrpnButton.h b/panda/src/vrpn/vrpnButton.h index 3b151b51301..8147f776e72 100644 --- a/panda/src/vrpn/vrpnButton.h +++ b/panda/src/vrpn/vrpnButton.h @@ -36,7 +36,7 @@ class VrpnButtonDevice; */ class VrpnButton { public: - VrpnButton(const std::string &button_name, vrpn_Connection *connection); + VrpnButton(std::string button_name, vrpn_Connection *connection); ~VrpnButton(); INLINE const std::string &get_button_name() const; diff --git a/panda/src/vrpn/vrpnButtonDevice.cxx b/panda/src/vrpn/vrpnButtonDevice.cxx index eb287d2f5ee..c9af849446e 100644 --- a/panda/src/vrpn/vrpnButtonDevice.cxx +++ b/panda/src/vrpn/vrpnButtonDevice.cxx @@ -20,9 +20,9 @@ TypeHandle VrpnButtonDevice::_type_handle; * */ VrpnButtonDevice:: -VrpnButtonDevice(VrpnClient *client, const std::string &device_name, +VrpnButtonDevice(VrpnClient *client, std::string device_name, VrpnButton *vrpn_button) : - ClientButtonDevice(client, device_name), + ClientButtonDevice(client, std::move(device_name)), _vrpn_button(vrpn_button) { } diff --git a/panda/src/vrpn/vrpnButtonDevice.h b/panda/src/vrpn/vrpnButtonDevice.h index 45ba3df6949..34762c28764 100644 --- a/panda/src/vrpn/vrpnButtonDevice.h +++ b/panda/src/vrpn/vrpnButtonDevice.h @@ -29,7 +29,7 @@ class VrpnButton; */ class VrpnButtonDevice : public ClientButtonDevice { public: - VrpnButtonDevice(VrpnClient *client, const std::string &device_name, + VrpnButtonDevice(VrpnClient *client, std::string device_name, VrpnButton *vrpn_button); virtual ~VrpnButtonDevice(); diff --git a/panda/src/vrpn/vrpnClient.cxx b/panda/src/vrpn/vrpnClient.cxx index 9bf4ea2795c..643500efb08 100644 --- a/panda/src/vrpn/vrpnClient.cxx +++ b/panda/src/vrpn/vrpnClient.cxx @@ -146,7 +146,7 @@ write(std::ostream &out, int indent_level) const { * been called for the same device_type/device_name). */ PT(ClientDevice) VrpnClient:: -make_device(TypeHandle device_type, const string &device_name) { +make_device(TypeHandle device_type, std::string_view device_name) { if (device_type == ClientTrackerDevice::get_class_type()) { return make_tracker_device(device_name); @@ -173,7 +173,7 @@ make_device(TypeHandle device_type, const string &device_name) { * unknown (e.g. it was disconnected previously). */ bool VrpnClient:: -disconnect_device(TypeHandle device_type, const string &device_name, +disconnect_device(TypeHandle device_type, std::string_view device_name, ClientDevice *device) { if (vrpn_cat.is_debug()) { vrpn_cat.debug() @@ -264,18 +264,18 @@ do_poll() { * indicated sensor number. */ PT(ClientDevice) VrpnClient:: -make_tracker_device(const string &device_name) { +make_tracker_device(std::string_view device_name) { if (vrpn_cat.is_debug()) { vrpn_cat.debug() << "Making tracker device for " << device_name << "\n"; } - string tracker_name = device_name; + std::string_view tracker_name = device_name; int sensor = 0; VrpnTrackerDevice::DataType data_type = VrpnTrackerDevice::DT_position; size_t colon = device_name.rfind(':'); - if (colon != string::npos && colon + 1 < device_name.length()) { + if (colon != std::string_view::npos && colon + 1 < device_name.length()) { size_t begin = colon + 1; size_t end = device_name.length(); VrpnTrackerDevice::DataType maybe_data_type = data_type; @@ -297,7 +297,7 @@ make_tracker_device(const string &device_name) { break; } int maybe_sensor; - if (string_to_int(device_name.substr(begin, end - begin), maybe_sensor)) { + if (string_to_int(std::string(device_name.substr(begin, end - begin)), maybe_sensor)) { // It seems to be a legitimate integer! sensor = maybe_sensor; data_type = maybe_data_type; @@ -308,7 +308,7 @@ make_tracker_device(const string &device_name) { VrpnTracker *tracker = get_tracker(tracker_name); VrpnTrackerDevice *device = - new VrpnTrackerDevice(this, device_name, sensor, data_type, tracker); + new VrpnTrackerDevice(this, std::string(device_name), sensor, data_type, tracker); if (vrpn_cat.is_debug()) { vrpn_cat.debug() @@ -324,7 +324,7 @@ make_tracker_device(const string &device_name) { * library. */ PT(ClientDevice) VrpnClient:: -make_button_device(const string &device_name) { +make_button_device(std::string_view device_name) { if (vrpn_cat.is_debug()) { vrpn_cat.debug() << "Making button device for " << device_name << "\n"; @@ -333,7 +333,7 @@ make_button_device(const string &device_name) { VrpnButton *button = get_button(device_name); VrpnButtonDevice *device = - new VrpnButtonDevice(this, device_name, button); + new VrpnButtonDevice(this, std::string(device_name), button); if (vrpn_cat.is_debug()) { vrpn_cat.debug() @@ -349,7 +349,7 @@ make_button_device(const string &device_name) { * library. */ PT(ClientDevice) VrpnClient:: -make_analog_device(const string &device_name) { +make_analog_device(std::string_view device_name) { if (vrpn_cat.is_debug()) { vrpn_cat.debug() << "Making analog device for " << device_name << "\n"; @@ -358,7 +358,7 @@ make_analog_device(const string &device_name) { VrpnAnalog *analog = get_analog(device_name); VrpnAnalogDevice *device = - new VrpnAnalogDevice(this, device_name, analog); + new VrpnAnalogDevice(this, std::string(device_name), analog); if (vrpn_cat.is_debug()) { vrpn_cat.debug() @@ -374,7 +374,7 @@ make_analog_device(const string &device_name) { * library. */ PT(ClientDevice) VrpnClient:: -make_dial_device(const string &device_name) { +make_dial_device(std::string_view device_name) { if (vrpn_cat.is_debug()) { vrpn_cat.debug() << "Making dial device for " << device_name << "\n"; @@ -383,7 +383,7 @@ make_dial_device(const string &device_name) { VrpnDial *dial = get_dial(device_name); VrpnDialDevice *device = - new VrpnDialDevice(this, device_name, dial); + new VrpnDialDevice(this, std::string(device_name), dial); if (vrpn_cat.is_debug()) { vrpn_cat.debug() @@ -447,7 +447,7 @@ disconnect_dial_device(VrpnDialDevice *device) { * exists, or creates a new one if it does not. */ VrpnTracker *VrpnClient:: -get_tracker(const string &tracker_name) { +get_tracker(std::string_view tracker_name) { Trackers::iterator ti; ti = _trackers.find(tracker_name); @@ -455,8 +455,9 @@ get_tracker(const string &tracker_name) { return (*ti).second; } - VrpnTracker *vrpn_tracker = new VrpnTracker(tracker_name, _connection); - _trackers.insert(Trackers::value_type(tracker_name, vrpn_tracker)); + std::string name(tracker_name); + VrpnTracker *vrpn_tracker = new VrpnTracker(name, _connection); + _trackers.insert(Trackers::value_type(std::move(name), vrpn_tracker)); if (vrpn_cat.is_debug()) { vrpn_cat.debug() @@ -493,7 +494,7 @@ free_tracker(VrpnTracker *vrpn_tracker) { * exists, or creates a new one if it does not. */ VrpnButton *VrpnClient:: -get_button(const string &button_name) { +get_button(std::string_view button_name) { Buttons::iterator bi; bi = _buttons.find(button_name); @@ -501,8 +502,9 @@ get_button(const string &button_name) { return (*bi).second; } - VrpnButton *vrpn_button = new VrpnButton(button_name, _connection); - _buttons.insert(Buttons::value_type(button_name, vrpn_button)); + std::string name(button_name); + VrpnButton *vrpn_button = new VrpnButton(name, _connection); + _buttons.insert(Buttons::value_type(std::move(name), vrpn_button)); if (vrpn_cat.is_debug()) { vrpn_cat.debug() @@ -539,7 +541,7 @@ free_button(VrpnButton *vrpn_button) { * exists, or creates a new one if it does not. */ VrpnAnalog *VrpnClient:: -get_analog(const string &analog_name) { +get_analog(std::string_view analog_name) { Analogs::iterator ai; ai = _analogs.find(analog_name); @@ -547,8 +549,9 @@ get_analog(const string &analog_name) { return (*ai).second; } - VrpnAnalog *vrpn_analog = new VrpnAnalog(analog_name, _connection); - _analogs.insert(Analogs::value_type(analog_name, vrpn_analog)); + std::string name(analog_name); + VrpnAnalog *vrpn_analog = new VrpnAnalog(name, _connection); + _analogs.insert(Analogs::value_type(std::move(name), vrpn_analog)); if (vrpn_cat.is_debug()) { vrpn_cat.debug() @@ -585,7 +588,7 @@ free_analog(VrpnAnalog *vrpn_analog) { * exists, or creates a new one if it does not. */ VrpnDial *VrpnClient:: -get_dial(const string &dial_name) { +get_dial(std::string_view dial_name) { Dials::iterator di; di = _dials.find(dial_name); @@ -593,8 +596,9 @@ get_dial(const string &dial_name) { return (*di).second; } - VrpnDial *vrpn_dial = new VrpnDial(dial_name, _connection); - _dials.insert(Dials::value_type(dial_name, vrpn_dial)); + std::string name(dial_name); + VrpnDial *vrpn_dial = new VrpnDial(name, _connection); + _dials.insert(Dials::value_type(std::move(name), vrpn_dial)); if (vrpn_cat.is_debug()) { vrpn_cat.debug() diff --git a/panda/src/vrpn/vrpnClient.h b/panda/src/vrpn/vrpnClient.h index 979351eac97..54ab641b90a 100644 --- a/panda/src/vrpn/vrpnClient.h +++ b/panda/src/vrpn/vrpnClient.h @@ -48,44 +48,44 @@ class EXPCL_VRPN VrpnClient : public ClientBase { protected: virtual PT(ClientDevice) make_device(TypeHandle device_type, - const std::string &device_name); + std::string_view device_name); virtual bool disconnect_device(TypeHandle device_type, - const std::string &device_name, + std::string_view device_name, ClientDevice *device); virtual void do_poll(); private: - PT(ClientDevice) make_tracker_device(const std::string &device_name); - PT(ClientDevice) make_button_device(const std::string &device_name); - PT(ClientDevice) make_analog_device(const std::string &device_name); - PT(ClientDevice) make_dial_device(const std::string &device_name); + PT(ClientDevice) make_tracker_device(std::string_view device_name); + PT(ClientDevice) make_button_device(std::string_view device_name); + PT(ClientDevice) make_analog_device(std::string_view device_name); + PT(ClientDevice) make_dial_device(std::string_view device_name); void disconnect_tracker_device(VrpnTrackerDevice *device); void disconnect_button_device(VrpnButtonDevice *device); void disconnect_analog_device(VrpnAnalogDevice *device); void disconnect_dial_device(VrpnDialDevice *device); - VrpnTracker *get_tracker(const std::string &tracker_name); + VrpnTracker *get_tracker(std::string_view tracker_name); void free_tracker(VrpnTracker *vrpn_tracker); - VrpnButton *get_button(const std::string &button_name); + VrpnButton *get_button(std::string_view button_name); void free_button(VrpnButton *vrpn_button); - VrpnAnalog *get_analog(const std::string &analog_name); + VrpnAnalog *get_analog(std::string_view analog_name); void free_analog(VrpnAnalog *vrpn_analog); - VrpnDial *get_dial(const std::string &dial_name); + VrpnDial *get_dial(std::string_view dial_name); void free_dial(VrpnDial *vrpn_dial); private: std::string _server_name; vrpn_Connection *_connection; - typedef pmap Trackers; - typedef pmap Buttons; - typedef pmap Analogs; - typedef pmap Dials; + typedef pmap> Trackers; + typedef pmap> Buttons; + typedef pmap> Analogs; + typedef pmap> Dials; Trackers _trackers; Buttons _buttons; diff --git a/panda/src/vrpn/vrpnDial.cxx b/panda/src/vrpn/vrpnDial.cxx index 04f19762df6..5c7dd8c09a5 100644 --- a/panda/src/vrpn/vrpnDial.cxx +++ b/panda/src/vrpn/vrpnDial.cxx @@ -24,8 +24,8 @@ * */ VrpnDial:: -VrpnDial(const std::string &dial_name, vrpn_Connection *connection) : - _dial_name(dial_name) +VrpnDial(std::string dial_name, vrpn_Connection *connection) : + _dial_name(std::move(dial_name)) { _dial = new vrpn_Dial_Remote(_dial_name.c_str(), connection); diff --git a/panda/src/vrpn/vrpnDial.h b/panda/src/vrpn/vrpnDial.h index e7be9c8aa12..9da93bef094 100644 --- a/panda/src/vrpn/vrpnDial.h +++ b/panda/src/vrpn/vrpnDial.h @@ -36,7 +36,7 @@ class VrpnDialDevice; */ class VrpnDial { public: - VrpnDial(const std::string &dial_name, vrpn_Connection *connection); + VrpnDial(std::string dial_name, vrpn_Connection *connection); ~VrpnDial(); INLINE const std::string &get_dial_name() const; diff --git a/panda/src/vrpn/vrpnDialDevice.cxx b/panda/src/vrpn/vrpnDialDevice.cxx index 6331fb8a024..5a971253bc7 100644 --- a/panda/src/vrpn/vrpnDialDevice.cxx +++ b/panda/src/vrpn/vrpnDialDevice.cxx @@ -20,9 +20,9 @@ TypeHandle VrpnDialDevice::_type_handle; * */ VrpnDialDevice:: -VrpnDialDevice(VrpnClient *client, const std::string &device_name, +VrpnDialDevice(VrpnClient *client, std::string device_name, VrpnDial *vrpn_dial) : - ClientDialDevice(client, device_name), + ClientDialDevice(client, std::move(device_name)), _vrpn_dial(vrpn_dial) { } diff --git a/panda/src/vrpn/vrpnDialDevice.h b/panda/src/vrpn/vrpnDialDevice.h index 52bb88c5872..f1ba6021bad 100644 --- a/panda/src/vrpn/vrpnDialDevice.h +++ b/panda/src/vrpn/vrpnDialDevice.h @@ -29,7 +29,7 @@ class VrpnDial; */ class VrpnDialDevice : public ClientDialDevice { public: - VrpnDialDevice(VrpnClient *client, const std::string &device_name, + VrpnDialDevice(VrpnClient *client, std::string device_name, VrpnDial *vrpn_dial); virtual ~VrpnDialDevice(); diff --git a/panda/src/vrpn/vrpnTracker.cxx b/panda/src/vrpn/vrpnTracker.cxx index 046eaf1d697..b17a8ce2add 100644 --- a/panda/src/vrpn/vrpnTracker.cxx +++ b/panda/src/vrpn/vrpnTracker.cxx @@ -24,8 +24,8 @@ * */ VrpnTracker:: -VrpnTracker(const std::string &tracker_name, vrpn_Connection *connection) : - _tracker_name(tracker_name) +VrpnTracker(std::string tracker_name, vrpn_Connection *connection) : + _tracker_name(std::move(tracker_name)) { _tracker = new vrpn_Tracker_Remote(_tracker_name.c_str(), connection); diff --git a/panda/src/vrpn/vrpnTracker.h b/panda/src/vrpn/vrpnTracker.h index bb6651cff71..1ae4e27c262 100644 --- a/panda/src/vrpn/vrpnTracker.h +++ b/panda/src/vrpn/vrpnTracker.h @@ -36,7 +36,7 @@ class VrpnTrackerDevice; */ class VrpnTracker { public: - VrpnTracker(const std::string &tracker_name, vrpn_Connection *connection); + VrpnTracker(std::string tracker_name, vrpn_Connection *connection); ~VrpnTracker(); INLINE const std::string &get_tracker_name() const; diff --git a/panda/src/vrpn/vrpnTrackerDevice.cxx b/panda/src/vrpn/vrpnTrackerDevice.cxx index 980f9cf77c3..b774ed0c1b1 100644 --- a/panda/src/vrpn/vrpnTrackerDevice.cxx +++ b/panda/src/vrpn/vrpnTrackerDevice.cxx @@ -20,10 +20,10 @@ TypeHandle VrpnTrackerDevice::_type_handle; * */ VrpnTrackerDevice:: -VrpnTrackerDevice(VrpnClient *client, const std::string &device_name, +VrpnTrackerDevice(VrpnClient *client, std::string device_name, int sensor, VrpnTrackerDevice::DataType data_type, VrpnTracker *vrpn_tracker) : - ClientTrackerDevice(client, device_name), + ClientTrackerDevice(client, std::move(device_name)), _sensor(sensor), _data_type(data_type), _vrpn_tracker(vrpn_tracker) diff --git a/panda/src/vrpn/vrpnTrackerDevice.h b/panda/src/vrpn/vrpnTrackerDevice.h index 58ddf9068b9..fa85f96f896 100644 --- a/panda/src/vrpn/vrpnTrackerDevice.h +++ b/panda/src/vrpn/vrpnTrackerDevice.h @@ -39,7 +39,7 @@ class VrpnTrackerDevice : public ClientTrackerDevice { DT_acceleration }; - VrpnTrackerDevice(VrpnClient *client, const std::string &device_name, + VrpnTrackerDevice(VrpnClient *client, std::string device_name, int sensor, DataType data_type, VrpnTracker *vrpn_tracker); virtual ~VrpnTrackerDevice(); diff --git a/panda/src/webgldisplay/webGLGraphicsPipe.cxx b/panda/src/webgldisplay/webGLGraphicsPipe.cxx index 9e80679fcd7..32f5432e056 100644 --- a/panda/src/webgldisplay/webGLGraphicsPipe.cxx +++ b/panda/src/webgldisplay/webGLGraphicsPipe.cxx @@ -68,7 +68,7 @@ get_preferred_window_thread() const { * Creates a new window on the pipe, if possible. */ PT(GraphicsOutput) WebGLGraphicsPipe:: -make_output(const std::string &name, +make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -99,7 +99,7 @@ make_output(const std::string &name, ((flags&BF_can_bind_every)!=0)) { return NULL; } - return new WebGLGraphicsWindow(engine, this, name, fb_prop, win_prop, + return new WebGLGraphicsWindow(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } @@ -129,7 +129,7 @@ make_output(const std::string &name, (fb_prop.is_basic())) { precertify = true; } - return new GLES2GraphicsBuffer(engine, this, name, fb_prop, win_prop, + return new GLES2GraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } diff --git a/panda/src/webgldisplay/webGLGraphicsPipe.h b/panda/src/webgldisplay/webGLGraphicsPipe.h index a8e2a8ddc62..f13184269e6 100644 --- a/panda/src/webgldisplay/webGLGraphicsPipe.h +++ b/panda/src/webgldisplay/webGLGraphicsPipe.h @@ -38,7 +38,7 @@ class WebGLGraphicsPipe : public GraphicsPipe { virtual PreferredWindowThread get_preferred_window_thread() const; protected: - virtual PT(GraphicsOutput) make_output(const std::string &name, + virtual PT(GraphicsOutput) make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/webgldisplay/webGLGraphicsWindow.cxx b/panda/src/webgldisplay/webGLGraphicsWindow.cxx index da094d1cb54..05eb52f0221 100644 --- a/panda/src/webgldisplay/webGLGraphicsWindow.cxx +++ b/panda/src/webgldisplay/webGLGraphicsWindow.cxx @@ -34,13 +34,13 @@ TypeHandle WebGLGraphicsWindow::_type_handle; */ WebGLGraphicsWindow:: WebGLGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + GraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { PT(GraphicsWindowInputDevice) device = GraphicsWindowInputDevice::pointer_and_keyboard(this, "keyboard_mouse"); diff --git a/panda/src/webgldisplay/webGLGraphicsWindow.h b/panda/src/webgldisplay/webGLGraphicsWindow.h index 3b905f8543c..3847b550d8c 100644 --- a/panda/src/webgldisplay/webGLGraphicsWindow.h +++ b/panda/src/webgldisplay/webGLGraphicsWindow.h @@ -28,7 +28,7 @@ class WebGLGraphicsWindow : public GraphicsWindow { public: WebGLGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/wgldisplay/wglGraphicsBuffer.cxx b/panda/src/wgldisplay/wglGraphicsBuffer.cxx index 3721dacb16d..94045d94429 100644 --- a/panda/src/wgldisplay/wglGraphicsBuffer.cxx +++ b/panda/src/wgldisplay/wglGraphicsBuffer.cxx @@ -28,13 +28,13 @@ TypeHandle wglGraphicsBuffer::_type_handle; */ wglGraphicsBuffer:: wglGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsBuffer(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + GraphicsBuffer(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { _pbuffer = (HPBUFFERARB)0; _pbuffer_dc = (HDC)0; diff --git a/panda/src/wgldisplay/wglGraphicsBuffer.h b/panda/src/wgldisplay/wglGraphicsBuffer.h index 3560d3f4b54..e7a78edef70 100644 --- a/panda/src/wgldisplay/wglGraphicsBuffer.h +++ b/panda/src/wgldisplay/wglGraphicsBuffer.h @@ -35,7 +35,7 @@ class EXPCL_PANDA_WGLDISPLAY wglGraphicsBuffer : public GraphicsBuffer { public: wglGraphicsBuffer(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/wgldisplay/wglGraphicsPipe.cxx b/panda/src/wgldisplay/wglGraphicsPipe.cxx index ef788deeec2..b9cfc96ea63 100644 --- a/panda/src/wgldisplay/wglGraphicsPipe.cxx +++ b/panda/src/wgldisplay/wglGraphicsPipe.cxx @@ -90,7 +90,7 @@ pipe_constructor() { * only called from GraphicsEngine::make_output. */ PT(GraphicsOutput) wglGraphicsPipe:: -make_output(const std::string &name, +make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, @@ -137,7 +137,7 @@ make_output(const std::string &name, return nullptr; } } - return new wglGraphicsWindow(engine, this, name, fb_prop, win_prop, + return new wglGraphicsWindow(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } @@ -170,7 +170,7 @@ make_output(const std::string &name, precertify = true; } } - return new GLGraphicsBuffer(engine, this, name, fb_prop, win_prop, + return new GLGraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } @@ -217,7 +217,7 @@ make_output(const std::string &name, (wglgsg->get_fb_properties().is_single_buffered())) { precertify = true; } - return new wglGraphicsBuffer(engine, this, name, fb_prop, win_prop, + return new wglGraphicsBuffer(engine, this, std::string(name), fb_prop, win_prop, flags, gsg, host); } diff --git a/panda/src/wgldisplay/wglGraphicsPipe.h b/panda/src/wgldisplay/wglGraphicsPipe.h index 7ba44a25e2d..9a7bace7d11 100644 --- a/panda/src/wgldisplay/wglGraphicsPipe.h +++ b/panda/src/wgldisplay/wglGraphicsPipe.h @@ -32,7 +32,7 @@ class EXPCL_PANDA_WGLDISPLAY wglGraphicsPipe : public WinGraphicsPipe { static PT(GraphicsPipe) pipe_constructor(); protected: - virtual PT(GraphicsOutput) make_output(const std::string &name, + virtual PT(GraphicsOutput) make_output(std::string_view name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/wgldisplay/wglGraphicsWindow.cxx b/panda/src/wgldisplay/wglGraphicsWindow.cxx index 536b5ad2f6a..e43f1c2d6dc 100644 --- a/panda/src/wgldisplay/wglGraphicsWindow.cxx +++ b/panda/src/wgldisplay/wglGraphicsWindow.cxx @@ -28,13 +28,13 @@ TypeHandle wglGraphicsWindow::_type_handle; */ wglGraphicsWindow:: wglGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - WinGraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + WinGraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { _hdc = (HDC)0; } diff --git a/panda/src/wgldisplay/wglGraphicsWindow.h b/panda/src/wgldisplay/wglGraphicsWindow.h index 66dc2d5878e..31dffb72113 100644 --- a/panda/src/wgldisplay/wglGraphicsWindow.h +++ b/panda/src/wgldisplay/wglGraphicsWindow.h @@ -23,7 +23,7 @@ class EXPCL_PANDA_WGLDISPLAY wglGraphicsWindow : public WinGraphicsWindow { public: wglGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/windisplay/winGraphicsWindow.cxx b/panda/src/windisplay/winGraphicsWindow.cxx index ee97911e66d..7cffba6bc4e 100644 --- a/panda/src/windisplay/winGraphicsWindow.cxx +++ b/panda/src/windisplay/winGraphicsWindow.cxx @@ -89,13 +89,13 @@ static PFN_CLOSETOUCHINPUTHANDLE pCloseTouchInputHandle = 0; */ WinGraphicsWindow:: WinGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) + GraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { initialize_input_devices(); _hWnd = (HWND)0; @@ -476,7 +476,7 @@ set_properties_now(WindowProperties &properties) { if (!enable_raw_input()) { break; } - // Fall through + [[fallthrough]]; case WindowProperties::M_confined: // If we are not the foreground window, we defer confining the cursor diff --git a/panda/src/windisplay/winGraphicsWindow.h b/panda/src/windisplay/winGraphicsWindow.h index d0e8f938a29..0899d1d54f5 100644 --- a/panda/src/windisplay/winGraphicsWindow.h +++ b/panda/src/windisplay/winGraphicsWindow.h @@ -64,7 +64,7 @@ typedef struct tagTOUCHINPUT { class EXPCL_PANDAWIN WinGraphicsWindow : public GraphicsWindow { public: WinGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/panda/src/x11display/x11GraphicsPipe.cxx b/panda/src/x11display/x11GraphicsPipe.cxx index 136ebaee6de..9931493ba6d 100644 --- a/panda/src/x11display/x11GraphicsPipe.cxx +++ b/panda/src/x11display/x11GraphicsPipe.cxx @@ -34,12 +34,12 @@ LightReMutex x11GraphicsPipe::_x_mutex; * */ x11GraphicsPipe:: -x11GraphicsPipe(const std::string &display) : +x11GraphicsPipe(std::string display) : _xcursor_size(-1), _have_xrandr(false), _XF86DGADirectVideo(nullptr) { - std::string display_spec = display; + std::string display_spec = std::move(display); if (display_spec.empty()) { display_spec = display_cfg; } diff --git a/panda/src/x11display/x11GraphicsPipe.h b/panda/src/x11display/x11GraphicsPipe.h index b2b69cca5e2..986dce8b195 100644 --- a/panda/src/x11display/x11GraphicsPipe.h +++ b/panda/src/x11display/x11GraphicsPipe.h @@ -134,7 +134,7 @@ class FrameBufferProperties; */ class x11GraphicsPipe : public GraphicsPipe { public: - x11GraphicsPipe(const std::string &display = std::string()); + x11GraphicsPipe(std::string display = std::string()); virtual ~x11GraphicsPipe(); INLINE X11_Display *get_display() const; diff --git a/panda/src/x11display/x11GraphicsWindow.cxx b/panda/src/x11display/x11GraphicsWindow.cxx index b3363ff1107..f84b90d5814 100644 --- a/panda/src/x11display/x11GraphicsWindow.cxx +++ b/panda/src/x11display/x11GraphicsWindow.cxx @@ -91,13 +91,13 @@ TypeHandle x11GraphicsWindow::_type_handle; */ x11GraphicsWindow:: x11GraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, GraphicsStateGuardian *gsg, GraphicsOutput *host) : - GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) { + GraphicsWindow(engine, pipe, std::move(name), fb_prop, win_prop, flags, gsg, host) { x11GraphicsPipe *x11_pipe; DCAST_INTO_V(x11_pipe, _pipe); _display = x11_pipe->get_display(); diff --git a/panda/src/x11display/x11GraphicsWindow.h b/panda/src/x11display/x11GraphicsWindow.h index 4ed95c8a119..9fe9414b466 100644 --- a/panda/src/x11display/x11GraphicsWindow.h +++ b/panda/src/x11display/x11GraphicsWindow.h @@ -26,7 +26,7 @@ class x11GraphicsWindow : public GraphicsWindow { public: x11GraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, - const std::string &name, + std::string name, const FrameBufferProperties &fb_prop, const WindowProperties &win_prop, int flags, diff --git a/pandatool/src/bam/ptsToBam.cxx b/pandatool/src/bam/ptsToBam.cxx index 0059df86164..3885cdaeecd 100644 --- a/pandatool/src/bam/ptsToBam.cxx +++ b/pandatool/src/bam/ptsToBam.cxx @@ -130,7 +130,7 @@ handle_args(ProgramBase::Args &args) { * Reads a single line from the pts file. */ void PtsToBam:: -process_line(const string &line) { +process_line(std::string_view line) { _line_number++; if (_line_number % 1000000 == 0) { diff --git a/pandatool/src/bam/ptsToBam.h b/pandatool/src/bam/ptsToBam.h index 20fa76e7a9f..401b3d787f9 100644 --- a/pandatool/src/bam/ptsToBam.h +++ b/pandatool/src/bam/ptsToBam.h @@ -37,7 +37,7 @@ class PtsToBam : public ProgramBase, public WithOutputFile { virtual bool handle_args(Args &args); private: - void process_line(const std::string &line); + void process_line(std::string_view line); void add_point(const vector_string &words); void open_vertex_data(); diff --git a/pandatool/src/converter/somethingToEggConverter.I b/pandatool/src/converter/somethingToEggConverter.I index b3fed0cb112..7b1d77c975f 100644 --- a/pandatool/src/converter/somethingToEggConverter.I +++ b/pandatool/src/converter/somethingToEggConverter.I @@ -82,8 +82,8 @@ get_animation_convert() const { * its associated animations. */ INLINE void SomethingToEggConverter:: -set_character_name(const std::string &character_name) { - _character_name = character_name; +set_character_name(std::string character_name) { + _character_name = std::move(character_name); } /** diff --git a/pandatool/src/converter/somethingToEggConverter.h b/pandatool/src/converter/somethingToEggConverter.h index 16d16df50d4..b0246b76b09 100644 --- a/pandatool/src/converter/somethingToEggConverter.h +++ b/pandatool/src/converter/somethingToEggConverter.h @@ -55,7 +55,7 @@ class SomethingToEggConverter { INLINE void set_animation_convert(AnimationConvert animation_convert); INLINE AnimationConvert get_animation_convert() const; - INLINE void set_character_name(const std::string &character_name); + INLINE void set_character_name(std::string character_name); INLINE const std::string &get_character_name() const; INLINE void set_start_frame(double start_frame); diff --git a/pandatool/src/dxf/dxfFile.cxx b/pandatool/src/dxf/dxfFile.cxx index f5bb6e0912f..a2ed94a892b 100644 --- a/pandatool/src/dxf/dxfFile.cxx +++ b/pandatool/src/dxf/dxfFile.cxx @@ -623,9 +623,9 @@ change_section(Section new_section) { * creates a new layer definition. */ void DXFFile:: -change_layer(const string &layer_name) { +change_layer(string layer_name) { if (_layer == nullptr || _layer->get_name() != layer_name) { - _layer = _layers.get_layer(layer_name, this); + _layer = _layers.get_layer(std::move(layer_name), this); } } diff --git a/pandatool/src/dxf/dxfFile.h b/pandatool/src/dxf/dxfFile.h index e555960e6a1..702f51c1523 100644 --- a/pandatool/src/dxf/dxfFile.h +++ b/pandatool/src/dxf/dxfFile.h @@ -57,8 +57,8 @@ class DXFFile : public MemoryBase { // definition, and must allocate a DXFLayer instance. This function is // provided so that user code may force allocate of a specialized DXFLayer // instance instead. - virtual DXFLayer *new_layer(const std::string &name) { - return new DXFLayer(name); + virtual DXFLayer *new_layer(std::string name) { + return new DXFLayer(std::move(name)); } enum State { @@ -151,7 +151,7 @@ class DXFFile : public MemoryBase { bool get_group(); void change_state(State new_state); void change_section(Section new_section); - void change_layer(const std::string &layer_name); + void change_layer(std::string layer_name); void change_entity(Entity new_entity); void reset_entity(); diff --git a/pandatool/src/dxf/dxfLayer.cxx b/pandatool/src/dxf/dxfLayer.cxx index 6803cc179e0..8d514ca09a8 100644 --- a/pandatool/src/dxf/dxfLayer.cxx +++ b/pandatool/src/dxf/dxfLayer.cxx @@ -18,7 +18,7 @@ * */ DXFLayer:: -DXFLayer(const std::string &name) : Namable(name) { +DXFLayer(std::string name) : Namable(std::move(name)) { } /** diff --git a/pandatool/src/dxf/dxfLayer.h b/pandatool/src/dxf/dxfLayer.h index 745197280cc..89bb79ac0a0 100644 --- a/pandatool/src/dxf/dxfLayer.h +++ b/pandatool/src/dxf/dxfLayer.h @@ -27,7 +27,7 @@ */ class DXFLayer : public Namable { public: - DXFLayer(const std::string &name); + DXFLayer(std::string name); virtual ~DXFLayer(); }; diff --git a/pandatool/src/dxf/dxfLayerMap.cxx b/pandatool/src/dxf/dxfLayerMap.cxx index d2049c81910..1ab98f0969b 100644 --- a/pandatool/src/dxf/dxfLayerMap.cxx +++ b/pandatool/src/dxf/dxfLayerMap.cxx @@ -22,7 +22,7 @@ * this function to create a specialized time, if desired. */ DXFLayer *DXFLayerMap:: -get_layer(const std::string &name, DXFFile *dxffile) { +get_layer(std::string name, DXFFile *dxffile) { iterator lmi; lmi = find(name); if (lmi != end()) { @@ -32,7 +32,7 @@ get_layer(const std::string &name, DXFFile *dxffile) { // Need a new layer. DXFLayer *layer = dxffile->new_layer(name); - (*this)[name] = layer; + (*this)[std::move(name)] = layer; return layer; } diff --git a/pandatool/src/dxf/dxfLayerMap.h b/pandatool/src/dxf/dxfLayerMap.h index f2fabe53737..9d83496883d 100644 --- a/pandatool/src/dxf/dxfLayerMap.h +++ b/pandatool/src/dxf/dxfLayerMap.h @@ -27,7 +27,7 @@ class DXFFile; */ class DXFLayerMap : public pmap { public: - DXFLayer *get_layer(const std::string &name, DXFFile *dxffile); + DXFLayer *get_layer(std::string name, DXFFile *dxffile); }; #endif diff --git a/pandatool/src/dxfegg/dxfToEggConverter.cxx b/pandatool/src/dxfegg/dxfToEggConverter.cxx index 6ba6411940d..27375f0d9ac 100644 --- a/pandatool/src/dxfegg/dxfToEggConverter.cxx +++ b/pandatool/src/dxfegg/dxfToEggConverter.cxx @@ -92,8 +92,8 @@ convert_file(const Filename &filename) { * */ DXFLayer *DXFToEggConverter:: -new_layer(const std::string &name) { - return new DXFToEggLayer(name, get_egg_data()); +new_layer(std::string name) { + return new DXFToEggLayer(std::move(name), get_egg_data()); } /** diff --git a/pandatool/src/dxfegg/dxfToEggConverter.h b/pandatool/src/dxfegg/dxfToEggConverter.h index 56969e74826..3ed59dfe36c 100644 --- a/pandatool/src/dxfegg/dxfToEggConverter.h +++ b/pandatool/src/dxfegg/dxfToEggConverter.h @@ -38,7 +38,7 @@ class DXFToEggConverter : public SomethingToEggConverter, public DXFFile { virtual bool convert_file(const Filename &filename); protected: - virtual DXFLayer *new_layer(const std::string &name); + virtual DXFLayer *new_layer(std::string name); virtual void done_entity(); virtual void error(); diff --git a/pandatool/src/dxfegg/dxfToEggLayer.cxx b/pandatool/src/dxfegg/dxfToEggLayer.cxx index 3ecb915efbf..fdb914d39bd 100644 --- a/pandatool/src/dxfegg/dxfToEggLayer.cxx +++ b/pandatool/src/dxfegg/dxfToEggLayer.cxx @@ -26,10 +26,10 @@ * */ DXFToEggLayer:: -DXFToEggLayer(const std::string &name, EggGroupNode *parent) : DXFLayer(name) { +DXFToEggLayer(std::string name, EggGroupNode *parent) : DXFLayer(name) { _group = new EggGroup(name); parent->add_child(_group); - _vpool = new EggVertexPool(name); + _vpool = new EggVertexPool(std::move(name)); _group->add_child(_vpool); } diff --git a/pandatool/src/dxfegg/dxfToEggLayer.h b/pandatool/src/dxfegg/dxfToEggLayer.h index 9067cc702fb..c657b39f0de 100644 --- a/pandatool/src/dxfegg/dxfToEggLayer.h +++ b/pandatool/src/dxfegg/dxfToEggLayer.h @@ -34,7 +34,7 @@ class DXFToEggConverter; */ class DXFToEggLayer : public DXFLayer { public: - DXFToEggLayer(const std::string &name, EggGroupNode *parent); + DXFToEggLayer(std::string name, EggGroupNode *parent); void add_polygon(const DXFToEggConverter *entity); void add_line(const DXFToEggConverter *entity); diff --git a/pandatool/src/egg-mkfont/eggMakeFont.cxx b/pandatool/src/egg-mkfont/eggMakeFont.cxx index 4efa4a5ad5f..1f2e9cc1868 100644 --- a/pandatool/src/egg-mkfont/eggMakeFont.cxx +++ b/pandatool/src/egg-mkfont/eggMakeFont.cxx @@ -722,14 +722,13 @@ r_add_extra_glyphs(EggGroupNode *egg_group) { * otherwise. */ bool EggMakeFont:: -is_numeric(const string &str) { +is_numeric(std::string_view str) { if (str.empty()) { return false; } - string::const_iterator si; - for (si = str.begin(); si != str.end(); ++si) { - if (!isdigit(*si)) { + for (char ch : str) { + if (!isdigit((unsigned char)ch)) { return false; } } diff --git a/pandatool/src/egg-mkfont/eggMakeFont.h b/pandatool/src/egg-mkfont/eggMakeFont.h index 3df12af6fad..fe7ad870fed 100644 --- a/pandatool/src/egg-mkfont/eggMakeFont.h +++ b/pandatool/src/egg-mkfont/eggMakeFont.h @@ -55,7 +55,7 @@ class EggMakeFont : public EggWriter { EggTexture *make_tref(PNMTextGlyph *glyph, int character); void add_extra_glyphs(const Filename &extra_filename); void r_add_extra_glyphs(EggGroupNode *egg_group); - static bool is_numeric(const std::string &str); + static bool is_numeric(std::string_view str); private: diff --git a/pandatool/src/egg-mkfont/rangeDescription.cxx b/pandatool/src/egg-mkfont/rangeDescription.cxx index 2833f533594..f4d17c57fec 100644 --- a/pandatool/src/egg-mkfont/rangeDescription.cxx +++ b/pandatool/src/egg-mkfont/rangeDescription.cxx @@ -31,14 +31,14 @@ RangeDescription() { * parsed correctly, false otherwise. */ bool RangeDescription:: -parse_parameter(const string ¶m) { +parse_parameter(std::string_view param) { // First, go through and separate the string by commas. We have to do this // by hand instead of calling tokenize(), because we also have to scan for // square brackets, which may contain nested commas. size_t p = 0; while (p < param.length()) { size_t q = param.find_first_of("[,", p); - if (q == string::npos) { + if (q == std::string_view::npos) { return parse_word(trim(param.substr(p))); } if (!parse_word(trim(param.substr(p, q - p)))) { @@ -50,7 +50,7 @@ parse_parameter(const string ¶m) { // bracket. However, a right bracket immediately after the left bracket // doesn't count; we start the scan after that. p = param.find("]", q + 2); - if ( p == string::npos) { + if (p == std::string_view::npos) { nout << "Unclosed open bracket.\n"; return false; } @@ -96,14 +96,14 @@ output(std::ostream &out) const { * single number, or a pair of numbers separated by a hyphen. */ bool RangeDescription:: -parse_word(const string &word) { +parse_word(std::string_view word) { if (word.empty()) { return true; } // It's not empty, so see if it includes a hyphen. size_t hyphen = word.find('-'); - if (hyphen == string::npos) { + if (hyphen == std::string_view::npos) { // Nope, just one number. int code; if (!parse_code(word, code)) { @@ -131,7 +131,7 @@ parse_word(const string &word) { * in the indicated parameter. Returns true if successful, false otherwise. */ bool RangeDescription:: -parse_code(const string &word, int &code) { +parse_code(std::string_view word, int &code) { string str = trim(word); const char *nptr = str.c_str(); char *endptr; @@ -148,9 +148,8 @@ parse_code(const string &word, int &code) { * Parses the text listed between square brackets on the command line. */ bool RangeDescription:: -parse_bracket(const string &str) { - string::const_iterator si; - si = str.begin(); +parse_bracket(std::string_view str) { + auto si = str.begin(); while (si != str.end()) { int ch = (*si); ++si; diff --git a/pandatool/src/egg-mkfont/rangeDescription.h b/pandatool/src/egg-mkfont/rangeDescription.h index 25119cb16f0..b3fb05034af 100644 --- a/pandatool/src/egg-mkfont/rangeDescription.h +++ b/pandatool/src/egg-mkfont/rangeDescription.h @@ -25,7 +25,7 @@ class RangeDescription { public: RangeDescription(); - bool parse_parameter(const std::string ¶m); + bool parse_parameter(std::string_view param); INLINE void add_singleton(int code); INLINE void add_range(int from_code, int to_code); INLINE bool is_empty() const; @@ -33,9 +33,9 @@ class RangeDescription { void output(std::ostream &out) const; private: - bool parse_word(const std::string &word); - bool parse_code(const std::string &word, int &code); - bool parse_bracket(const std::string &str); + bool parse_word(std::string_view word); + bool parse_code(std::string_view word, int &code); + bool parse_bracket(std::string_view str); private: class Range { diff --git a/pandatool/src/egg-optchar/eggOptchar.cxx b/pandatool/src/egg-optchar/eggOptchar.cxx index 182b657968c..c39b7bea474 100644 --- a/pandatool/src/egg-optchar/eggOptchar.cxx +++ b/pandatool/src/egg-optchar/eggOptchar.cxx @@ -1342,7 +1342,7 @@ rename_joints() { * indicated name. */ void EggOptchar:: -change_dart_type(EggGroupNode *egg_group, const string &new_dart_type) { +change_dart_type(EggGroupNode *egg_group, std::string_view new_dart_type) { EggGroupNode::iterator gi; for (gi = egg_group->begin(); gi != egg_group->end(); ++gi) { EggNode *child = (*gi); @@ -1367,7 +1367,7 @@ change_dart_type(EggGroupNode *egg_group, const string &new_dart_type) { * indicated name. */ void EggOptchar:: -rename_primitives(EggGroupNode *egg_group, const string &name) { +rename_primitives(EggGroupNode *egg_group, std::string_view name) { EggGroupNode::iterator gi; for (gi = egg_group->begin(); gi != egg_group->end(); ++gi) { EggNode *child = (*gi); @@ -1377,7 +1377,7 @@ rename_primitives(EggGroupNode *egg_group, const string &name) { rename_primitives(group, name); } else if (child->is_of_type(EggPrimitive::get_class_type())) { - child->set_name(name); + child->set_name(std::string(name)); } } } diff --git a/pandatool/src/egg-optchar/eggOptchar.h b/pandatool/src/egg-optchar/eggOptchar.h index 30ea4cddae9..a78876b9be7 100644 --- a/pandatool/src/egg-optchar/eggOptchar.h +++ b/pandatool/src/egg-optchar/eggOptchar.h @@ -73,8 +73,8 @@ class EggOptchar : public EggCharacterFilter { void do_flag_groups(EggGroupNode *egg_group); void rename_joints(); - void rename_primitives(EggGroupNode *egg_group, const std::string &name); - void change_dart_type(EggGroupNode *egg_group, const std::string &new_dart_type); + void rename_primitives(EggGroupNode *egg_group, std::string_view name); + void change_dart_type(EggGroupNode *egg_group, std::string_view new_dart_type); void do_preload(); void do_defpose(); diff --git a/pandatool/src/egg-qtess/qtessInputEntry.I b/pandatool/src/egg-qtess/qtessInputEntry.I index d8ab6de61ef..a07c6525fc0 100644 --- a/pandatool/src/egg-qtess/qtessInputEntry.I +++ b/pandatool/src/egg-qtess/qtessInputEntry.I @@ -23,8 +23,8 @@ QtessInputEntry(const QtessInputEntry ©) { * */ INLINE void QtessInputEntry:: -add_node_name(const std::string &name) { - _node_names.push_back(GlobPattern(name)); +add_node_name(std::string name) { + _node_names.push_back(GlobPattern(std::move(name))); } /** diff --git a/pandatool/src/egg-qtess/qtessInputEntry.cxx b/pandatool/src/egg-qtess/qtessInputEntry.cxx index 66df4c88136..82a572ec361 100644 --- a/pandatool/src/egg-qtess/qtessInputEntry.cxx +++ b/pandatool/src/egg-qtess/qtessInputEntry.cxx @@ -27,14 +27,14 @@ using std::string; * */ QtessInputEntry:: -QtessInputEntry(const string &name) { +QtessInputEntry(std::string name) { _type = T_undefined; _num_patches = 0.0; _auto_place = QtessGlobals::_auto_place; _auto_distribute = QtessGlobals::_auto_distribute; _curvature_ratio = QtessGlobals::_curvature_ratio; if (!name.empty()) { - add_node_name(name); + add_node_name(std::move(name)); } } diff --git a/pandatool/src/egg-qtess/qtessInputEntry.h b/pandatool/src/egg-qtess/qtessInputEntry.h index bffcca0d4ac..c0383352413 100644 --- a/pandatool/src/egg-qtess/qtessInputEntry.h +++ b/pandatool/src/egg-qtess/qtessInputEntry.h @@ -32,11 +32,11 @@ class QtessInputEntry { T_min_u, T_min_v }; - QtessInputEntry(const std::string &name = std::string()); + QtessInputEntry(std::string name = std::string()); INLINE QtessInputEntry(const QtessInputEntry ©); void operator = (const QtessInputEntry ©); - INLINE void add_node_name(const std::string &name); + INLINE void add_node_name(std::string name); INLINE void set_importance(double i); INLINE void set_match_uu(); INLINE void set_match_vv(); diff --git a/pandatool/src/egg-qtess/qtessSurface.I b/pandatool/src/egg-qtess/qtessSurface.I index d65f82c32c1..39e6325a637 100644 --- a/pandatool/src/egg-qtess/qtessSurface.I +++ b/pandatool/src/egg-qtess/qtessSurface.I @@ -126,14 +126,14 @@ get_joint_membership_index(EggGroup *joint) { * Dxyz morph offset should be stored. */ INLINE int QtessSurface:: -get_dxyz_index(const std::string &morph_name) { +get_dxyz_index(std::string morph_name) { MorphTable::iterator mti = _dxyz_table.find(morph_name); if (mti != _dxyz_table.end()) { return (*mti).second; } int d = _next_d; _next_d += 3; - _dxyz_table[morph_name] = d; + _dxyz_table[std::move(morph_name)] = d; return d; } @@ -142,13 +142,13 @@ get_dxyz_index(const std::string &morph_name) { * Drgba morph offset should be stored. */ INLINE int QtessSurface:: -get_drgba_index(const std::string &morph_name) { +get_drgba_index(std::string morph_name) { MorphTable::iterator mti = _drgba_table.find(morph_name); if (mti != _drgba_table.end()) { return (*mti).second; } int d = _next_d; _next_d += 4; - _drgba_table[morph_name] = d; + _drgba_table[std::move(morph_name)] = d; return d; } diff --git a/pandatool/src/egg-qtess/qtessSurface.h b/pandatool/src/egg-qtess/qtessSurface.h index fc3720e5245..c12cb8acf62 100644 --- a/pandatool/src/egg-qtess/qtessSurface.h +++ b/pandatool/src/egg-qtess/qtessSurface.h @@ -60,8 +60,8 @@ class QtessSurface : public ReferenceCount { private: void record_vertex_extras(); INLINE int get_joint_membership_index(EggGroup *joint); - INLINE int get_dxyz_index(const std::string &morph_name); - INLINE int get_drgba_index(const std::string &morph_name); + INLINE int get_dxyz_index(std::string morph_name); + INLINE int get_drgba_index(std::string morph_name); void apply_match(); PT(EggGroup) do_uniform_tesselate(int &tris) const; diff --git a/pandatool/src/eggbase/eggBase.cxx b/pandatool/src/eggbase/eggBase.cxx index 83d07a0a6aa..040622ab07b 100644 --- a/pandatool/src/eggbase/eggBase.cxx +++ b/pandatool/src/eggbase/eggBase.cxx @@ -211,8 +211,8 @@ append_command_comment(EggData *data) { * EggWriter, and it's not necessary to call it explicitly. */ void EggBase:: -append_command_comment(EggData *data, const string &comment) { - data->insert(data->begin(), new EggComment("", comment)); +append_command_comment(EggData *data, std::string comment) { + data->insert(data->begin(), new EggComment("", std::move(comment))); } /** diff --git a/pandatool/src/eggbase/eggBase.h b/pandatool/src/eggbase/eggBase.h index 4c6b156721c..437ae00807f 100644 --- a/pandatool/src/eggbase/eggBase.h +++ b/pandatool/src/eggbase/eggBase.h @@ -39,7 +39,7 @@ class EggBase : public ProgramBase { protected: void append_command_comment(EggData *_data); - static void append_command_comment(EggData *_data, const std::string &comment); + static void append_command_comment(EggData *_data, std::string comment); static bool dispatch_normals(ProgramBase *self, const std::string &opt, const std::string &arg, void *mode); bool ns_dispatch_normals(const std::string &opt, const std::string &arg, void *mode); diff --git a/pandatool/src/eggbase/eggConverter.cxx b/pandatool/src/eggbase/eggConverter.cxx index 036b7dea18f..344ee5a0eec 100644 --- a/pandatool/src/eggbase/eggConverter.cxx +++ b/pandatool/src/eggbase/eggConverter.cxx @@ -21,14 +21,14 @@ * with a leading dot. */ EggConverter:: -EggConverter(const std::string &format_name, - const std::string &preferred_extension, +EggConverter(std::string format_name, + std::string preferred_extension, bool allow_last_param, bool allow_stdout) : EggFilter(allow_last_param, allow_stdout), - _format_name(format_name) + _format_name(std::move(format_name)) { // Indicate the extension name we expect the user to supply for output // files. - _preferred_extension = preferred_extension; + _preferred_extension = std::move(preferred_extension); } diff --git a/pandatool/src/eggbase/eggConverter.h b/pandatool/src/eggbase/eggConverter.h index 3922a6b842c..d4cc173788b 100644 --- a/pandatool/src/eggbase/eggConverter.h +++ b/pandatool/src/eggbase/eggConverter.h @@ -24,8 +24,8 @@ */ class EggConverter : public EggFilter { public: - EggConverter(const std::string &format_name, - const std::string &preferred_extension = std::string(), + EggConverter(std::string format_name, + std::string preferred_extension = std::string(), bool allow_last_param = true, bool allow_stdout = true); diff --git a/pandatool/src/eggbase/eggToSomething.cxx b/pandatool/src/eggbase/eggToSomething.cxx index eb6adc89e51..ccaff8cf696 100644 --- a/pandatool/src/eggbase/eggToSomething.cxx +++ b/pandatool/src/eggbase/eggToSomething.cxx @@ -19,10 +19,10 @@ * just used in printing error messages and such. */ EggToSomething:: -EggToSomething(const std::string &format_name, - const std::string &preferred_extension, +EggToSomething(std::string format_name, + std::string preferred_extension, bool allow_last_param, bool allow_stdout) : - EggConverter(format_name, preferred_extension, allow_last_param, + EggConverter(std::move(format_name), std::move(preferred_extension), allow_last_param, allow_stdout) { clear_runlines(); @@ -39,28 +39,28 @@ EggToSomething(const std::string &format_name, if (_allow_stdout) { if (_allow_last_param) { o_description = - "Specify the filename to which the resulting " + format_name + + "Specify the filename to which the resulting " + _format_name + " file will be written. " "If this option is omitted, the last parameter name is taken to be the " "name of the output file, or standard output is used if there are no " "other parameters."; } else { o_description = - "Specify the filename to which the resulting " + format_name + + "Specify the filename to which the resulting " + _format_name + " file will be written. " - "If this option is omitted, the " + format_name + + "If this option is omitted, the " + _format_name + " file is written to standard output."; } } else { if (_allow_last_param) { o_description = - "Specify the filename to which the resulting " + format_name + + "Specify the filename to which the resulting " + _format_name + " file will be written. " "If this option is omitted, the last parameter name is taken to be the " "name of the output file."; } else { o_description = - "Specify the filename to which the resulting " + format_name + + "Specify the filename to which the resulting " + _format_name + " file will be written."; } } diff --git a/pandatool/src/eggbase/eggToSomething.h b/pandatool/src/eggbase/eggToSomething.h index aafc045a3dc..aa611f8334a 100644 --- a/pandatool/src/eggbase/eggToSomething.h +++ b/pandatool/src/eggbase/eggToSomething.h @@ -25,8 +25,8 @@ */ class EggToSomething : public EggConverter { public: - EggToSomething(const std::string &format_name, - const std::string &preferred_extension = std::string(), + EggToSomething(std::string format_name, + std::string preferred_extension = std::string(), bool allow_last_param = true, bool allow_stdout = true); diff --git a/pandatool/src/eggbase/somethingToEgg.cxx b/pandatool/src/eggbase/somethingToEgg.cxx index 45d705f12cd..5d9136219bd 100644 --- a/pandatool/src/eggbase/somethingToEgg.cxx +++ b/pandatool/src/eggbase/somethingToEgg.cxx @@ -22,10 +22,10 @@ * just used in printing error messages and such. */ SomethingToEgg:: -SomethingToEgg(const std::string &format_name, - const std::string &preferred_extension, +SomethingToEgg(std::string format_name, + std::string preferred_extension, bool allow_last_param, bool allow_stdout) : - EggConverter(format_name, preferred_extension, allow_last_param, allow_stdout) + EggConverter(std::move(format_name), std::move(preferred_extension), allow_last_param, allow_stdout) { clear_runlines(); if (_allow_last_param) { diff --git a/pandatool/src/eggbase/somethingToEgg.h b/pandatool/src/eggbase/somethingToEgg.h index 5c5427dcded..a9b8ea74e0b 100644 --- a/pandatool/src/eggbase/somethingToEgg.h +++ b/pandatool/src/eggbase/somethingToEgg.h @@ -28,8 +28,8 @@ class SomethingToEggConverter; */ class SomethingToEgg : public EggConverter { public: - SomethingToEgg(const std::string &format_name, - const std::string &preferred_extension = std::string(), + SomethingToEgg(std::string format_name, + std::string preferred_extension = std::string(), bool allow_last_param = true, bool allow_stdout = true); diff --git a/pandatool/src/eggcharbase/eggBackPointer.cxx b/pandatool/src/eggcharbase/eggBackPointer.cxx index cc6110d0753..13cc6b21771 100644 --- a/pandatool/src/eggcharbase/eggBackPointer.cxx +++ b/pandatool/src/eggcharbase/eggBackPointer.cxx @@ -57,5 +57,5 @@ has_vertices() const { * Applies the indicated name change to the egg file. */ void EggBackPointer:: -set_name(const std::string &name) { +set_name(std::string name) { } diff --git a/pandatool/src/eggcharbase/eggBackPointer.h b/pandatool/src/eggcharbase/eggBackPointer.h index 2595c09d18a..8c5c51eedb9 100644 --- a/pandatool/src/eggcharbase/eggBackPointer.h +++ b/pandatool/src/eggcharbase/eggBackPointer.h @@ -37,7 +37,7 @@ class EggBackPointer : public TypedObject { virtual void extend_to(int num_frames); virtual bool has_vertices() const; - virtual void set_name(const std::string &name); + virtual void set_name(std::string name); public: static TypeHandle get_class_type() { diff --git a/pandatool/src/eggcharbase/eggCharacterCollection.cxx b/pandatool/src/eggcharbase/eggCharacterCollection.cxx index f90c7d9a915..b478a2d1fd1 100644 --- a/pandatool/src/eggcharbase/eggCharacterCollection.cxx +++ b/pandatool/src/eggcharbase/eggCharacterCollection.cxx @@ -118,7 +118,7 @@ add_egg(EggData *egg) { * collection, or NULL if it does not. */ EggCharacterData *EggCharacterCollection:: -get_character_by_name(const string &character_name) const { +get_character_by_name(std::string_view character_name) const { Characters::const_iterator ci; for (ci = _characters.begin(); ci != _characters.end(); ++ci) { EggCharacterData *char_data = (*ci); @@ -167,7 +167,7 @@ make_slider_data(EggCharacterData *char_data) { * character, if there is not already a character by that name. */ EggCharacterData *EggCharacterCollection:: -make_character(const string &character_name) { +make_character(std::string character_name) { // Does the named character exist yet? Characters::iterator ci; @@ -180,7 +180,7 @@ make_character(const string &character_name) { // Define a new character. EggCharacterData *char_data = make_character_data(); - char_data->set_name(character_name); + char_data->set_name(std::move(character_name)); _characters.push_back(char_data); return char_data; } @@ -614,13 +614,13 @@ found_egg_match(EggCharacterData *char_data, EggJointData *joint_data, * already be used by another character in the collection. */ void EggCharacterCollection:: -rename_char(int i, const string &name) { +rename_char(int i, std::string name) { nassertv(i >= 0 && i < (int)_characters.size()); EggCharacterData *char_data = _characters[i]; if (char_data->get_name() != name) { nassertv(get_character_by_name(name) == nullptr); - char_data->rename_char(name); + char_data->rename_char(std::move(name)); } } diff --git a/pandatool/src/eggcharbase/eggCharacterCollection.h b/pandatool/src/eggcharbase/eggCharacterCollection.h index 8a0bbd4f28b..fe01d621d04 100644 --- a/pandatool/src/eggcharbase/eggCharacterCollection.h +++ b/pandatool/src/eggcharbase/eggCharacterCollection.h @@ -43,11 +43,11 @@ class EggCharacterCollection { INLINE int get_num_characters() const; INLINE EggCharacterData *get_character(int i) const; - EggCharacterData *get_character_by_name(const std::string &character_name) const; + EggCharacterData *get_character_by_name(std::string_view character_name) const; INLINE EggCharacterData *get_character_by_model_index(int model_index) const; - void rename_char(int i, const std::string &name); + void rename_char(int i, std::string name); virtual void write(std::ostream &out, int indent_level = 0) const; void check_errors(std::ostream &out, bool force_initial_rest_frame); @@ -57,7 +57,7 @@ class EggCharacterCollection { virtual EggSliderData *make_slider_data(EggCharacterData *char_data); public: - EggCharacterData *make_character(const std::string &character_name); + EggCharacterData *make_character(std::string character_name); class EggInfo { public: diff --git a/pandatool/src/eggcharbase/eggCharacterData.I b/pandatool/src/eggcharbase/eggCharacterData.I index fc3d3f1bcc9..c7f299a17d3 100644 --- a/pandatool/src/eggcharbase/eggCharacterData.I +++ b/pandatool/src/eggcharbase/eggCharacterData.I @@ -77,7 +77,7 @@ get_root_joint() const { * has that name. */ INLINE EggJointData *EggCharacterData:: -find_joint(const std::string &name) const { +find_joint(std::string_view name) const { return _root_joint->find_joint(name); } @@ -87,8 +87,8 @@ find_joint(const std::string &name) const { * inherits the net transform of the indicated parent joint. */ INLINE EggJointData *EggCharacterData:: -make_new_joint(const std::string &name, EggJointData *parent) { - EggJointData *joint = parent->make_new_joint(name); +make_new_joint(std::string name, EggJointData *parent) { + EggJointData *joint = parent->make_new_joint(std::move(name)); _joints.push_back(joint); _components.push_back(joint); return joint; diff --git a/pandatool/src/eggcharbase/eggCharacterData.cxx b/pandatool/src/eggcharbase/eggCharacterData.cxx index d3c7a545305..ab9c70ab9b8 100644 --- a/pandatool/src/eggcharbase/eggCharacterData.cxx +++ b/pandatool/src/eggcharbase/eggCharacterData.cxx @@ -63,13 +63,13 @@ EggCharacterData:: * as if they are expected to have the same skeleton hierarchy. */ void EggCharacterData:: -rename_char(const std::string &name) { +rename_char(std::string name) { Models::iterator mi; for (mi = _models.begin(); mi != _models.end(); ++mi) { (*mi)._model_root->set_name(name); } - set_name(name); + set_name(std::move(name)); } /** @@ -338,7 +338,7 @@ choose_optimal_hierarchy() { * name. */ EggSliderData *EggCharacterData:: -find_slider(const std::string &name) const { +find_slider(std::string_view name) const { SlidersByName::const_iterator si; si = _sliders_by_name.find(name); if (si != _sliders_by_name.end()) { @@ -353,7 +353,7 @@ find_slider(const std::string &name) const { * already, creates a new one. */ EggSliderData *EggCharacterData:: -make_slider(const std::string &name) { +make_slider(std::string name) { SlidersByName::const_iterator si; si = _sliders_by_name.find(name); if (si != _sliders_by_name.end()) { @@ -362,7 +362,7 @@ make_slider(const std::string &name) { EggSliderData *slider = _collection->make_slider_data(this); slider->set_name(name); - _sliders_by_name.insert(SlidersByName::value_type(name, slider)); + _sliders_by_name.insert(SlidersByName::value_type(std::move(name), slider)); _sliders.push_back(slider); _components.push_back(slider); return slider; diff --git a/pandatool/src/eggcharbase/eggCharacterData.h b/pandatool/src/eggcharbase/eggCharacterData.h index f488e335367..cdd0aeb3105 100644 --- a/pandatool/src/eggcharbase/eggCharacterData.h +++ b/pandatool/src/eggcharbase/eggCharacterData.h @@ -54,7 +54,7 @@ class EggCharacterData : public Namable { EggCharacterData(EggCharacterCollection *collection); virtual ~EggCharacterData(); - void rename_char(const std::string &name); + void rename_char(std::string name); void add_model(int model_index, EggNode *model_root, EggData *egg_data); INLINE int get_num_models() const; @@ -66,8 +66,8 @@ class EggCharacterData : public Namable { double get_frame_rate(int model_index) const; INLINE EggJointData *get_root_joint() const; - INLINE EggJointData *find_joint(const std::string &name) const; - INLINE EggJointData *make_new_joint(const std::string &name, EggJointData *parent); + INLINE EggJointData *find_joint(std::string_view name) const; + INLINE EggJointData *make_new_joint(std::string name, EggJointData *parent); INLINE int get_num_joints() const; INLINE EggJointData *get_joint(int n) const; @@ -76,8 +76,8 @@ class EggCharacterData : public Namable { INLINE int get_num_sliders() const; INLINE EggSliderData *get_slider(int n) const; - EggSliderData *find_slider(const std::string &name) const; - EggSliderData *make_slider(const std::string &name); + EggSliderData *find_slider(std::string_view name) const; + EggSliderData *make_slider(std::string name); INLINE int get_num_components() const; INLINE EggComponentData *get_component(int n) const; @@ -99,7 +99,7 @@ class EggCharacterData : public Namable { EggCharacterCollection *_collection; EggJointData *_root_joint; - typedef pmap SlidersByName; + typedef pmap> SlidersByName; SlidersByName _sliders_by_name; typedef pvector Sliders; diff --git a/pandatool/src/eggcharbase/eggComponentData.cxx b/pandatool/src/eggcharbase/eggComponentData.cxx index ab57e5bd53e..43a5594aa6d 100644 --- a/pandatool/src/eggcharbase/eggComponentData.cxx +++ b/pandatool/src/eggcharbase/eggComponentData.cxx @@ -49,8 +49,8 @@ EggComponentData:: * matched_name(). */ void EggComponentData:: -add_name(const std::string &name, NameUniquifier &uniquifier) { - if (_names.insert(name).second) { +add_name(std::string_view name, NameUniquifier &uniquifier) { + if (_names.emplace(name).second) { // This is a new name for this component. if (!has_name()) { set_name(uniquifier.add_name(name)); @@ -67,7 +67,7 @@ add_name(const std::string &name, NameUniquifier &uniquifier) { * with this particular joint, false otherwise. */ bool EggComponentData:: -matches_name(const std::string &name) const { +matches_name(std::string_view name) const { if (name == get_name()) { return true; } diff --git a/pandatool/src/eggcharbase/eggComponentData.h b/pandatool/src/eggcharbase/eggComponentData.h index b54c20ffb6f..8184b55ca37 100644 --- a/pandatool/src/eggcharbase/eggComponentData.h +++ b/pandatool/src/eggcharbase/eggComponentData.h @@ -37,8 +37,8 @@ class EggComponentData : public EggObject, public Namable { EggCharacterData *char_data); virtual ~EggComponentData(); - void add_name(const std::string &name, NameUniquifier &uniquifier); - bool matches_name(const std::string &name) const; + void add_name(std::string_view name, NameUniquifier &uniquifier); + bool matches_name(std::string_view name) const; int get_num_frames(int model_index) const; void extend_to(int model_index, int num_frames) const; @@ -59,7 +59,7 @@ class EggComponentData : public EggObject, public Namable { typedef pvector BackPointers; BackPointers _back_pointers; - typedef pset Names; + typedef pset> Names; Names _names; EggCharacterCollection *_collection; diff --git a/pandatool/src/eggcharbase/eggJointData.I b/pandatool/src/eggcharbase/eggJointData.I index c8b81967eed..a1c5ba07a0a 100644 --- a/pandatool/src/eggcharbase/eggJointData.I +++ b/pandatool/src/eggcharbase/eggJointData.I @@ -41,7 +41,7 @@ get_child(int n) const { * if no joint has that name. */ INLINE EggJointData *EggJointData:: -find_joint(const std::string &name) { +find_joint(std::string_view name) { EggJointData *joint = find_joint_exact(name); if (joint == nullptr) { joint = find_joint_matches(name); diff --git a/pandatool/src/eggcharbase/eggJointData.cxx b/pandatool/src/eggcharbase/eggJointData.cxx index ebf656b113c..b96930bae84 100644 --- a/pandatool/src/eggcharbase/eggJointData.cxx +++ b/pandatool/src/eggcharbase/eggJointData.cxx @@ -347,7 +347,7 @@ expose(EggGroup::DCSType dcs_type) { * downwards. */ void EggJointData:: -zero_channels(const string &components) { +zero_channels(std::string_view components) { BackPointers::iterator bpi; for (bpi = _back_pointers.begin(); bpi != _back_pointers.end(); ++bpi) { EggBackPointer *back = (*bpi); @@ -364,7 +364,7 @@ zero_channels(const string &components) { * downwards to all joints below. */ void EggJointData:: -quantize_channels(const string &components, double quantum) { +quantize_channels(std::string_view components, double quantum) { BackPointers::iterator bpi; for (bpi = _back_pointers.begin(); bpi != _back_pointers.end(); ++bpi) { EggBackPointer *back = (*bpi); @@ -628,7 +628,7 @@ do_finish_reparent() { * intended to be called only from EggCharacterData::make_new_joint(). */ EggJointData *EggJointData:: -make_new_joint(const string &name) { +make_new_joint(std::string name) { EggJointData *child = new EggJointData(_collection, _char_data); child->set_name(name); child->_parent = this; @@ -654,7 +654,7 @@ make_new_joint(const string &name) { * recursively for an exact match of the preferred joint name. */ EggJointData *EggJointData:: -find_joint_exact(const string &name) { +find_joint_exact(std::string_view name) { Children::const_iterator ci; for (ci = _children.begin(); ci != _children.end(); ++ci) { EggJointData *child = (*ci); @@ -675,7 +675,7 @@ find_joint_exact(const string &name) { * recursively for any acceptable match. */ EggJointData *EggJointData:: -find_joint_matches(const string &name) { +find_joint_matches(std::string_view name) { Children::const_iterator ci; for (ci = _children.begin(); ci != _children.end(); ++ci) { EggJointData *child = (*ci); diff --git a/pandatool/src/eggcharbase/eggJointData.h b/pandatool/src/eggcharbase/eggJointData.h index bf9cf7b3d18..6cabf0656f0 100644 --- a/pandatool/src/eggcharbase/eggJointData.h +++ b/pandatool/src/eggcharbase/eggJointData.h @@ -36,7 +36,7 @@ class EggJointData : public EggComponentData { INLINE EggJointData *get_parent() const; INLINE int get_num_children() const; INLINE EggJointData *get_child(int n) const; - INLINE EggJointData *find_joint(const std::string &name); + INLINE EggJointData *find_joint(std::string_view name); LMatrix4d get_frame(int model_index, int n) const; LMatrix4d get_net_frame(int model_index, int n, EggCharacterDb &db) const; @@ -54,8 +54,8 @@ class EggJointData : public EggComponentData { bool do_rebuild_all(EggCharacterDb &db); void optimize(); void expose(EggGroup::DCSType dcs_type = EggGroup::DC_default); - void zero_channels(const std::string &components); - void quantize_channels(const std::string &components, double quantum); + void zero_channels(std::string_view components); + void quantize_channels(std::string_view components, double quantum); void apply_default_pose(int source_model, int frame); virtual void add_back_pointer(int model_index, EggObject *egg_object); @@ -70,9 +70,9 @@ class EggJointData : public EggComponentData { void do_finish_reparent(); private: - EggJointData *make_new_joint(const std::string &name); - EggJointData *find_joint_exact(const std::string &name); - EggJointData *find_joint_matches(const std::string &name); + EggJointData *make_new_joint(std::string name); + EggJointData *find_joint_exact(std::string_view name); + EggJointData *find_joint_matches(std::string_view name); bool is_new_ancestor(EggJointData *child) const; const LMatrix4d &get_new_net_frame(int model_index, int n, EggCharacterDb &db); diff --git a/pandatool/src/eggcharbase/eggJointNodePointer.cxx b/pandatool/src/eggcharbase/eggJointNodePointer.cxx index 23bf7ea480f..fd867fd0884 100644 --- a/pandatool/src/eggcharbase/eggJointNodePointer.cxx +++ b/pandatool/src/eggcharbase/eggJointNodePointer.cxx @@ -193,8 +193,8 @@ has_vertices() const { * pointer to it. */ EggJointPointer *EggJointNodePointer:: -make_new_joint(const std::string &name) { - EggGroup *new_joint = new EggGroup(name); +make_new_joint(std::string name) { + EggGroup *new_joint = new EggGroup(std::move(name)); new_joint->set_group_type(EggGroup::GT_joint); _joint->add_child(new_joint); return new EggJointNodePointer(new_joint); @@ -204,6 +204,6 @@ make_new_joint(const std::string &name) { * Applies the indicated name change to the egg file. */ void EggJointNodePointer:: -set_name(const std::string &name) { - _joint->set_name(name); +set_name(std::string name) { + _joint->set_name(std::move(name)); } diff --git a/pandatool/src/eggcharbase/eggJointNodePointer.h b/pandatool/src/eggcharbase/eggJointNodePointer.h index 8a979f11d58..2a66c52c012 100644 --- a/pandatool/src/eggcharbase/eggJointNodePointer.h +++ b/pandatool/src/eggcharbase/eggJointNodePointer.h @@ -41,9 +41,9 @@ class EggJointNodePointer : public EggJointPointer { virtual bool has_vertices() const; - virtual EggJointPointer *make_new_joint(const std::string &name); + virtual EggJointPointer *make_new_joint(std::string name); - virtual void set_name(const std::string &name); + virtual void set_name(std::string name); private: PT(EggGroup) _joint; diff --git a/pandatool/src/eggcharbase/eggJointPointer.cxx b/pandatool/src/eggcharbase/eggJointPointer.cxx index 6a5ed440037..987b42b44d7 100644 --- a/pandatool/src/eggcharbase/eggJointPointer.cxx +++ b/pandatool/src/eggcharbase/eggJointPointer.cxx @@ -69,7 +69,7 @@ expose(EggGroup::DCSType) { * Zeroes out the named components of the transform in the animation frames. */ void EggJointPointer:: -zero_channels(const std::string &) { +zero_channels(std::string_view) { } /** @@ -77,7 +77,7 @@ zero_channels(const std::string &) { * quantum. */ void EggJointPointer:: -quantize_channels(const std::string &, double) { +quantize_channels(std::string_view, double) { } /** diff --git a/pandatool/src/eggcharbase/eggJointPointer.h b/pandatool/src/eggcharbase/eggJointPointer.h index 94a8a3180e6..c43521aecf3 100644 --- a/pandatool/src/eggcharbase/eggJointPointer.h +++ b/pandatool/src/eggcharbase/eggJointPointer.h @@ -42,11 +42,11 @@ class EggJointPointer : public EggBackPointer { virtual void optimize(); virtual void expose(EggGroup::DCSType dcs_type); - virtual void zero_channels(const std::string &components); - virtual void quantize_channels(const std::string &components, double quantum); + virtual void zero_channels(std::string_view components); + virtual void quantize_channels(std::string_view components, double quantum); virtual void apply_default_pose(EggJointPointer *source_joint, int frame); - virtual EggJointPointer *make_new_joint(const std::string &name)=0; + virtual EggJointPointer *make_new_joint(std::string name)=0; public: static TypeHandle get_class_type() { diff --git a/pandatool/src/eggcharbase/eggMatrixTablePointer.cxx b/pandatool/src/eggcharbase/eggMatrixTablePointer.cxx index 267296483f3..2e05e198e8a 100644 --- a/pandatool/src/eggcharbase/eggMatrixTablePointer.cxx +++ b/pandatool/src/eggcharbase/eggMatrixTablePointer.cxx @@ -226,16 +226,15 @@ optimize() { * Zeroes out the named components of the transform in the animation frames. */ void EggMatrixTablePointer:: -zero_channels(const string &components) { +zero_channels(std::string_view components) { if (_xform == nullptr) { return; } // This is particularly easy: we only have to remove children from the // _xform object whose name is listed in the components. - string::const_iterator si; - for (si = components.begin(); si != components.end(); ++si) { - string table_name(1, *si); + for (char ch : components) { + string table_name(1, ch); EggNode *child = _xform->find_child(table_name); if (child != nullptr) { _xform->remove_child(child); @@ -248,16 +247,15 @@ zero_channels(const string &components) { * quantum. */ void EggMatrixTablePointer:: -quantize_channels(const string &components, double quantum) { +quantize_channels(std::string_view components, double quantum) { if (_xform == nullptr) { return; } // This is similar to the above: we quantize children of the _xform object // whose name is listed in the components. - string::const_iterator si; - for (si = components.begin(); si != components.end(); ++si) { - string table_name(1, *si); + for (char ch : components) { + string table_name(1, ch); EggNode *child = _xform->find_child(table_name); if (child != nullptr && child->is_of_type(EggSAnimData::get_class_type())) { @@ -272,8 +270,8 @@ quantize_channels(const string &components, double quantum) { * pointer to it. */ EggJointPointer *EggMatrixTablePointer:: -make_new_joint(const string &name) { - EggTable *new_table = new EggTable(name); +make_new_joint(std::string name) { + EggTable *new_table = new EggTable(std::move(name)); _table->add_child(new_table); CoordinateSystem cs = CS_default; if (_xform != nullptr) { @@ -290,6 +288,6 @@ make_new_joint(const string &name) { * Applies the indicated name change to the egg file. */ void EggMatrixTablePointer:: -set_name(const string &name) { - _table->set_name(name); +set_name(std::string name) { + _table->set_name(std::move(name)); } diff --git a/pandatool/src/eggcharbase/eggMatrixTablePointer.h b/pandatool/src/eggcharbase/eggMatrixTablePointer.h index cbdeeecc5a0..30b4bca3ae8 100644 --- a/pandatool/src/eggcharbase/eggMatrixTablePointer.h +++ b/pandatool/src/eggcharbase/eggMatrixTablePointer.h @@ -43,12 +43,12 @@ class EggMatrixTablePointer : public EggJointPointer { virtual bool do_rebuild(EggCharacterDb &db); virtual void optimize(); - virtual void zero_channels(const std::string &components); - virtual void quantize_channels(const std::string &components, double quantum); + virtual void zero_channels(std::string_view components); + virtual void quantize_channels(std::string_view components, double quantum); - virtual EggJointPointer *make_new_joint(const std::string &name); + virtual EggJointPointer *make_new_joint(std::string name); - virtual void set_name(const std::string &name); + virtual void set_name(std::string name); private: PT(EggTable) _table; diff --git a/pandatool/src/eggcharbase/eggScalarTablePointer.cxx b/pandatool/src/eggcharbase/eggScalarTablePointer.cxx index 450bb548cee..4f7801b6a3d 100644 --- a/pandatool/src/eggcharbase/eggScalarTablePointer.cxx +++ b/pandatool/src/eggcharbase/eggScalarTablePointer.cxx @@ -89,7 +89,7 @@ get_frame(int n) const { * Applies the indicated name change to the egg file. */ void EggScalarTablePointer:: -set_name(const std::string &name) { +set_name(std::string name) { // Actually, let's not rename the slider table (yet), because we haven't // written the code to rename all of the morph targets. diff --git a/pandatool/src/eggcharbase/eggScalarTablePointer.h b/pandatool/src/eggcharbase/eggScalarTablePointer.h index c0a74879739..3125fc34e8e 100644 --- a/pandatool/src/eggcharbase/eggScalarTablePointer.h +++ b/pandatool/src/eggcharbase/eggScalarTablePointer.h @@ -35,7 +35,7 @@ class EggScalarTablePointer : public EggSliderPointer { virtual void extend_to(int num_frames); virtual double get_frame(int n) const; - virtual void set_name(const std::string &name); + virtual void set_name(std::string name); private: PT(EggSAnimData) _data; diff --git a/pandatool/src/flt/fltBeadID.cxx b/pandatool/src/flt/fltBeadID.cxx index 4b6dc695a73..0d36d2eef0b 100644 --- a/pandatool/src/flt/fltBeadID.cxx +++ b/pandatool/src/flt/fltBeadID.cxx @@ -38,8 +38,8 @@ get_id() const { * is unique to this bead. */ void FltBeadID:: -set_id(const std::string &id) { - _id = id; +set_id(std::string id) { + _id = std::move(id); } /** diff --git a/pandatool/src/flt/fltBeadID.h b/pandatool/src/flt/fltBeadID.h index d7e943b2070..7b6173b3020 100644 --- a/pandatool/src/flt/fltBeadID.h +++ b/pandatool/src/flt/fltBeadID.h @@ -26,7 +26,7 @@ class FltBeadID : public FltBead { FltBeadID(FltHeader *header); const std::string &get_id() const; - void set_id(const std::string &id); + void set_id(std::string id); virtual void output(std::ostream &out) const; diff --git a/pandatool/src/flt/fltRecord.cxx b/pandatool/src/flt/fltRecord.cxx index 9fcc52fcfa0..9a76f770dd9 100644 --- a/pandatool/src/flt/fltRecord.cxx +++ b/pandatool/src/flt/fltRecord.cxx @@ -237,8 +237,8 @@ clear_comment() { * Changes the comment for this record. */ void FltRecord:: -set_comment(const std::string &comment) { - _comment = comment; +set_comment(std::string comment) { + _comment = std::move(comment); } /** @@ -251,7 +251,7 @@ set_comment(const std::string &comment) { * this is exactly the sort of thing we expect. */ void FltRecord:: -check_remaining_size(const DatagramIterator &di, const std::string &name) const { +check_remaining_size(const DatagramIterator &di, std::string_view name) const { if (di.get_remaining_size() == 0) { return; } diff --git a/pandatool/src/flt/fltRecord.h b/pandatool/src/flt/fltRecord.h index 9fc8e3ad3e1..019166f6d3b 100644 --- a/pandatool/src/flt/fltRecord.h +++ b/pandatool/src/flt/fltRecord.h @@ -61,10 +61,10 @@ class FltRecord : public TypedReferenceCount { bool has_comment() const; const std::string &get_comment() const; void clear_comment(); - void set_comment(const std::string &comment); + void set_comment(std::string comment); void check_remaining_size(const DatagramIterator &di, - const std::string &name = std::string()) const; + std::string_view name = std::string_view()) const; virtual void apply_converted_filenames(); diff --git a/pandatool/src/fltegg/fltToEggConverter.cxx b/pandatool/src/fltegg/fltToEggConverter.cxx index 98b01938c5f..494c9f04db1 100644 --- a/pandatool/src/fltegg/fltToEggConverter.cxx +++ b/pandatool/src/fltegg/fltToEggConverter.cxx @@ -585,7 +585,7 @@ parse_comment(const FltTexture *flt_texture, EggNode *egg_node) { * success, false on syntax error (in which case _error is also set to true). */ bool FltToEggConverter:: -parse_comment(const string &comment, const string &name, +parse_comment(std::string_view comment, std::string_view name, EggNode *egg_node) { if (comment.empty()) { // No comment. @@ -633,7 +633,7 @@ parse_comment(const string &comment, const string &name, return false; } - string egg_syntax = comment.substr(p, q - p); + string egg_syntax(comment.substr(p, q - p)); if (!egg_node->parse_egg(egg_syntax)) { nout << "Syntax error in comment for " diff --git a/pandatool/src/fltegg/fltToEggConverter.h b/pandatool/src/fltegg/fltToEggConverter.h index c9e8cc61c14..37be91a1f2f 100644 --- a/pandatool/src/fltegg/fltToEggConverter.h +++ b/pandatool/src/fltegg/fltToEggConverter.h @@ -91,7 +91,7 @@ class FltToEggConverter : public SomethingToEggConverter { bool parse_comment(const FltBeadID *flt_bead, EggNode *egg_node); bool parse_comment(const FltBead *flt_bead, EggNode *egg_node); bool parse_comment(const FltTexture *flt_texture, EggNode *egg_node); - bool parse_comment(const std::string &comment, const std::string &name, + bool parse_comment(std::string_view comment, std::string_view name, EggNode *egg_node); PT_EggVertex make_egg_vertex(const FltVertex *flt_vertex); diff --git a/pandatool/src/fltegg/fltToEggLevelState.cxx b/pandatool/src/fltegg/fltToEggLevelState.cxx index ef396fd818d..d33629de4da 100644 --- a/pandatool/src/fltegg/fltToEggLevelState.cxx +++ b/pandatool/src/fltegg/fltToEggLevelState.cxx @@ -56,7 +56,7 @@ ParentNodes() { * group per polygon. */ EggGroupNode *FltToEggLevelState:: -get_synthetic_group(const std::string &name, +get_synthetic_group(std::string name, const FltBead *transform_bead, FltGeometry::BillboardType type) { LMatrix4d transform = transform_bead->get_transform(); @@ -83,7 +83,7 @@ get_synthetic_group(const std::string &name, switch (type) { case FltGeometry::BT_axial: if (nodes->_axial_billboard == nullptr) { - nodes->_axial_billboard = new EggGroup(name); + nodes->_axial_billboard = new EggGroup(std::move(name)); _egg_parent->add_child(nodes->_axial_billboard); nodes->_axial_billboard->set_billboard_type(EggGroup::BT_axis); if (!is_identity) { @@ -95,7 +95,7 @@ get_synthetic_group(const std::string &name, case FltGeometry::BT_point: if (nodes->_point_billboard == nullptr) { - nodes->_point_billboard = new EggGroup(name); + nodes->_point_billboard = new EggGroup(std::move(name)); _egg_parent->add_child(nodes->_point_billboard); nodes->_point_billboard->set_billboard_type(EggGroup::BT_point_world_relative); if (!is_identity) { @@ -108,7 +108,7 @@ get_synthetic_group(const std::string &name, default: // Normally, BT_none, although we've occasionally seen a // value of 3 come in here, whatever that's supposed to mean. if (nodes->_plain == nullptr) { - nodes->_plain = new EggGroup(name); + nodes->_plain = new EggGroup(std::move(name)); _egg_parent->add_child(nodes->_plain); if (!is_identity) { set_transform(transform_bead, nodes->_plain); diff --git a/pandatool/src/fltegg/fltToEggLevelState.h b/pandatool/src/fltegg/fltToEggLevelState.h index 91877e2306b..5eca23bfb4a 100644 --- a/pandatool/src/fltegg/fltToEggLevelState.h +++ b/pandatool/src/fltegg/fltToEggLevelState.h @@ -34,7 +34,7 @@ class FltToEggLevelState { INLINE void operator = (const FltToEggLevelState ©); ~FltToEggLevelState(); - EggGroupNode *get_synthetic_group(const std::string &name, + EggGroupNode *get_synthetic_group(std::string name, const FltBead *transform_bead, FltGeometry::BillboardType type = FltGeometry::BT_none); diff --git a/pandatool/src/fltprogs/eggToFlt.cxx b/pandatool/src/fltprogs/eggToFlt.cxx index f6cbc9d24ff..994f00ba42b 100644 --- a/pandatool/src/fltprogs/eggToFlt.cxx +++ b/pandatool/src/fltprogs/eggToFlt.cxx @@ -450,7 +450,7 @@ apply_transform(EggTransform *egg_transform, FltBead *flt_node) { * comment, so that flt2egg will reapply it to the egg groups. */ void EggToFlt:: -apply_egg_syntax(const std::string &egg_syntax, FltRecord *flt_record) { +apply_egg_syntax(std::string_view egg_syntax, FltRecord *flt_record) { if (!egg_syntax.empty()) { std::ostringstream out; out << " {\n" diff --git a/pandatool/src/fltprogs/eggToFlt.h b/pandatool/src/fltprogs/eggToFlt.h index 0cbcb2126d6..f1a023ef141 100644 --- a/pandatool/src/fltprogs/eggToFlt.h +++ b/pandatool/src/fltprogs/eggToFlt.h @@ -51,7 +51,7 @@ class EggToFlt : public EggToSomething { void convert_group(EggGroup *egg_group, FltBead *flt_node, FltGeometry::BillboardType billboard); void apply_transform(EggTransform *egg_transform, FltBead *flt_node); - void apply_egg_syntax(const std::string &egg_syntax, FltRecord *flt_record); + void apply_egg_syntax(std::string_view egg_syntax, FltRecord *flt_record); FltVertex *get_flt_vertex(EggVertex *egg_vertex, EggNode *context); FltTexture *get_flt_texture(EggTexture *egg_texture); diff --git a/pandatool/src/gtk-stats/gtkStatsTimeline.cxx b/pandatool/src/gtk-stats/gtkStatsTimeline.cxx index bffdd32e57f..2dfc17a47dd 100644 --- a/pandatool/src/gtk-stats/gtkStatsTimeline.cxx +++ b/pandatool/src/gtk-stats/gtkStatsTimeline.cxx @@ -201,7 +201,7 @@ draw_guide_bar(int x, GuideBarStyle style) { */ void GtkStatsTimeline:: draw_bar(int row, int from_x, int to_x, int collector_index, - const std::string &collector_name) { + std::string_view collector_name) { int top = row_to_pixel(row); int bottom = row_to_pixel(row + 1); int scale = _pixel_scale; @@ -238,7 +238,8 @@ draw_bar(int row, int from_x, int to_x, int collector_index, // Make sure that the text doesn't run off the chart. int text_width, text_height; - PangoLayout *layout = gtk_widget_create_pango_layout(_graph_window, collector_name.c_str()); + PangoLayout *layout = gtk_widget_create_pango_layout(_graph_window, nullptr); + pango_layout_set_text(layout, collector_name.data(), collector_name.size()); pango_layout_set_attributes(layout, _pango_attrs); pango_layout_set_height(layout, -1); pango_layout_get_pixel_size(layout, &text_width, &text_height); @@ -252,12 +253,12 @@ draw_bar(int row, int from_x, int to_x, int collector_index, size_t c = collector_name.rfind(':'); if (text_right - text_left < scale * 6) { // It's a really tiny space. Draw a single letter. - const char *ch = collector_name.data() + (c != std::string::npos ? c + 1 : 0); + const char *ch = collector_name.data() + (c != std::string_view::npos ? c + 1 : 0); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_set_text(layout, ch, 1); } else { // Maybe just use everything after the last colon. - if (c != std::string::npos) { + if (c != std::string_view::npos) { pango_layout_set_text(layout, collector_name.data() + c + 1, collector_name.size() - c - 1); pango_layout_get_pixel_size(layout, &text_width, &text_height); diff --git a/pandatool/src/gtk-stats/gtkStatsTimeline.h b/pandatool/src/gtk-stats/gtkStatsTimeline.h index b354712d663..7d70a6cce81 100644 --- a/pandatool/src/gtk-stats/gtkStatsTimeline.h +++ b/pandatool/src/gtk-stats/gtkStatsTimeline.h @@ -41,7 +41,7 @@ class GtkStatsTimeline final : public PStatTimeline, public GtkStatsGraph { virtual void draw_separator(int row); virtual void draw_guide_bar(int x, GuideBarStyle style); virtual void draw_bar(int row, int from_x, int to_x, int collector_index, - const std::string &collector_name); + std::string_view collector_name); virtual void end_draw(); virtual void idle(); diff --git a/pandatool/src/lwoegg/cLwoPoints.cxx b/pandatool/src/lwoegg/cLwoPoints.cxx index 93a89f79c60..88ea2a901d8 100644 --- a/pandatool/src/lwoegg/cLwoPoints.cxx +++ b/pandatool/src/lwoegg/cLwoPoints.cxx @@ -52,7 +52,7 @@ add_vmap(const LwoVertexMap *lwo_vmap) { * given vertex, false otherwise. If true, fills in uv with the value. */ bool CLwoPoints:: -get_uv(const std::string &uv_name, int n, LPoint2 &uv) const { +get_uv(std::string_view uv_name, int n, LPoint2 &uv) const { VMap::const_iterator ni = _txuv.find(uv_name); if (ni == _txuv.end()) { return false; diff --git a/pandatool/src/lwoegg/cLwoPoints.h b/pandatool/src/lwoegg/cLwoPoints.h index a4dbf642ac7..0feba42bf36 100644 --- a/pandatool/src/lwoegg/cLwoPoints.h +++ b/pandatool/src/lwoegg/cLwoPoints.h @@ -36,7 +36,7 @@ class CLwoPoints { CLwoLayer *layer); void add_vmap(const LwoVertexMap *lwo_vmap); - bool get_uv(const std::string &uv_name, int n, LPoint2 &uv) const; + bool get_uv(std::string_view uv_name, int n, LPoint2 &uv) const; void make_egg(); void connect_egg(); @@ -48,7 +48,7 @@ class CLwoPoints { // A number of vertex maps of different types may be associated, but we only // care about some of the types here. - typedef pmap VMap; + typedef pmap> VMap; VMap _txuv; VMap _pick; }; diff --git a/pandatool/src/lwoegg/cLwoPolygons.cxx b/pandatool/src/lwoegg/cLwoPolygons.cxx index e6a0fac4cfe..2a37ab87861 100644 --- a/pandatool/src/lwoegg/cLwoPolygons.cxx +++ b/pandatool/src/lwoegg/cLwoPolygons.cxx @@ -125,7 +125,7 @@ get_surface(int polygon_index) const { * standard vertex map, which is associated with the points themselves. */ bool CLwoPolygons:: -get_uv(const string &uv_name, int pi, int vi, LPoint2 &uv) const { +get_uv(std::string_view uv_name, int pi, int vi, LPoint2 &uv) const { VMad::const_iterator ni = _txuv.find(uv_name); if (ni == _txuv.end()) { return false; diff --git a/pandatool/src/lwoegg/cLwoPolygons.h b/pandatool/src/lwoegg/cLwoPolygons.h index d5c4b4afdae..289b9629fb2 100644 --- a/pandatool/src/lwoegg/cLwoPolygons.h +++ b/pandatool/src/lwoegg/cLwoPolygons.h @@ -43,7 +43,7 @@ class CLwoPolygons { void add_vmad(const LwoDiscontinuousVertexMap *lwo_vmad); CLwoSurface *get_surface(int polygon_index) const; - bool get_uv(const std::string &uv_name, int pi, int vi, LPoint2 &uv) const; + bool get_uv(std::string_view uv_name, int pi, int vi, LPoint2 &uv) const; void make_egg(); void connect_egg(); @@ -61,7 +61,7 @@ class CLwoPolygons { // There might be named maps associated with the polygons to bring a per- // polygon mapping to the UV's. - typedef pmap VMad; + typedef pmap> VMad; VMad _txuv; private: diff --git a/pandatool/src/lwoegg/lwoToEggConverter.cxx b/pandatool/src/lwoegg/lwoToEggConverter.cxx index 524d60a8cf8..5ba66dd0be3 100644 --- a/pandatool/src/lwoegg/lwoToEggConverter.cxx +++ b/pandatool/src/lwoegg/lwoToEggConverter.cxx @@ -182,7 +182,7 @@ get_clip(int number) const { * there is no such surface. */ CLwoSurface *LwoToEggConverter:: -get_surface(const std::string &name) const { +get_surface(std::string_view name) const { Surfaces::const_iterator si; si = _surfaces.find(name); if (si != _surfaces.end()) { diff --git a/pandatool/src/lwoegg/lwoToEggConverter.h b/pandatool/src/lwoegg/lwoToEggConverter.h index c4380a21f70..eb5e4206845 100644 --- a/pandatool/src/lwoegg/lwoToEggConverter.h +++ b/pandatool/src/lwoegg/lwoToEggConverter.h @@ -53,7 +53,7 @@ class LwoToEggConverter : public SomethingToEggConverter { CLwoLayer *get_layer(int number) const; CLwoClip *get_clip(int number) const; - CLwoSurface *get_surface(const std::string &name) const; + CLwoSurface *get_surface(std::string_view name) const; bool _make_materials; @@ -83,7 +83,7 @@ class LwoToEggConverter : public SomethingToEggConverter { typedef pvector Polygons; Polygons _polygons; - typedef pmap Surfaces; + typedef pmap> Surfaces; Surfaces _surfaces; }; diff --git a/pandatool/src/mac-stats/macStatsTimeline.h b/pandatool/src/mac-stats/macStatsTimeline.h index e26d5e7caed..b658f0fc574 100644 --- a/pandatool/src/mac-stats/macStatsTimeline.h +++ b/pandatool/src/mac-stats/macStatsTimeline.h @@ -39,7 +39,7 @@ class MacStatsTimeline final : public PStatTimeline, public MacStatsGraph { virtual void draw_separator(int row); virtual void draw_guide_bar(int x, GuideBarStyle style); virtual void draw_bar(int row, int from_x, int to_x, int collector_index, - const std::string &collector_name); + std::string_view collector_name); virtual void end_draw(); virtual void idle(); diff --git a/pandatool/src/mac-stats/macStatsTimeline.mm b/pandatool/src/mac-stats/macStatsTimeline.mm index 85f5c89e308..e006de49d1f 100644 --- a/pandatool/src/mac-stats/macStatsTimeline.mm +++ b/pandatool/src/mac-stats/macStatsTimeline.mm @@ -196,7 +196,7 @@ @interface MacStatsTimelineViewController : MacStatsScrollableGraphViewControlle */ void MacStatsTimeline:: draw_bar(int row, int from_x, int to_x, int collector_index, - const std::string &collector_name) { + std::string_view collector_name) { int top = row_to_pixel(row); int bottom = row_to_pixel(row + 1); int scale = 4; @@ -242,7 +242,7 @@ @interface MacStatsTimelineViewController : MacStatsScrollableGraphViewControlle }; CFDictionaryRef attribs = CFDictionaryCreate(kCFAllocatorDefault, (const void **)keys, (const void **)values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - CFStringRef str = CFStringCreateWithCString(kCFAllocatorDefault, collector_name.c_str(), kCFStringEncodingUTF8); + CFStringRef str = CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)collector_name.data(), collector_name.size(), kCFStringEncodingUTF8, false); CFAttributedStringRef astr = CFAttributedStringCreate(kCFAllocatorDefault, str, attribs); CTLineRef line = CTLineCreateWithAttributedString(astr); @@ -262,7 +262,7 @@ @interface MacStatsTimelineViewController : MacStatsScrollableGraphViewControlle size_t c = collector_name.rfind(':'); if (text_right - text_left < scale * 6) { // It's a really tiny space. Draw a single letter. - UniChar ch = *(collector_name.data() + (c != std::string::npos ? c + 1 : 0)); + UniChar ch = *(collector_name.data() + (c != std::string_view::npos ? c + 1 : 0)); CFStringRef str = CFStringCreateWithCharacters(kCFAllocatorDefault, &ch, 1); CFAttributedStringRef astr = CFAttributedStringCreate(kCFAllocatorDefault, str, attribs); @@ -278,9 +278,9 @@ @interface MacStatsTimelineViewController : MacStatsScrollableGraphViewControlle } else { // Maybe just use everything after the last colon. - if (c != std::string::npos) { - const char *short_name = collector_name.data() + c + 1; - CFStringRef str = CFStringCreateWithCString(kCFAllocatorDefault, short_name, kCFStringEncodingUTF8); + if (c != std::string_view::npos) { + std::string_view short_name = collector_name.substr(c + 1); + CFStringRef str = CFStringCreateWithBytes(kCFAllocatorDefault, (const UInt8 *)short_name.data(), short_name.size(), kCFStringEncodingUTF8, false); CFAttributedStringRef astr = CFAttributedStringCreate(kCFAllocatorDefault, str, attribs); CTLineRef new_line = CTLineCreateWithAttributedString((CFAttributedStringRef)astr); diff --git a/pandatool/src/objegg/eggToObjConverter.cxx b/pandatool/src/objegg/eggToObjConverter.cxx index a03630698ce..36057b29d48 100644 --- a/pandatool/src/objegg/eggToObjConverter.cxx +++ b/pandatool/src/objegg/eggToObjConverter.cxx @@ -371,7 +371,7 @@ record_unique(UniqueVertices &unique, double pos) { * obj output stream. */ void EggToObjConverter:: -write_vertices(ostream &out, const string &prefix, int num_components, +write_vertices(ostream &out, std::string_view prefix, int num_components, const UniqueVertices &unique) { // First, sort the list into numeric order. int num_vertices = (int)unique.size(); diff --git a/pandatool/src/objegg/eggToObjConverter.h b/pandatool/src/objegg/eggToObjConverter.h index 51f940d56c1..5d4f67a4ad5 100644 --- a/pandatool/src/objegg/eggToObjConverter.h +++ b/pandatool/src/objegg/eggToObjConverter.h @@ -63,7 +63,7 @@ class EggToObjConverter : public EggToSomethingConverter { int record_unique(UniqueVertices &unique, const LVecBase2d &vec); int record_unique(UniqueVertices &unique, double pos); - void write_vertices(std::ostream &out, const std::string &prefix, int num_components, + void write_vertices(std::ostream &out, std::string_view prefix, int num_components, const UniqueVertices &unique); private: diff --git a/pandatool/src/objegg/objToEggConverter.cxx b/pandatool/src/objegg/objToEggConverter.cxx index 7044409ca59..0f8b4c5d614 100644 --- a/pandatool/src/objegg/objToEggConverter.cxx +++ b/pandatool/src/objegg/objToEggConverter.cxx @@ -221,7 +221,7 @@ process(const Filename &filename) { * */ bool ObjToEggConverter:: -process_line(const string &line) { +process_line(std::string_view line) { vector_string words; tokenize(line, words, " \t", true); nassertr(!words.empty(), false); @@ -256,7 +256,7 @@ process_line(const string &line) { * */ bool ObjToEggConverter:: -process_ref_plane_res(const string &line) { +process_ref_plane_res(std::string_view line) { // the #_ref_plane_res line is a DRZ extension that defines the pixel // resolution of the projector device. It's needed to properly scale the // xvt lines. @@ -492,7 +492,7 @@ process_g(vector_string &words) { * reference. */ EggVertex *ObjToEggConverter:: -get_face_vertex(const string &reference) { +get_face_vertex(std::string_view reference) { VertexEntry entry(this, reference); // Synthesize a vertex. @@ -610,7 +610,7 @@ process_node(const Filename &filename) { * */ bool ObjToEggConverter:: -process_line_node(const string &line) { +process_line_node(std::string_view line) { vector_string words; tokenize(line, words, " \t", true); nassertr(!words.empty(), false); @@ -819,7 +819,7 @@ add_synth_normal(const LVecBase3d &normal) { * reference. */ ObjToEggConverter::VertexEntry:: -VertexEntry(const ObjToEggConverter *converter, const string &obj_vertex) { +VertexEntry(const ObjToEggConverter *converter, std::string_view obj_vertex) { _vi = 0; _vti = 0; _vni = 0; @@ -877,8 +877,8 @@ VertexEntry(const ObjToEggConverter *converter, const string &obj_vertex) { * */ ObjToEggConverter::VertexData:: -VertexData(PandaNode *parent, const string &name) : - _parent(parent), _name(name) +VertexData(PandaNode *parent, std::string name) : + _parent(parent), _name(std::move(name)) { _geom_node = nullptr; diff --git a/pandatool/src/objegg/objToEggConverter.h b/pandatool/src/objegg/objToEggConverter.h index 528dab8e7ab..a6381fe35ca 100644 --- a/pandatool/src/objegg/objToEggConverter.h +++ b/pandatool/src/objegg/objToEggConverter.h @@ -48,8 +48,8 @@ class ObjToEggConverter : public SomethingToEggConverter { protected: bool process(const Filename &filename); - bool process_line(const std::string &line); - bool process_ref_plane_res(const std::string &line); + bool process_line(std::string_view line); + bool process_ref_plane_res(std::string_view line); bool process_v(vector_string &words); bool process_vt(vector_string &words); @@ -59,11 +59,11 @@ class ObjToEggConverter : public SomethingToEggConverter { bool process_f(vector_string &words); bool process_g(vector_string &words); - EggVertex *get_face_vertex(const std::string &face_reference); + EggVertex *get_face_vertex(std::string_view face_reference); void generate_egg_points(); bool process_node(const Filename &filename); - bool process_line_node(const std::string &line); + bool process_line_node(std::string_view line); bool process_f_node(vector_string &words); bool process_g_node(vector_string &words); @@ -101,7 +101,7 @@ class ObjToEggConverter : public SomethingToEggConverter { class VertexEntry { public: VertexEntry(); - VertexEntry(const ObjToEggConverter *converter, const std::string &obj_vertex); + VertexEntry(const ObjToEggConverter *converter, std::string_view obj_vertex); INLINE bool operator < (const VertexEntry &other) const; INLINE bool operator == (const VertexEntry &other) const; @@ -119,7 +119,7 @@ class ObjToEggConverter : public SomethingToEggConverter { class VertexData { public: - VertexData(PandaNode *parent, const std::string &name); + VertexData(PandaNode *parent, std::string name); int add_vertex(const ObjToEggConverter *converter, const VertexEntry &entry); void add_triangle(const ObjToEggConverter *converter, const VertexEntry &v0, diff --git a/pandatool/src/palettizer/eggFile.cxx b/pandatool/src/palettizer/eggFile.cxx index c47eae2f3e0..44cdf69916e 100644 --- a/pandatool/src/palettizer/eggFile.cxx +++ b/pandatool/src/palettizer/eggFile.cxx @@ -57,7 +57,7 @@ bool EggFile:: from_command_line(EggData *data, const Filename &source_filename, const Filename &dest_filename, - const std::string &egg_comment) { + std::string egg_comment) { _data = data; _had_data = true; remove_backstage(_data); @@ -74,7 +74,7 @@ from_command_line(EggData *data, // We also save the command line that loaded this egg file, so we can // continue to write it as a comment to the beginning of the egg file, // should we need to rewrite it later. - _egg_comment = egg_comment; + _egg_comment = std::move(egg_comment); // We save the default PaletteGroup at this point, because the egg file // inherits the default group that was in effect when it was specified on diff --git a/pandatool/src/palettizer/eggFile.h b/pandatool/src/palettizer/eggFile.h index aa8e729e6db..5d0fdd28e2b 100644 --- a/pandatool/src/palettizer/eggFile.h +++ b/pandatool/src/palettizer/eggFile.h @@ -40,7 +40,7 @@ class EggFile : public TypedWritable, public Namable { bool from_command_line(EggData *data, const Filename &source_filename, const Filename &dest_filename, - const std::string &egg_comment); + std::string egg_comment); const Filename &get_source_filename() const; diff --git a/pandatool/src/palettizer/imageFile.cxx b/pandatool/src/palettizer/imageFile.cxx index 15a5ebc4e60..e9d80934d58 100644 --- a/pandatool/src/palettizer/imageFile.cxx +++ b/pandatool/src/palettizer/imageFile.cxx @@ -48,7 +48,7 @@ ImageFile() { * otherwise. */ bool ImageFile:: -make_shadow_image(const string &basename) { +make_shadow_image(std::string_view basename) { bool any_changed = false; if (_properties._color_type != pal->_shadow_color_type || @@ -147,7 +147,7 @@ update_properties(const TextureProperties &properties) { * otherwise. */ bool ImageFile:: -set_filename(PaletteGroup *group, const string &basename) { +set_filename(PaletteGroup *group, std::string_view basename) { // Synthesize the directory name based on the map_dirname set to the // palettizer, and the group's dirname. string dirname; @@ -185,7 +185,7 @@ set_filename(PaletteGroup *group, const string &basename) { * otherwise. */ bool ImageFile:: -set_filename(const string &dirname, const string &basename) { +set_filename(std::string_view dirname, std::string_view basename) { Filename orig_filename = _filename; Filename orig_alpha_filename = _alpha_filename; diff --git a/pandatool/src/palettizer/imageFile.h b/pandatool/src/palettizer/imageFile.h index c4d8ed90143..2bfa55f4062 100644 --- a/pandatool/src/palettizer/imageFile.h +++ b/pandatool/src/palettizer/imageFile.h @@ -34,7 +34,7 @@ class ImageFile : public TypedWritable { public: ImageFile(); - bool make_shadow_image(const std::string &basename); + bool make_shadow_image(std::string_view basename); bool is_size_known() const; int get_x_size() const; @@ -46,8 +46,8 @@ class ImageFile : public TypedWritable { void clear_basic_properties(); void update_properties(const TextureProperties &properties); - bool set_filename(PaletteGroup *group, const std::string &basename); - bool set_filename(const std::string &dirname, const std::string &basename); + bool set_filename(PaletteGroup *group, std::string_view basename); + bool set_filename(std::string_view dirname, std::string_view basename); const Filename &get_filename() const; const Filename &get_alpha_filename() const; int get_alpha_file_channel() const; diff --git a/pandatool/src/palettizer/pal_string_utils.cxx b/pandatool/src/palettizer/pal_string_utils.cxx index 279a7aad471..6f03ad652f9 100644 --- a/pandatool/src/palettizer/pal_string_utils.cxx +++ b/pandatool/src/palettizer/pal_string_utils.cxx @@ -22,7 +22,7 @@ using std::string; // Extracts the first word of the string into param, and the remainder of the // line into value. void -extract_param_value(const string &str, string ¶m, string &value) { +extract_param_value(std::string_view str, string ¶m, string &value) { size_t i = 0; // First, skip all whitespace at the beginning. @@ -39,7 +39,7 @@ extract_param_value(const string &str, string ¶m, string &value) { size_t end = i; - param = str.substr(start, end - start); + param.assign(str.substr(start, end - start)); // Skip a little bit further to the start of the value. while (i < str.length() && isspace(str[i])) { @@ -50,20 +50,20 @@ extract_param_value(const string &str, string ¶m, string &value) { bool -parse_image_type_request(const string &word, PNMFileType *&color_type, +parse_image_type_request(std::string_view word, PNMFileType *&color_type, PNMFileType *&alpha_type) { PNMFileTypeRegistry *registry = PNMFileTypeRegistry::get_global_ptr(); color_type = nullptr; alpha_type = nullptr; - string color_name = word; + string color_name(word); string alpha_name; size_t comma = word.find(','); - if (comma != string::npos) { + if (comma != std::string_view::npos) { // If we have a comma in the image_type, it's two types: a color type and // an alpha type. - color_name = word.substr(0, comma); - alpha_name = word.substr(comma + 1); + color_name.assign(word.substr(0, comma)); + alpha_name.assign(word.substr(comma + 1)); } if (!color_name.empty()) { diff --git a/pandatool/src/palettizer/pal_string_utils.h b/pandatool/src/palettizer/pal_string_utils.h index 4f37b330630..734dfa15bf1 100644 --- a/pandatool/src/palettizer/pal_string_utils.h +++ b/pandatool/src/palettizer/pal_string_utils.h @@ -19,9 +19,9 @@ class PNMFileType; -void extract_param_value(const std::string &str, std::string ¶m, std::string &value); +void extract_param_value(std::string_view str, std::string ¶m, std::string &value); -bool parse_image_type_request(const std::string &word, PNMFileType *&color_type, +bool parse_image_type_request(std::string_view word, PNMFileType *&color_type, PNMFileType *&alpha_type); #endif diff --git a/pandatool/src/palettizer/paletteGroup.cxx b/pandatool/src/palettizer/paletteGroup.cxx index d7e583259d2..4feaaf5d4cf 100644 --- a/pandatool/src/palettizer/paletteGroup.cxx +++ b/pandatool/src/palettizer/paletteGroup.cxx @@ -50,8 +50,8 @@ PaletteGroup() { * palette groups into different install directories. */ void PaletteGroup:: -set_dirname(const string &dirname) { - _dirname = dirname; +set_dirname(std::string dirname) { + _dirname = std::move(dirname); } /** diff --git a/pandatool/src/palettizer/paletteGroup.h b/pandatool/src/palettizer/paletteGroup.h index 5c20e1ca4df..27967d9f019 100644 --- a/pandatool/src/palettizer/paletteGroup.h +++ b/pandatool/src/palettizer/paletteGroup.h @@ -44,7 +44,7 @@ class PaletteGroup : public TypedWritable, public Namable { public: PaletteGroup(); - void set_dirname(const std::string &dirname); + void set_dirname(std::string dirname); bool has_dirname() const; const std::string &get_dirname() const; diff --git a/pandatool/src/palettizer/palettizer.cxx b/pandatool/src/palettizer/palettizer.cxx index 0860cb38191..dd5591c1d7a 100644 --- a/pandatool/src/palettizer/palettizer.cxx +++ b/pandatool/src/palettizer/palettizer.cxx @@ -351,7 +351,7 @@ report_statistics() const { * files. */ void Palettizer:: -read_txa_file(std::istream &txa_file, const string &txa_filename) { +read_txa_file(std::istream &txa_file, std::string_view txa_filename) { // Clear out the group dependencies, in preparation for reading them again // from the .txa file. Groups::iterator gi; @@ -747,7 +747,7 @@ write_eggs() { * files, which is typically the basename of the filename. */ EggFile *Palettizer:: -get_egg_file(const string &name) { +get_egg_file(std::string name) { EggFiles::iterator ei = _egg_files.find(name); if (ei != _egg_files.end()) { return (*ei).second; @@ -755,7 +755,7 @@ get_egg_file(const string &name) { EggFile *file = new EggFile; file->set_name(name); - _egg_files.insert(EggFiles::value_type(name, file)); + _egg_files.insert(EggFiles::value_type(std::move(name), file)); return file; } @@ -764,7 +764,7 @@ get_egg_file(const string &name) { * if the egg file was found, false if it was not. */ bool Palettizer:: -remove_egg_file(const string &name) { +remove_egg_file(std::string_view name) { EggFiles::iterator ei = _egg_files.find(name); if (ei != _egg_files.end()) { EggFile *file = (*ei).second; @@ -791,7 +791,7 @@ add_command_line_egg(EggFile *egg_file) { * with the indicated name, creates one. */ PaletteGroup *Palettizer:: -get_palette_group(const string &name) { +get_palette_group(std::string name) { Groups::iterator gi = _groups.find(name); if (gi != _groups.end()) { return (*gi).second; @@ -799,7 +799,7 @@ get_palette_group(const string &name) { PaletteGroup *group = new PaletteGroup; group->set_name(name); - _groups.insert(Groups::value_type(name, group)); + _groups.insert(Groups::value_type(std::move(name), group)); return group; } @@ -808,7 +808,7 @@ get_palette_group(const string &name) { * with the indicated name, returns NULL. */ PaletteGroup *Palettizer:: -test_palette_group(const string &name) const { +test_palette_group(std::string_view name) const { Groups::const_iterator gi = _groups.find(name); if (gi != _groups.end()) { return (*gi).second; @@ -836,7 +836,7 @@ get_default_group() { * the textures, which is typically the basename of the primary filename. */ TextureImage *Palettizer:: -get_texture(const string &name) { +get_texture(std::string name) { // Look first in the same-case name, just in case it happens to be there // (from an older version of egg-palettize that did this). Textures::iterator ti = _textures.find(name); @@ -853,9 +853,9 @@ get_texture(const string &name) { } TextureImage *image = new TextureImage; - image->set_name(name); + image->set_name(std::move(name)); // image->set_filename(name); - _textures.insert(Textures::value_type(downcase_name, image)); + _textures.insert(Textures::value_type(std::move(downcase_name), image)); return image; } @@ -874,7 +874,7 @@ yesno(bool flag) { * RU_invalid if the string is invalid. */ Palettizer::RemapUV Palettizer:: -string_remap(const string &str) { +string_remap(std::string_view str) { if (str == "never") { return RU_never; diff --git a/pandatool/src/palettizer/palettizer.h b/pandatool/src/palettizer/palettizer.h index 93f211bb6b1..88b1761e5f2 100644 --- a/pandatool/src/palettizer/palettizer.h +++ b/pandatool/src/palettizer/palettizer.h @@ -47,7 +47,7 @@ class Palettizer : public TypedWritable { void report_pi() const; void report_statistics() const; - void read_txa_file(std::istream &txa_file, const std::string &txa_filename); + void read_txa_file(std::istream &txa_file, std::string_view txa_filename); void all_params_set(); void process_command_line_eggs(bool force_texture_read, const Filename &state_filename); void process_all(bool force_texture_read, const Filename &state_filename); @@ -57,15 +57,15 @@ class Palettizer : public TypedWritable { bool read_stale_eggs(bool redo_all); bool write_eggs(); - EggFile *get_egg_file(const std::string &name); - bool remove_egg_file(const std::string &name); + EggFile *get_egg_file(std::string name); + bool remove_egg_file(std::string_view name); void add_command_line_egg(EggFile *egg_file); - PaletteGroup *get_palette_group(const std::string &name); - PaletteGroup *test_palette_group(const std::string &name) const; + PaletteGroup *get_palette_group(std::string name); + PaletteGroup *test_palette_group(std::string_view name) const; PaletteGroup *get_default_group(); - TextureImage *get_texture(const std::string &name); + TextureImage *get_texture(std::string name); private: static const char *yesno(bool flag); @@ -82,7 +82,7 @@ class Palettizer : public TypedWritable { RU_invalid }; - static RemapUV string_remap(const std::string &str); + static RemapUV string_remap(std::string_view str); bool _is_valid; @@ -124,7 +124,7 @@ class Palettizer : public TypedWritable { void compute_statistics(std::ostream &out, int indent_level, const Placements &placements) const; - typedef pmap EggFiles; + typedef pmap> EggFiles; EggFiles _egg_files; typedef pvector CommandLineEggs; @@ -133,10 +133,10 @@ class Palettizer : public TypedWritable { typedef pset CommandLineTextures; CommandLineTextures _command_line_textures; - typedef pmap Groups; + typedef pmap> Groups; Groups _groups; - typedef pmap Textures; + typedef pmap> Textures; Textures _textures; typedef pvector TextureConflicts; TextureConflicts _texture_conflicts; diff --git a/pandatool/src/palettizer/texturePlacement.cxx b/pandatool/src/palettizer/texturePlacement.cxx index b92583b6d60..9b5a18b5966 100644 --- a/pandatool/src/palettizer/texturePlacement.cxx +++ b/pandatool/src/palettizer/texturePlacement.cxx @@ -756,7 +756,7 @@ fill_image(PNMImage &image) { case EggTexture::WM_mirror_once: sy = (sy < y_size) ? sy : 2 * y_size - sy - 1; - // Fall through + [[fallthrough]]; case EggTexture::WM_border_color: if (sy < 0 || sy >= y_size) { @@ -786,7 +786,7 @@ fill_image(PNMImage &image) { case EggTexture::WM_mirror_once: sx = (sx >= 0) ? sx : ~sx; - // Fall through + [[fallthrough]]; case EggTexture::WM_border_color: if (sx < 0 || sx >= x_size) { diff --git a/pandatool/src/palettizer/txaFile.cxx b/pandatool/src/palettizer/txaFile.cxx index cb4cb5331df..279423563ba 100644 --- a/pandatool/src/palettizer/txaFile.cxx +++ b/pandatool/src/palettizer/txaFile.cxx @@ -34,7 +34,7 @@ TxaFile() { * there is an error. */ bool TxaFile:: -read(std::istream &in, const string &filename) { +read(std::istream &in, std::string_view filename) { string line; int line_number = 1; diff --git a/pandatool/src/palettizer/txaFile.h b/pandatool/src/palettizer/txaFile.h index 05d0a32ae10..a567b226434 100644 --- a/pandatool/src/palettizer/txaFile.h +++ b/pandatool/src/palettizer/txaFile.h @@ -31,7 +31,7 @@ class TxaFile { public: TxaFile(); - bool read(std::istream &in, const std::string &filename); + bool read(std::istream &in, std::string_view filename); bool match_egg(EggFile *egg_file) const; bool match_texture(TextureImage *texture) const; diff --git a/pandatool/src/palettizer/txaLine.cxx b/pandatool/src/palettizer/txaLine.cxx index bf3b645ca6a..c5a714f5a23 100644 --- a/pandatool/src/palettizer/txaLine.cxx +++ b/pandatool/src/palettizer/txaLine.cxx @@ -56,9 +56,9 @@ TxaLine() { * its constinuent parts. Returns true if successful, false on error. */ bool TxaLine:: -parse(const string &line) { +parse(std::string_view line) { size_t colon = line.find(':'); - if (colon == string::npos) { + if (colon == std::string_view::npos) { nout << "Colon required.\n"; return false; } @@ -424,7 +424,7 @@ match_texture(TextureImage *texture) const { case ST_explicit_3: request._got_num_channels = true; request._num_channels = _num_channels; - // fall through + [[fallthrough]]; case ST_explicit_2: request._got_size = true; diff --git a/pandatool/src/palettizer/txaLine.h b/pandatool/src/palettizer/txaLine.h index 8a93c45a9a7..e10a21674ff 100644 --- a/pandatool/src/palettizer/txaLine.h +++ b/pandatool/src/palettizer/txaLine.h @@ -37,7 +37,7 @@ class TxaLine { public: TxaLine(); - bool parse(const std::string &line); + bool parse(std::string_view line); bool match_egg(EggFile *egg_file) const; bool match_texture(TextureImage *texture) const; diff --git a/pandatool/src/pandatoolbase/animationConvert.cxx b/pandatool/src/pandatoolbase/animationConvert.cxx index d09ce0f19f2..a56bad57467 100644 --- a/pandatool/src/pandatoolbase/animationConvert.cxx +++ b/pandatool/src/pandatoolbase/animationConvert.cxx @@ -63,7 +63,7 @@ operator << (std::ostream &out, AnimationConvert convert) { * AnimationConvert types. Returns AC_invalid if the string is unknown. */ AnimationConvert -string_animation_convert(const std::string &str) { +string_animation_convert(std::string_view str) { if (cmp_nocase(str, "none") == 0) { return AC_none; diff --git a/pandatool/src/pandatoolbase/animationConvert.h b/pandatool/src/pandatoolbase/animationConvert.h index 2365cfff1ed..043aaf0adb4 100644 --- a/pandatool/src/pandatoolbase/animationConvert.h +++ b/pandatool/src/pandatoolbase/animationConvert.h @@ -34,6 +34,6 @@ enum AnimationConvert { std::string format_animation_convert(AnimationConvert unit); std::ostream &operator << (std::ostream &out, AnimationConvert unit); -AnimationConvert string_animation_convert(const std::string &str); +AnimationConvert string_animation_convert(std::string_view str); #endif diff --git a/pandatool/src/pandatoolbase/distanceUnit.cxx b/pandatool/src/pandatoolbase/distanceUnit.cxx index 8ee495be3c4..14b35e490fe 100644 --- a/pandatool/src/pandatoolbase/distanceUnit.cxx +++ b/pandatool/src/pandatoolbase/distanceUnit.cxx @@ -128,7 +128,7 @@ operator >> (istream &in, DistanceUnit &unit) { * DistanceUnit types. Returns DU_invalid if the string is unknown. */ DistanceUnit -string_distance_unit(const string &str) { +string_distance_unit(std::string_view str) { if (cmp_nocase(str, "mm") == 0 || cmp_nocase(str, "millimeters") == 0) { return DU_millimeters; diff --git a/pandatool/src/pandatoolbase/distanceUnit.h b/pandatool/src/pandatoolbase/distanceUnit.h index 2030ae09e09..ffe6bc7f406 100644 --- a/pandatool/src/pandatoolbase/distanceUnit.h +++ b/pandatool/src/pandatoolbase/distanceUnit.h @@ -38,7 +38,7 @@ std::string format_long_unit(DistanceUnit unit); std::ostream &operator << (std::ostream &out, DistanceUnit unit); std::istream &operator >> (std::istream &in, DistanceUnit &unit); -DistanceUnit string_distance_unit(const std::string &str); +DistanceUnit string_distance_unit(std::string_view str); double convert_units(DistanceUnit from, DistanceUnit to); diff --git a/pandatool/src/pandatoolbase/pathReplace.I b/pandatool/src/pandatoolbase/pathReplace.I index 282c37d306b..d64cacd4dae 100644 --- a/pandatool/src/pandatoolbase/pathReplace.I +++ b/pandatool/src/pandatoolbase/pathReplace.I @@ -44,8 +44,8 @@ clear() { * orig_prefix, that prefix will be replaced with replacement_prefix. */ INLINE void PathReplace:: -add_pattern(const std::string &orig_prefix, const std::string &replacement_prefix) { - _entries.push_back(Entry(orig_prefix, replacement_prefix)); +add_pattern(std::string orig_prefix, std::string replacement_prefix) { + _entries.push_back(Entry(std::move(orig_prefix), std::move(replacement_prefix))); } /** @@ -98,8 +98,8 @@ convert_path(const Filename &orig_filename, const DSearchPath &additional_path) * */ INLINE PathReplace::Component:: -Component(const std::string &component) : - _orig_prefix(component), +Component(std::string_view component) : + _orig_prefix(std::string(component)), _double_star(component == "**") { } diff --git a/pandatool/src/pandatoolbase/pathReplace.cxx b/pandatool/src/pandatoolbase/pathReplace.cxx index b3b6bcb498d..528079edead 100644 --- a/pandatool/src/pandatoolbase/pathReplace.cxx +++ b/pandatool/src/pandatoolbase/pathReplace.cxx @@ -451,9 +451,9 @@ copy_this_file(Filename &filename) { * */ PathReplace::Entry:: -Entry(const std::string &orig_prefix, const std::string &replacement_prefix) : - _orig_prefix(orig_prefix), - _replacement_prefix(replacement_prefix) +Entry(std::string orig_prefix, std::string replacement_prefix) : + _orig_prefix(std::move(orig_prefix)), + _replacement_prefix(std::move(replacement_prefix)) { // Eliminate trailing slashes; they're implicit. if (_orig_prefix.length() > 1 && diff --git a/pandatool/src/pandatoolbase/pathReplace.h b/pandatool/src/pandatoolbase/pathReplace.h index edc69abc08e..804dcdd884b 100644 --- a/pandatool/src/pandatoolbase/pathReplace.h +++ b/pandatool/src/pandatoolbase/pathReplace.h @@ -42,7 +42,7 @@ class PathReplace : public ReferenceCount { INLINE bool had_error() const; INLINE void clear(); - INLINE void add_pattern(const std::string &orig_prefix, const std::string &replacement_prefix); + INLINE void add_pattern(std::string orig_prefix, std::string replacement_prefix); INLINE int get_num_patterns() const; INLINE const std::string &get_orig_prefix(int n) const; @@ -88,7 +88,7 @@ class PathReplace : public ReferenceCount { class Component { public: - INLINE Component(const std::string &component); + INLINE Component(std::string_view component); INLINE Component(const Component ©); INLINE void operator = (const Component ©); @@ -99,7 +99,7 @@ class PathReplace : public ReferenceCount { class Entry { public: - Entry(const std::string &orig_prefix, const std::string &replacement_prefix); + Entry(std::string orig_prefix, std::string replacement_prefix); INLINE Entry(const Entry ©); INLINE void operator = (const Entry ©); diff --git a/pandatool/src/pandatoolbase/pathStore.cxx b/pandatool/src/pandatoolbase/pathStore.cxx index dffacfe6785..4aa0bcf3c94 100644 --- a/pandatool/src/pandatoolbase/pathStore.cxx +++ b/pandatool/src/pandatoolbase/pathStore.cxx @@ -57,7 +57,7 @@ operator << (std::ostream &out, PathStore store) { * PathStore types. Returns PS_invalid if the string is unknown. */ PathStore -string_path_store(const std::string &str) { +string_path_store(std::string_view str) { if (cmp_nocase(str, "relative") == 0 || cmp_nocase(str, "rel") == 0) { return PS_relative; diff --git a/pandatool/src/pandatoolbase/pathStore.h b/pandatool/src/pandatoolbase/pathStore.h index 30440b70a70..e421f055ff1 100644 --- a/pandatool/src/pandatoolbase/pathStore.h +++ b/pandatool/src/pandatoolbase/pathStore.h @@ -32,6 +32,6 @@ enum PathStore { std::string format_path_store(PathStore unit); std::ostream &operator << (std::ostream &out, PathStore unit); -PathStore string_path_store(const std::string &str); +PathStore string_path_store(std::string_view str); #endif diff --git a/pandatool/src/progbase/programBase.I b/pandatool/src/progbase/programBase.I index 960bad09f26..0bda87015a3 100644 --- a/pandatool/src/progbase/programBase.I +++ b/pandatool/src/progbase/programBase.I @@ -15,6 +15,6 @@ * Formats the indicated text to stderr with the known _terminal_width. */ INLINE void ProgramBase:: -show_text(const std::string &text) { - show_text("", 0, text); +show_text(std::string_view text) { + show_text("", 0, std::string(text)); } diff --git a/pandatool/src/progbase/programBase.cxx b/pandatool/src/progbase/programBase.cxx index 7486c4a9427..b8afdb3261f 100644 --- a/pandatool/src/progbase/programBase.cxx +++ b/pandatool/src/progbase/programBase.cxx @@ -82,7 +82,7 @@ static ConfigVariableBool use_terminal_width * */ ProgramBase:: -ProgramBase(const string &name) : _name(name) { +ProgramBase(string name) : _name(std::move(name)) { // Set up Notify to write output to our own formatted stream. Notify::ptr()->set_ostream_ptr(new WordWrapStream(this), true); @@ -171,7 +171,7 @@ show_options() { * known _terminal_width. */ void ProgramBase:: -show_text(const string &prefix, int indent_width, string text) { +show_text(std::string_view prefix, int indent_width, string text) { get_terminal_width(); // This is correct! It goes go to cerr, not to nout. Sending it to nout @@ -577,8 +577,8 @@ post_command_line() { * This should be of the format: "perform operation foo on bar files" */ void ProgramBase:: -set_program_brief(const string &brief) { - _brief = brief; +set_program_brief(string brief) { + _brief = std::move(brief); } /** @@ -587,8 +587,8 @@ set_program_brief(const string &brief) { * characters are interpreted as paragraph breaks and printed as blank lines. */ void ProgramBase:: -set_program_description(const string &description) { - _description = description; +set_program_description(string description) { + _description = std::move(description); } /** @@ -611,8 +611,8 @@ clear_runlines() { * to define more than one. */ void ProgramBase:: -add_runline(const string &runline) { - _runlines.push_back(runline); +add_runline(string runline) { + _runlines.push_back(std::move(runline)); } /** @@ -647,22 +647,22 @@ clear_options() { * classes. */ void ProgramBase:: -add_option(const string &option, const string &parm_name, - int index_group, const string &description, +add_option(string option, string parm_name, + int index_group, string description, OptionDispatchFunction option_function, bool *bool_var, void *option_data) { Option opt; opt._option = option; - opt._parm_name = parm_name; + opt._parm_name = std::move(parm_name); opt._index_group = index_group; opt._sequence = ++_next_sequence; - opt._description = description; + opt._description = std::move(description); opt._option_function = option_function; opt._option_method = (OptionDispatchMethod)nullptr; opt._bool_var = bool_var; opt._option_data = option_data; - _options_by_name[option] = opt; + _options_by_name[std::move(option)] = std::move(opt); _sorted_options = false; if (bool_var != nullptr) { @@ -683,22 +683,22 @@ add_option(const string &option, const string &parm_name, * the first argument. */ void ProgramBase:: -add_option(const string &option, const string &parm_name, - int index_group, const string &description, +add_option(string option, string parm_name, + int index_group, string description, OptionDispatchMethod option_method, bool *bool_var, void *option_data) { Option opt; opt._option = option; - opt._parm_name = parm_name; + opt._parm_name = std::move(parm_name); opt._index_group = index_group; opt._sequence = ++_next_sequence; - opt._description = description; + opt._description = std::move(description); opt._option_function = (OptionDispatchFunction)nullptr; opt._option_method = option_method; opt._bool_var = bool_var; opt._option_data = option_data; - _options_by_name[option] = opt; + _options_by_name[std::move(option)] = std::move(opt); _sorted_options = false; if (bool_var != nullptr) { @@ -711,12 +711,12 @@ add_option(const string &option, const string &parm_name, * Returns true if the option was changed, false if it hadn't been defined. */ bool ProgramBase:: -redescribe_option(const string &option, const string &description) { +redescribe_option(const string &option, string description) { OptionsByName::iterator oi = _options_by_name.find(option); if (oi == _options_by_name.end()) { return false; } - (*oi).second._description = description; + (*oi).second._description = std::move(description); return true; } @@ -1327,8 +1327,8 @@ handle_help_option(const string &, const string &, void *data) { */ void ProgramBase:: format_text(std::ostream &out, bool &last_newline, - const string &prefix, int indent_width, - const string &text, int line_width) { + std::string_view prefix, int indent_width, + std::string_view text, int line_width) { indent_width = min(indent_width, line_width - 20); int indent_amount = indent_width; bool initial_break = false; diff --git a/pandatool/src/progbase/programBase.h b/pandatool/src/progbase/programBase.h index a245e999518..07cbbd0fdef 100644 --- a/pandatool/src/progbase/programBase.h +++ b/pandatool/src/progbase/programBase.h @@ -39,15 +39,15 @@ class ProgramBase { EC_failure = 1 }; - ProgramBase(const std::string &name = std::string()); + ProgramBase(std::string name = std::string()); virtual ~ProgramBase(); void show_description(); void show_usage(); void show_options(); - INLINE void show_text(const std::string &text); - void show_text(const std::string &prefix, int indent_width, std::string text); + INLINE void show_text(std::string_view text); + void show_text(std::string_view prefix, int indent_width, std::string text); void write_man_page(std::ostream &out); @@ -66,22 +66,22 @@ class ProgramBase { virtual bool handle_args(Args &args); virtual bool post_command_line(); - void set_program_brief(const std::string &brief); - void set_program_description(const std::string &description); + void set_program_brief(std::string brief); + void set_program_description(std::string description); void clear_runlines(); - void add_runline(const std::string &runline); + void add_runline(std::string runline); void clear_options(); - void add_option(const std::string &option, const std::string &parm_name, - int index_group, const std::string &description, + void add_option(std::string option, std::string parm_name, + int index_group, std::string description, OptionDispatchFunction option_function, bool *bool_var = nullptr, void *option_data = nullptr); - void add_option(const std::string &option, const std::string &parm_name, - int index_group, const std::string &description, + void add_option(std::string option, std::string parm_name, + int index_group, std::string description, OptionDispatchMethod option_method, bool *bool_var = nullptr, void *option_data = nullptr); - bool redescribe_option(const std::string &option, const std::string &description); + bool redescribe_option(const std::string &option, std::string description); bool remove_option(const std::string &option); void add_path_replace_options(); @@ -113,8 +113,8 @@ class ProgramBase { static bool handle_help_option(const std::string &opt, const std::string &arg, void *); static void format_text(std::ostream &out, bool &last_newline, - const std::string &prefix, int indent_width, - const std::string &text, int line_width); + std::string_view prefix, int indent_width, + std::string_view text, int line_width); PT(PathReplace) _path_replace; bool _got_path_store; diff --git a/pandatool/src/pstatserver/pStatClientData.cxx b/pandatool/src/pstatserver/pStatClientData.cxx index a3dc317d27e..39d30b53901 100644 --- a/pandatool/src/pstatserver/pStatClientData.cxx +++ b/pandatool/src/pstatserver/pStatClientData.cxx @@ -120,11 +120,11 @@ has_collector(int index) const { * such collector has been defined by the client. */ int PStatClientData:: -find_collector(const std::string &fullname) const { +find_collector(std::string_view fullname) const { // Take the last bit, we can compare it more cheaply, only check the full // name if the basename matches. - const char *colon = strrchr(fullname.c_str(), ':'); - std::string name(colon != nullptr ? colon + 1 : fullname.c_str()); + size_t colon = fullname.rfind(':'); + std::string_view name = (colon != std::string_view::npos) ? fullname.substr(colon + 1) : fullname; for (int index = 0; index < get_num_collectors(); ++index) { const PStatCollectorDef *def = _collectors[index]._def; @@ -269,7 +269,7 @@ has_thread(int index) const { * has yet been defined. */ int PStatClientData:: -find_thread(const std::string &name) const { +find_thread(std::string_view name) const { for (int index = 0; index < get_num_threads(); ++index) { if (_threads[index]._name == name) { return index; @@ -370,7 +370,7 @@ add_collector(PStatCollectorDef *def) { * information just arrived from the client. */ void PStatClientData:: -define_thread(int thread_index, const string &name, bool mark_alive) { +define_thread(int thread_index, std::string name, bool mark_alive) { // A sanity check on the index number. nassertv(thread_index < 1000); @@ -384,7 +384,7 @@ define_thread(int thread_index, const string &name, bool mark_alive) { } if (!name.empty()) { - _threads[thread_index]._name = name; + _threads[thread_index]._name = std::move(name); } if (_threads[thread_index]._data.is_null()) { diff --git a/pandatool/src/pstatserver/pStatClientData.h b/pandatool/src/pstatserver/pStatClientData.h index bd2bb1d6b6d..7c26c655d98 100644 --- a/pandatool/src/pstatserver/pStatClientData.h +++ b/pandatool/src/pstatserver/pStatClientData.h @@ -49,7 +49,7 @@ class PStatClientData : public PStatClientVersion { int get_num_collectors() const; bool has_collector(int index) const; - int find_collector(const std::string &fullname) const; + int find_collector(std::string_view fullname) const; const PStatCollectorDef &get_collector_def(int index) const; std::string get_collector_name(int index) const; std::string get_collector_fullname(int index) const; @@ -61,7 +61,7 @@ class PStatClientData : public PStatClientVersion { int get_num_threads() const; bool has_thread(int index) const; - int find_thread(const std::string &name) const; + int find_thread(std::string_view name) const; std::string get_thread_name(int index) const; const PStatThreadData *get_thread_data(int index) const; bool is_thread_alive(int index) const; @@ -70,7 +70,7 @@ class PStatClientData : public PStatClientVersion { void add_collector(PStatCollectorDef *def); - void define_thread(int thread_index, const std::string &name = std::string(), + void define_thread(int thread_index, std::string name = std::string(), bool mark_alive = false); void expire_thread(int thread_index); void remove_thread(int thread_index); diff --git a/pandatool/src/pstatserver/pStatGraph.I b/pandatool/src/pstatserver/pStatGraph.I index 3bda0cedeed..7cda1b5930e 100644 --- a/pandatool/src/pstatserver/pStatGraph.I +++ b/pandatool/src/pstatserver/pStatGraph.I @@ -117,8 +117,8 @@ get_guide_bar_units() const { * is set to GBU_named | GBU_show_units. */ INLINE void PStatGraph:: -set_guide_bar_unit_name(const std::string &unit_name) { - _unit_name = unit_name; +set_guide_bar_unit_name(std::string unit_name) { + _unit_name = std::move(unit_name); } /** diff --git a/pandatool/src/pstatserver/pStatGraph.cxx b/pandatool/src/pstatserver/pStatGraph.cxx index a0d1a5dad5c..5d758291d65 100644 --- a/pandatool/src/pstatserver/pStatGraph.cxx +++ b/pandatool/src/pstatserver/pStatGraph.cxx @@ -26,9 +26,9 @@ using std::string; * */ PStatGraph::GuideBar:: -GuideBar(double height, const string &label, PStatGraph::GuideBarStyle style) : +GuideBar(double height, std::string label, PStatGraph::GuideBarStyle style) : _height(height), - _label(label), + _label(std::move(label)), _style(style) { } @@ -173,7 +173,7 @@ format_number(double value) { * including the units as indicated. */ string PStatGraph:: -format_number(double value, int guide_bar_units, const string &unit_name) { +format_number(double value, int guide_bar_units, std::string_view unit_name) { string label; if ((guide_bar_units & GBU_named) != 0) { diff --git a/pandatool/src/pstatserver/pStatGraph.h b/pandatool/src/pstatserver/pStatGraph.h index 6c9168a4858..773f1bec934 100644 --- a/pandatool/src/pstatserver/pStatGraph.h +++ b/pandatool/src/pstatserver/pStatGraph.h @@ -57,7 +57,7 @@ class PStatGraph { class GuideBar { public: - GuideBar(double height, const std::string &label, GuideBarStyle style); + GuideBar(double height, std::string label, GuideBarStyle style); GuideBar(const GuideBar ©); double _height; @@ -84,12 +84,12 @@ class PStatGraph { INLINE void set_guide_bar_units(int unit_mask); INLINE int get_guide_bar_units() const; - INLINE void set_guide_bar_unit_name(const std::string &unit_name); + INLINE void set_guide_bar_unit_name(std::string unit_name); INLINE const std::string &get_guide_bar_unit_name() const; static std::string format_number(double value); static std::string format_number(double value, int guide_bar_units, - const std::string &unit_name = std::string()); + std::string_view unit_name = std::string_view()); virtual void write_datagram(Datagram &dg) const; virtual void read_datagram(DatagramIterator &scan); diff --git a/pandatool/src/pstatserver/pStatMonitor.cxx b/pandatool/src/pstatserver/pStatMonitor.cxx index cbc49a71403..a5ce7f6fc81 100644 --- a/pandatool/src/pstatserver/pStatMonitor.cxx +++ b/pandatool/src/pstatserver/pStatMonitor.cxx @@ -58,10 +58,10 @@ PStatMonitor:: * indicates the client's reported hostname and program name. */ void PStatMonitor:: -hello_from(const string &hostname, const string &progname, int pid) { +hello_from(std::string_view hostname, std::string_view progname, int pid) { _client_known = true; - _client_hostname = hostname; - _client_progname = progname; + _client_hostname.assign(hostname); + _client_progname.assign(progname); _client_pid = pid; got_hello(); } @@ -73,12 +73,12 @@ hello_from(const string &hostname, const string &progname, int pid) { * effect. */ void PStatMonitor:: -bad_version(const string &hostname, const string &progname, int pid, +bad_version(std::string_view hostname, std::string_view progname, int pid, int client_major, int client_minor, int server_major, int server_minor) { _client_known = true; - _client_hostname = hostname; - _client_progname = progname; + _client_hostname.assign(hostname); + _client_progname.assign(progname); _client_pid = 0; got_bad_version(client_major, client_minor, server_major, server_minor); diff --git a/pandatool/src/pstatserver/pStatMonitor.h b/pandatool/src/pstatserver/pStatMonitor.h index d98ce2b9b09..a619f125133 100644 --- a/pandatool/src/pstatserver/pStatMonitor.h +++ b/pandatool/src/pstatserver/pStatMonitor.h @@ -44,9 +44,9 @@ class PStatMonitor : public ReferenceCount { PStatMonitor(PStatServer *server = nullptr); virtual ~PStatMonitor(); - void hello_from(const std::string &hostname, const std::string &progname, + void hello_from(std::string_view hostname, std::string_view progname, int pid); - void bad_version(const std::string &hostname, const std::string &progname, + void bad_version(std::string_view hostname, std::string_view progname, int pid, int client_major, int client_minor, int server_major, int server_minor); diff --git a/pandatool/src/pstatserver/pStatTimeline.cxx b/pandatool/src/pstatserver/pStatTimeline.cxx index d8d0fdfbc2e..9e3a08781de 100644 --- a/pandatool/src/pstatserver/pStatTimeline.cxx +++ b/pandatool/src/pstatserver/pStatTimeline.cxx @@ -776,7 +776,7 @@ draw_guide_bar(int x, GuideBarStyle style) { * given collector, for the indicated horizontal pixel range. */ void PStatTimeline:: -draw_bar(int, int, int, int, const std::string &) { +draw_bar(int, int, int, int, std::string_view) { } /** diff --git a/pandatool/src/pstatserver/pStatTimeline.h b/pandatool/src/pstatserver/pStatTimeline.h index ebf5a30de79..731c6e22be3 100644 --- a/pandatool/src/pstatserver/pStatTimeline.h +++ b/pandatool/src/pstatserver/pStatTimeline.h @@ -73,7 +73,7 @@ class PStatTimeline : public PStatGraph { virtual void draw_separator(int row); virtual void draw_guide_bar(int x, GuideBarStyle style); virtual void draw_bar(int row, int from_x, int to_x, int collector_index, - const std::string &collector_name); + std::string_view collector_name); virtual void end_draw(); virtual void idle(); diff --git a/pandatool/src/win-stats/winStatsTimeline.cxx b/pandatool/src/win-stats/winStatsTimeline.cxx index a9c3f6688ac..7f8ffd8ef1c 100644 --- a/pandatool/src/win-stats/winStatsTimeline.cxx +++ b/pandatool/src/win-stats/winStatsTimeline.cxx @@ -128,7 +128,7 @@ draw_guide_bar(int x, GuideBarStyle style) { */ void WinStatsTimeline:: draw_bar(int row, int from_x, int to_x, int collector_index, - const std::string &collector_name) { + std::string_view collector_name) { int top = row_to_pixel(row); int bottom = row_to_pixel(row + 1); diff --git a/pandatool/src/win-stats/winStatsTimeline.h b/pandatool/src/win-stats/winStatsTimeline.h index 8c66b2b1061..cb12c61466f 100644 --- a/pandatool/src/win-stats/winStatsTimeline.h +++ b/pandatool/src/win-stats/winStatsTimeline.h @@ -46,7 +46,7 @@ class WinStatsTimeline : public PStatTimeline, public WinStatsGraph { virtual void draw_separator(int row); virtual void draw_guide_bar(int x, GuideBarStyle style); virtual void draw_bar(int row, int from_x, int to_x, int collector_index, - const std::string &collector_name); + std::string_view collector_name); virtual void end_draw(); virtual void idle(); diff --git a/pandatool/src/xfile/xFile.cxx b/pandatool/src/xfile/xFile.cxx index 3c0d7b3445d..0312c2e38a8 100644 --- a/pandatool/src/xfile/xFile.cxx +++ b/pandatool/src/xfile/xFile.cxx @@ -175,7 +175,7 @@ write(ostream &out) const { * none. */ XFileTemplate *XFile:: -find_template(const string &name) const { +find_template(std::string_view name) const { XFileTemplate *standard = nullptr; const XFile *standard_templates = get_standard_templates(); if (standard_templates != this) { @@ -234,7 +234,7 @@ find_template(const WindowsGuid &guid) const { * or NULL if none. */ XFileTemplate *XFile:: -find_standard_template(const string &name) { +find_standard_template(std::string_view name) { const XFile *standard_templates = get_standard_templates(); return standard_templates->find_template(name); } @@ -254,7 +254,7 @@ find_standard_template(const WindowsGuid &guid) { * if none. */ XFileDataNodeTemplate *XFile:: -find_data_object(const string &name) const { +find_data_object(std::string_view name) const { XFileNode *child = find_descendent(name); if (child != nullptr && child->is_of_type(XFileDataNodeTemplate::get_class_type())) { diff --git a/pandatool/src/xfile/xFile.h b/pandatool/src/xfile/xFile.h index 5dacb3c4568..c4f67aa1dbf 100644 --- a/pandatool/src/xfile/xFile.h +++ b/pandatool/src/xfile/xFile.h @@ -42,13 +42,13 @@ class XFile : public XFileNode { bool write(Filename filename) const; bool write(std::ostream &out) const; - XFileTemplate *find_template(const std::string &name) const; + XFileTemplate *find_template(std::string_view name) const; XFileTemplate *find_template(const WindowsGuid &guid) const; - static XFileTemplate *find_standard_template(const std::string &name); + static XFileTemplate *find_standard_template(std::string_view name); static XFileTemplate *find_standard_template(const WindowsGuid &guid); - XFileDataNodeTemplate *find_data_object(const std::string &name) const; + XFileDataNodeTemplate *find_data_object(std::string_view name) const; XFileDataNodeTemplate *find_data_object(const WindowsGuid &guid) const; virtual void write_text(std::ostream &out, int indent_level) const; diff --git a/pandatool/src/xfile/xFileDataDef.I b/pandatool/src/xfile/xFileDataDef.I index 65a7d9c36ae..dddf6448230 100644 --- a/pandatool/src/xfile/xFileDataDef.I +++ b/pandatool/src/xfile/xFileDataDef.I @@ -15,7 +15,7 @@ * */ INLINE XFileDataDef:: -XFileDataDef(XFile *x_file, const std::string &name, +XFileDataDef(XFile *x_file, std::string_view name, XFileDataDef::Type type, XFileTemplate *xtemplate) : XFileNode(x_file, name), _type(type), diff --git a/pandatool/src/xfile/xFileDataDef.h b/pandatool/src/xfile/xFileDataDef.h index adcac50d1d5..5f712ec5aa5 100644 --- a/pandatool/src/xfile/xFileDataDef.h +++ b/pandatool/src/xfile/xFileDataDef.h @@ -45,7 +45,7 @@ class XFileDataDef : public XFileNode { T_template, }; - INLINE XFileDataDef(XFile *x_file, const std::string &name, + INLINE XFileDataDef(XFile *x_file, std::string_view name, Type type, XFileTemplate *xtemplate = nullptr); virtual ~XFileDataDef(); diff --git a/pandatool/src/xfile/xFileDataNode.cxx b/pandatool/src/xfile/xFileDataNode.cxx index bc1326697eb..8da1ad38e37 100644 --- a/pandatool/src/xfile/xFileDataNode.cxx +++ b/pandatool/src/xfile/xFileDataNode.cxx @@ -20,7 +20,7 @@ TypeHandle XFileDataNode::_type_handle; * */ XFileDataNode:: -XFileDataNode(XFile *x_file, const std::string &name, +XFileDataNode(XFile *x_file, std::string_view name, XFileTemplate *xtemplate) : XFileNode(x_file, name), _template(xtemplate) @@ -46,7 +46,7 @@ is_object() const { * object must be of type XFileDataNode. */ bool XFileDataNode:: -is_standard_object(const std::string &template_name) const { +is_standard_object(std::string_view template_name) const { if (_template->is_standard() && _template->get_name() == template_name) { return true; diff --git a/pandatool/src/xfile/xFileDataNode.h b/pandatool/src/xfile/xFileDataNode.h index c04df4a3d16..76212cd9b31 100644 --- a/pandatool/src/xfile/xFileDataNode.h +++ b/pandatool/src/xfile/xFileDataNode.h @@ -32,11 +32,11 @@ */ class XFileDataNode : public XFileNode, public XFileDataObject { public: - XFileDataNode(XFile *x_file, const std::string &name, + XFileDataNode(XFile *x_file, std::string_view name, XFileTemplate *xtemplate); virtual bool is_object() const; - virtual bool is_standard_object(const std::string &template_name) const; + virtual bool is_standard_object(std::string_view template_name) const; virtual std::string get_type_name() const; INLINE const XFileDataNode &get_data_child(int n) const; diff --git a/pandatool/src/xfile/xFileDataNodeReference.cxx b/pandatool/src/xfile/xFileDataNodeReference.cxx index 7796aeeeda5..0704edbd018 100644 --- a/pandatool/src/xfile/xFileDataNodeReference.cxx +++ b/pandatool/src/xfile/xFileDataNodeReference.cxx @@ -89,6 +89,6 @@ get_element(int n) { * name. */ XFileDataObject *XFileDataNodeReference:: -get_element(const std::string &name) { +get_element(std::string_view name) { return &((*_object)[name]); } diff --git a/pandatool/src/xfile/xFileDataNodeReference.h b/pandatool/src/xfile/xFileDataNodeReference.h index f1e9eb4c80b..40d7ab7fb52 100644 --- a/pandatool/src/xfile/xFileDataNodeReference.h +++ b/pandatool/src/xfile/xFileDataNodeReference.h @@ -41,7 +41,7 @@ class XFileDataNodeReference : public XFileDataNode { protected: virtual int get_num_elements() const; virtual XFileDataObject *get_element(int n); - virtual XFileDataObject *get_element(const std::string &name); + virtual XFileDataObject *get_element(std::string_view name); private: PT(XFileDataNodeTemplate) _object; diff --git a/pandatool/src/xfile/xFileDataNodeTemplate.cxx b/pandatool/src/xfile/xFileDataNodeTemplate.cxx index 6464716964d..2ba8992ce23 100644 --- a/pandatool/src/xfile/xFileDataNodeTemplate.cxx +++ b/pandatool/src/xfile/xFileDataNodeTemplate.cxx @@ -25,7 +25,7 @@ TypeHandle XFileDataNodeTemplate::_type_handle; * */ XFileDataNodeTemplate:: -XFileDataNodeTemplate(XFile *x_file, const string &name, +XFileDataNodeTemplate(XFile *x_file, std::string_view name, XFileTemplate *xtemplate) : XFileDataNode(x_file, name, xtemplate) { @@ -79,9 +79,9 @@ add_parse_int(PTA_int int_list) { * will later be processed by finalize_parse_data(). */ void XFileDataNodeTemplate:: -add_parse_string(const string &str) { +add_parse_string(std::string str) { XFileParseData pdata; - pdata._string = str; + pdata._string = std::move(str); pdata._parse_flags = XFileParseData::PF_string; _parse_data_list._list.push_back(pdata); @@ -216,7 +216,7 @@ get_element(int n) { * name. */ XFileDataObject *XFileDataNodeTemplate:: -get_element(const string &name) { +get_element(std::string_view name) { int child_index = _template->find_child_index(name); if (child_index >= 0) { return get_element(child_index); diff --git a/pandatool/src/xfile/xFileDataNodeTemplate.h b/pandatool/src/xfile/xFileDataNodeTemplate.h index 521c3752e2d..c4d1d32314a 100644 --- a/pandatool/src/xfile/xFileDataNodeTemplate.h +++ b/pandatool/src/xfile/xFileDataNodeTemplate.h @@ -29,7 +29,7 @@ */ class XFileDataNodeTemplate : public XFileDataNode { public: - XFileDataNodeTemplate(XFile *x_file, const std::string &name, + XFileDataNodeTemplate(XFile *x_file, std::string_view name, XFileTemplate *xtemplate); void zero_fill(); @@ -38,7 +38,7 @@ class XFileDataNodeTemplate : public XFileDataNode { void add_parse_double(PTA_double double_list); void add_parse_int(PTA_int int_list); - void add_parse_string(const std::string &str); + void add_parse_string(std::string str); bool finalize_parse_data(); virtual bool add_element(XFileDataObject *element); @@ -50,7 +50,7 @@ class XFileDataNodeTemplate : public XFileDataNode { protected: virtual int get_num_elements() const; virtual XFileDataObject *get_element(int n); - virtual XFileDataObject *get_element(const std::string &name); + virtual XFileDataObject *get_element(std::string_view name); private: XFileParseDataList _parse_data_list; diff --git a/pandatool/src/xfile/xFileDataObject.I b/pandatool/src/xfile/xFileDataObject.I index 269bc0b0e95..37abfb841c8 100644 --- a/pandatool/src/xfile/xFileDataObject.I +++ b/pandatool/src/xfile/xFileDataObject.I @@ -55,7 +55,7 @@ operator = (double double_value) { * value. */ INLINE void XFileDataObject:: -operator = (const std::string &string_value) { +operator = (std::string_view string_value) { set(string_value); } @@ -125,8 +125,8 @@ set(double double_value) { * value. */ INLINE void XFileDataObject:: -set(const std::string &string_value) { - set_string_value(string_value); +set(std::string_view string_value) { + set_string_value(std::string(string_value)); } /** @@ -268,7 +268,7 @@ operator [] (int n) const { * doubt. */ INLINE const XFileDataObject &XFileDataObject:: -operator [] (const std::string &name) const { +operator [] (std::string_view name) const { const XFileDataObject *element = ((XFileDataObject *)this)->get_element(name); nassertr(element != nullptr, *this); return *element; @@ -291,7 +291,7 @@ operator [] (int n) { * doubt. */ INLINE XFileDataObject &XFileDataObject:: -operator [] (const std::string &name) { +operator [] (std::string_view name) { XFileDataObject *element = get_element(name); nassertr(element != nullptr, *this); return *element; diff --git a/pandatool/src/xfile/xFileDataObject.cxx b/pandatool/src/xfile/xFileDataObject.cxx index f3cf0b0303b..04ac6756ca3 100644 --- a/pandatool/src/xfile/xFileDataObject.cxx +++ b/pandatool/src/xfile/xFileDataObject.cxx @@ -82,9 +82,9 @@ add_double(double double_value) { * cases for a DataNodeTemplate. */ XFileDataObject &XFileDataObject:: -add_string(const string &string_value) { +add_string(std::string string_value) { XFileDataObject *object = - new XFileDataObjectString(get_data_def(), string_value); + new XFileDataObjectString(get_data_def(), std::move(string_value)); add_element(object); return *object; } @@ -205,7 +205,7 @@ set_double_value(double double_value) { * Sets the object's value as a string, if this is legal. */ void XFileDataObject:: -set_string_value(const string &string_value) { +set_string_value(std::string string_value) { xfile_cat.error() << get_type_name() << " does not support string values.\n"; } @@ -298,7 +298,7 @@ get_element(int n) { * name. */ XFileDataObject *XFileDataObject:: -get_element(const string &name) { +get_element(std::string_view name) { xfile_cat.warning() << "Looking for [\"" << name << "\"] within data object of type " << get_type_name() << ", does not support nested objects.\n"; diff --git a/pandatool/src/xfile/xFileDataObject.h b/pandatool/src/xfile/xFileDataObject.h index 814d5f3c3f4..f18d521b147 100644 --- a/pandatool/src/xfile/xFileDataObject.h +++ b/pandatool/src/xfile/xFileDataObject.h @@ -39,7 +39,7 @@ class XFileDataObject : virtual public ReferenceCount { INLINE void operator = (int int_value); INLINE void operator = (double double_value); - INLINE void operator = (const std::string &string_value); + INLINE void operator = (std::string_view string_value); INLINE void operator = (const LVecBase2d &vec); INLINE void operator = (const LVecBase3d &vec); INLINE void operator = (const LVecBase4d &vec); @@ -47,7 +47,7 @@ class XFileDataObject : virtual public ReferenceCount { INLINE void set(int int_value); INLINE void set(double double_value); - INLINE void set(const std::string &string_value); + INLINE void set(std::string_view string_value); INLINE void set(const LVecBase2d &vec); INLINE void set(const LVecBase3d &vec); INLINE void set(const LVecBase4d &vec); @@ -63,17 +63,17 @@ class XFileDataObject : virtual public ReferenceCount { INLINE int size() const; INLINE const XFileDataObject &operator [] (int n) const; - INLINE const XFileDataObject &operator [] (const std::string &name) const; + INLINE const XFileDataObject &operator [] (std::string_view name) const; INLINE XFileDataObject &operator [] (int n); - INLINE XFileDataObject &operator [] (const std::string &name); + INLINE XFileDataObject &operator [] (std::string_view name); // The following methods can be used to add elements of a specific type to a // complex object, e.g. an array or a template object. XFileDataObject &add_int(int int_value); XFileDataObject &add_double(double double_value); - XFileDataObject &add_string(const std::string &string_value); + XFileDataObject &add_string(std::string string_value); // The following methods can be used to add elements of a specific type, // based on one of the standard templates. @@ -94,7 +94,7 @@ class XFileDataObject : virtual public ReferenceCount { protected: virtual void set_int_value(int int_value); virtual void set_double_value(double double_value); - virtual void set_string_value(const std::string &string_value); + virtual void set_string_value(std::string string_value); void store_double_array(int num_elements, const double *values); virtual int get_int_value() const; @@ -104,7 +104,7 @@ class XFileDataObject : virtual public ReferenceCount { virtual int get_num_elements() const; virtual XFileDataObject *get_element(int n); - virtual XFileDataObject *get_element(const std::string &name); + virtual XFileDataObject *get_element(std::string_view name); const XFileDataDef *_data_def; diff --git a/pandatool/src/xfile/xFileDataObjectString.cxx b/pandatool/src/xfile/xFileDataObjectString.cxx index 99ef31a89f2..56e03644ffd 100644 --- a/pandatool/src/xfile/xFileDataObjectString.cxx +++ b/pandatool/src/xfile/xFileDataObjectString.cxx @@ -23,9 +23,9 @@ TypeHandle XFileDataObjectString::_type_handle; * */ XFileDataObjectString:: -XFileDataObjectString(const XFileDataDef *data_def, const string &value) : +XFileDataObjectString(const XFileDataDef *data_def, std::string value) : XFileDataObject(data_def), - _value(value) + _value(std::move(value)) { } @@ -51,8 +51,8 @@ write_data(std::ostream &out, int indent_level, const char *separator) const { * Sets the object's value as a string, if this is legal. */ void XFileDataObjectString:: -set_string_value(const string &string_value) { - _value = string_value; +set_string_value(std::string string_value) { + _value = std::move(string_value); } /** diff --git a/pandatool/src/xfile/xFileDataObjectString.h b/pandatool/src/xfile/xFileDataObjectString.h index 1fd10dea2b0..674812d7ddd 100644 --- a/pandatool/src/xfile/xFileDataObjectString.h +++ b/pandatool/src/xfile/xFileDataObjectString.h @@ -23,14 +23,14 @@ */ class XFileDataObjectString : public XFileDataObject { public: - XFileDataObjectString(const XFileDataDef *data_def, const std::string &value); + XFileDataObjectString(const XFileDataDef *data_def, std::string value); virtual void output_data(std::ostream &out) const; virtual void write_data(std::ostream &out, int indent_level, const char *separator) const; protected: - virtual void set_string_value(const std::string &string_value); + virtual void set_string_value(std::string string_value); virtual std::string get_string_value() const; private: diff --git a/pandatool/src/xfile/xFileNode.cxx b/pandatool/src/xfile/xFileNode.cxx index 51c795e42a5..3d09a004e2f 100644 --- a/pandatool/src/xfile/xFileNode.cxx +++ b/pandatool/src/xfile/xFileNode.cxx @@ -29,12 +29,12 @@ TypeHandle XFileNode::_type_handle; * */ XFileNode:: -XFileNode(XFile *x_file, const string &name) : +XFileNode(XFile *x_file, std::string_view name) : Namable(), _x_file(x_file) { if (x_file && x_file->_keep_names) { - set_name(name); + set_name(std::string(name)); } else { set_name(make_nice_name(name)); } @@ -52,7 +52,7 @@ XFileNode:: * Returns the child with the indicated name, if any, or NULL if none. */ XFileNode *XFileNode:: -find_child(const string &name) const { +find_child(std::string_view name) const { ChildrenByName::const_iterator ni; ni = _children_by_name.find(downcase(name)); if (ni != _children_by_name.end()) { @@ -67,7 +67,7 @@ find_child(const string &name) const { * -1 if none. */ int XFileNode:: -find_child_index(const string &name) const { +find_child_index(std::string_view name) const { ChildrenByName::const_iterator ni; ni = _children_by_name.find(downcase(name)); if (ni != _children_by_name.end()) { @@ -96,7 +96,7 @@ find_child_index(const XFileNode *child) const { * depth-first search, if any, or NULL if none. */ XFileNode *XFileNode:: -find_descendent(const string &name) const { +find_descendent(std::string_view name) const { XFileNode *child = find_child(name); if (child != nullptr) { return child; @@ -180,7 +180,7 @@ is_object() const { * an XFileDataNodeTemplate or an XFileDataNodeReference). */ bool XFileNode:: -is_standard_object(const string &template_name) const { +is_standard_object(std::string_view template_name) const { return false; } @@ -297,7 +297,7 @@ matches(const XFileNode *other) const { * Creates a new Mesh instance, as a child of this node. */ XFileDataNode *XFileNode:: -add_Mesh(const string &name) { +add_Mesh(std::string_view name) { XFileTemplate *xtemplate = XFile::find_standard_template("Mesh"); nassertr(xtemplate != nullptr, nullptr); XFileDataNodeTemplate *node = @@ -312,7 +312,7 @@ add_Mesh(const string &name) { * Creates a new MeshNormals instance, as a child of this node. */ XFileDataNode *XFileNode:: -add_MeshNormals(const string &name) { +add_MeshNormals(std::string_view name) { XFileTemplate *xtemplate = XFile::find_standard_template("MeshNormals"); nassertr(xtemplate != nullptr, nullptr); XFileDataNodeTemplate *node = @@ -327,7 +327,7 @@ add_MeshNormals(const string &name) { * Creates a new MeshVertexColors instance, as a child of this node. */ XFileDataNode *XFileNode:: -add_MeshVertexColors(const string &name) { +add_MeshVertexColors(std::string_view name) { XFileTemplate *xtemplate = XFile::find_standard_template("MeshVertexColors"); nassertr(xtemplate != nullptr, nullptr); XFileDataNodeTemplate *node = @@ -342,7 +342,7 @@ add_MeshVertexColors(const string &name) { * Creates a new MeshTextureCoords instance, as a child of this node. */ XFileDataNode *XFileNode:: -add_MeshTextureCoords(const string &name) { +add_MeshTextureCoords(std::string_view name) { XFileTemplate *xtemplate = XFile::find_standard_template("MeshTextureCoords"); nassertr(xtemplate != nullptr, nullptr); XFileDataNodeTemplate *node = @@ -357,7 +357,7 @@ add_MeshTextureCoords(const string &name) { * Creates a new MeshMaterialList instance, as a child of this node. */ XFileDataNode *XFileNode:: -add_MeshMaterialList(const string &name) { +add_MeshMaterialList(std::string_view name) { XFileTemplate *xtemplate = XFile::find_standard_template("MeshMaterialList"); nassertr(xtemplate != nullptr, nullptr); XFileDataNodeTemplate *node = @@ -372,7 +372,7 @@ add_MeshMaterialList(const string &name) { * Creates a new Material instance, as a child of this node. */ XFileDataNode *XFileNode:: -add_Material(const string &name, const LColor &face_color, +add_Material(std::string_view name, const LColor &face_color, double power, const LRGBColor &specular_color, const LRGBColor &emissive_color) { XFileTemplate *xtemplate = XFile::find_standard_template("Material"); @@ -401,7 +401,7 @@ add_Material(const string &name, const LColor &face_color, * Creates a new TextureFilename instance, as a child of this node. */ XFileDataNode *XFileNode:: -add_TextureFilename(const string &name, const Filename &filename) { +add_TextureFilename(std::string_view name, const Filename &filename) { XFileTemplate *xtemplate = XFile::find_standard_template("TextureFilename"); nassertr(xtemplate != nullptr, nullptr); XFileDataNodeTemplate *node = @@ -418,7 +418,7 @@ add_TextureFilename(const string &name, const Filename &filename) { * Creates a new Frame instance, as a child of this node. */ XFileDataNode *XFileNode:: -add_Frame(const string &name) { +add_Frame(std::string_view name) { XFileTemplate *xtemplate = XFile::find_standard_template("Frame"); nassertr(xtemplate != nullptr, nullptr); XFileDataNodeTemplate *node = @@ -471,17 +471,16 @@ add_FrameTransformMatrix(const LMatrix4d &mat) { * in the X File format. */ string XFileNode:: -make_nice_name(const string &str) { +make_nice_name(std::string_view str) { string result; - string::const_iterator si; - for (si = str.begin(); si != str.end(); ++si) { - if (isalnum(*si)) { - result += (*si); + for (char ch : str) { + if (isalnum((unsigned char)ch)) { + result += ch; } else { - switch (*si) { + switch (ch) { case '-': - result += (*si); + result += ch; break; default: result += "_"; @@ -489,7 +488,7 @@ make_nice_name(const string &str) { } } - if (str.empty() || isdigit(str[0])) { + if (str.empty() || isdigit((unsigned char)str[0])) { // If the name begins with a digit, or if it is empty, then we must make // it begin with something else, like for instance an underscore. result = '_' + result; diff --git a/pandatool/src/xfile/xFileNode.h b/pandatool/src/xfile/xFileNode.h index 2cd9f6d3f6e..54478c3e6eb 100644 --- a/pandatool/src/xfile/xFileNode.h +++ b/pandatool/src/xfile/xFileNode.h @@ -42,17 +42,17 @@ class XFileNode : public TypedObject, public Namable, INLINE XFileNode(XFile *x_file); public: - XFileNode(XFile *x_file, const std::string &name); + XFileNode(XFile *x_file, std::string_view name); virtual ~XFileNode(); INLINE XFile *get_x_file() const; INLINE int get_num_children() const; INLINE XFileNode *get_child(int n) const; - XFileNode *find_child(const std::string &name) const; - int find_child_index(const std::string &name) const; + XFileNode *find_child(std::string_view name) const; + int find_child_index(std::string_view name) const; int find_child_index(const XFileNode *child) const; - XFileNode *find_descendent(const std::string &name) const; + XFileNode *find_descendent(std::string_view name) const; INLINE int get_num_objects() const; INLINE XFileDataNode *get_object(int n) const; @@ -63,7 +63,7 @@ class XFileNode : public TypedObject, public Namable, virtual bool is_template_def() const; virtual bool is_reference() const; virtual bool is_object() const; - virtual bool is_standard_object(const std::string &template_name) const; + virtual bool is_standard_object(std::string_view template_name) const; void add_child(XFileNode *node); virtual void clear(); @@ -84,21 +84,21 @@ class XFileNode : public TypedObject, public Namable, // The following methods can be used to create instances of the standard // template objects. These definitions match those defined in // standardTemplates.x in this directory (and compiled into the executable). - XFileDataNode *add_Mesh(const std::string &name); - XFileDataNode *add_MeshNormals(const std::string &name); - XFileDataNode *add_MeshVertexColors(const std::string &name); - XFileDataNode *add_MeshTextureCoords(const std::string &name); - XFileDataNode *add_MeshMaterialList(const std::string &name); - XFileDataNode *add_Material(const std::string &name, const LColor &face_color, + XFileDataNode *add_Mesh(std::string_view name); + XFileDataNode *add_MeshNormals(std::string_view name); + XFileDataNode *add_MeshVertexColors(std::string_view name); + XFileDataNode *add_MeshTextureCoords(std::string_view name); + XFileDataNode *add_MeshMaterialList(std::string_view name); + XFileDataNode *add_Material(std::string_view name, const LColor &face_color, double power, const LRGBColor &specular_color, const LRGBColor &emissive_color); - XFileDataNode *add_TextureFilename(const std::string &name, + XFileDataNode *add_TextureFilename(std::string_view name, const Filename &filename); - XFileDataNode *add_Frame(const std::string &name); + XFileDataNode *add_Frame(std::string_view name); XFileDataNode *add_FrameTransformMatrix(const LMatrix4d &mat); public: - static std::string make_nice_name(const std::string &str); + static std::string make_nice_name(std::string_view str); protected: XFile *_x_file; @@ -109,7 +109,7 @@ class XFileNode : public TypedObject, public Namable, typedef pvector Objects; Objects _objects; - typedef pmap ChildrenByName; + typedef pmap> ChildrenByName; ChildrenByName _children_by_name; public: diff --git a/pandatool/src/xfile/xFileTemplate.cxx b/pandatool/src/xfile/xFileTemplate.cxx index e4ef5e2c170..1f46485c0b6 100644 --- a/pandatool/src/xfile/xFileTemplate.cxx +++ b/pandatool/src/xfile/xFileTemplate.cxx @@ -20,7 +20,7 @@ TypeHandle XFileTemplate::_type_handle; * */ XFileTemplate:: -XFileTemplate(XFile *x_file, const std::string &name, const WindowsGuid &guid) : +XFileTemplate(XFile *x_file, std::string_view name, const WindowsGuid &guid) : XFileNode(x_file, name), _guid(guid), _is_standard(false), diff --git a/pandatool/src/xfile/xFileTemplate.h b/pandatool/src/xfile/xFileTemplate.h index d119a297b7f..3ba7d867d35 100644 --- a/pandatool/src/xfile/xFileTemplate.h +++ b/pandatool/src/xfile/xFileTemplate.h @@ -26,7 +26,7 @@ class XFileDataDef; */ class XFileTemplate : public XFileNode { public: - XFileTemplate(XFile *x_file, const std::string &name, const WindowsGuid &guid); + XFileTemplate(XFile *x_file, std::string_view name, const WindowsGuid &guid); virtual ~XFileTemplate(); virtual bool has_guid() const; diff --git a/pandatool/src/xfileegg/xFileAnimationSet.cxx b/pandatool/src/xfileegg/xFileAnimationSet.cxx index f76bc33ee93..abb3981bbd9 100644 --- a/pandatool/src/xfileegg/xFileAnimationSet.cxx +++ b/pandatool/src/xfileegg/xFileAnimationSet.cxx @@ -98,7 +98,7 @@ create_hierarchy(XFileToEggConverter *converter) { * Returns the table associated with the indicated joint name. */ EggXfmSAnim *XFileAnimationSet:: -get_table(const std::string &joint_name) const { +get_table(std::string_view joint_name) const { Tables::const_iterator ti; ti = _tables.find(joint_name); if (ti != _tables.end()) { diff --git a/pandatool/src/xfileegg/xFileAnimationSet.h b/pandatool/src/xfileegg/xFileAnimationSet.h index a0bec7d43a6..fd4aedaab75 100644 --- a/pandatool/src/xfileegg/xFileAnimationSet.h +++ b/pandatool/src/xfileegg/xFileAnimationSet.h @@ -36,7 +36,7 @@ class XFileAnimationSet : public Namable { ~XFileAnimationSet(); bool create_hierarchy(XFileToEggConverter *converter); - EggXfmSAnim *get_table(const std::string &joint_name) const; + EggXfmSAnim *get_table(std::string_view joint_name) const; enum FrameDataFlags { FDF_scale = 0x01, @@ -74,7 +74,7 @@ class XFileAnimationSet : public Namable { void mirror_table(XFileToEggConverter *converter, EggGroup *model_node, EggTable *anim_node); - typedef pmap JointData; + typedef pmap> JointData; JointData _joint_data; class TablePair { @@ -83,7 +83,7 @@ class XFileAnimationSet : public Namable { EggXfmSAnim *_table; }; - typedef pmap Tables; + typedef pmap> Tables; Tables _tables; }; diff --git a/pandatool/src/xfileegg/xFileToEggConverter.cxx b/pandatool/src/xfileegg/xFileToEggConverter.cxx index 91ba21ba978..bfae96b7f92 100644 --- a/pandatool/src/xfileegg/xFileToEggConverter.cxx +++ b/pandatool/src/xfileegg/xFileToEggConverter.cxx @@ -224,7 +224,7 @@ create_unique_material(const EggMaterial ©) { * transform. */ EggGroup *XFileToEggConverter:: -find_joint(const string &joint_name) { +find_joint(std::string_view joint_name) { Joints::iterator ji; ji = _joints.find(joint_name); if (ji != _joints.end()) { @@ -243,7 +243,7 @@ find_joint(const string &joint_name) { xfile_cat.warning() << "Joint name " << joint_name << " in animation data is undefined.\n"; } - _joints[joint_name] = nullptr; + _joints[std::string(joint_name)] = nullptr; return nullptr; } @@ -545,7 +545,7 @@ convert_animation(XFileDataNode *obj, XFileAnimationSet &animation_set) { * Converts the indicated object, a child of a Animation. */ bool XFileToEggConverter:: -convert_animation_object(XFileDataNode *obj, const string &joint_name, +convert_animation_object(XFileDataNode *obj, std::string_view joint_name, XFileToEggConverter::FrameData &table) { if (obj->is_standard_object("AnimationOptions")) { // Quietly ignore AnimationOptions. @@ -573,7 +573,7 @@ convert_animation_object(XFileDataNode *obj, const string &joint_name, * Converts the indicated AnimationKey template object. */ bool XFileToEggConverter:: -convert_animation_key(XFileDataNode *obj, const string &joint_name, +convert_animation_key(XFileDataNode *obj, std::string_view joint_name, XFileToEggConverter::FrameData &table) { int key_type = (*obj)["keyType"].i(); @@ -609,7 +609,7 @@ convert_animation_key(XFileDataNode *obj, const string &joint_name, * Sets a single frame of the animation data. */ bool XFileToEggConverter:: -set_animation_frame(const string &joint_name, +set_animation_frame(std::string_view joint_name, XFileToEggConverter::FrameData &table, int frame, int key_type, const XFileDataObject &values) { if ((int)table._entries.size() <= frame) { diff --git a/pandatool/src/xfileegg/xFileToEggConverter.h b/pandatool/src/xfileegg/xFileToEggConverter.h index d92f4c2325a..5cfda43804f 100644 --- a/pandatool/src/xfileegg/xFileToEggConverter.h +++ b/pandatool/src/xfileegg/xFileToEggConverter.h @@ -56,7 +56,7 @@ class XFileToEggConverter : public SomethingToEggConverter { EggTexture *create_unique_texture(const EggTexture ©); EggMaterial *create_unique_material(const EggMaterial ©); - EggGroup *find_joint(const std::string &joint_name); + EggGroup *find_joint(std::string_view joint_name); void strip_nodes(TypeHandle t); public: @@ -80,10 +80,10 @@ class XFileToEggConverter : public SomethingToEggConverter { bool convert_animation(XFileDataNode *obj, XFileAnimationSet &animation_set); bool convert_animation_object(XFileDataNode *obj, - const std::string &joint_name, FrameData &table); - bool convert_animation_key(XFileDataNode *obj, const std::string &joint_name, + std::string_view joint_name, FrameData &table); + bool convert_animation_key(XFileDataNode *obj, std::string_view joint_name, FrameData &table); - bool set_animation_frame(const std::string &joint_name, FrameData &table, + bool set_animation_frame(std::string_view joint_name, FrameData &table, int frame, int key_type, const XFileDataObject &values); bool convert_mesh(XFileDataNode *obj, EggGroupNode *egg_parent); @@ -105,7 +105,7 @@ class XFileToEggConverter : public SomethingToEggConverter { typedef pvector AnimationSets; AnimationSets _animation_sets; - typedef pmap Joints; + typedef pmap> Joints; Joints _joints; EggGroup *_dart_node; diff --git a/tests/dcparser/conftest.py b/tests/dcparser/conftest.py new file mode 100644 index 00000000000..def763b7dff --- /dev/null +++ b/tests/dcparser/conftest.py @@ -0,0 +1,12 @@ +import pytest +from pathlib import Path + + +@pytest.fixture(scope="module") +def dc_file(): + direct = pytest.importorskip("panda3d.direct") + dcf = direct.DCFile() + path = Path(__file__).parent / "schema.dc" + success = dcf.read(path) + assert success, "failed to parse DC fixture" + return dcf diff --git a/tests/dcparser/schema.dc b/tests/dcparser/schema.dc new file mode 100644 index 00000000000..50860cf12a6 --- /dev/null +++ b/tests/dcparser/schema.dc @@ -0,0 +1,21 @@ +typedef uint32 DoId; + +dclass Avatar { + setName(string name) required broadcast db; + setPos(int32 x, int32 y, int32 z) broadcast; + setHealth(uint16 health = 100) required broadcast ram; +}; + +struct Item { + uint16 itemId; + string label; + uint8 quantity = 1; +}; + +dclass Inventory : Avatar { + setItems(Item items[]); + setItem(Item item); + setColor(uint8 r, uint8 g, uint8 b); + setBlob(blob data); + setRanged(int16(-100 - 100) value); +}; diff --git a/tests/dcparser/test_dcfile.py b/tests/dcparser/test_dcfile.py new file mode 100644 index 00000000000..d83fcbd5fbe --- /dev/null +++ b/tests/dcparser/test_dcfile.py @@ -0,0 +1,61 @@ +import pytest + +direct = pytest.importorskip("panda3d.direct") + + +def test_dcfile_get_class_by_name(dc_file): + avatar = dc_file.get_class_by_name("Avatar") + inventory = dc_file.get_class_by_name("Inventory") + item = dc_file.get_class_by_name("Item") + assert avatar is not None and avatar.get_name() == "Avatar" + assert inventory is not None and inventory.get_name() == "Inventory" + assert item is not None and item.get_name() == "Item" + + assert dc_file.get_class_by_name("Nonexistent") is None + assert dc_file.get_class_by_name("") is None + + assert dc_file.get_class_by_name("Avata") is None + assert dc_file.get_class_by_name("AvatarX") is None + assert dc_file.get_class_by_name("Inv") is None + assert dc_file.get_class_by_name("Inventory ") is None + + +def test_dcfile_get_field_by_name(dc_file): + avatar = dc_file.get_class_by_name("Avatar") + field = avatar.get_field_by_name("setName") + assert field is not None + assert field.get_name() == "setName" + + field = avatar.get_field_by_name("setHealth") + assert field is not None and field.get_name() == "setHealth" + + # Inventory inherits from Avatar; setName lives on the parent but + # get_field_by_name() should still find it. + inventory = dc_file.get_class_by_name("Inventory") + field = inventory.get_field_by_name("setName") + assert field is not None + assert field.get_name() == "setName" + + # And the child's own fields. + field = inventory.get_field_by_name("setItems") + assert field is not None and field.get_name() == "setItems" + + assert avatar.get_field_by_name("noSuchField") is None + assert avatar.get_field_by_name("") is None + + assert avatar.get_field_by_name("set") is None + assert avatar.get_field_by_name("setNam") is None + assert avatar.get_field_by_name("setNameX") is None + assert avatar.get_field_by_name("etName") is None + + +def test_dcfile_get_field_index_roundtrip(dc_file): + # A field's index returned by get_field_by_name() should resolve back + # to the same field via get_field_by_index(). + inventory = dc_file.get_class_by_name("Inventory") + for name in ("setItems", "setColor", "setBlob", "setName", "setPos"): + field = inventory.get_field_by_name(name) + assert field is not None, name + same = dc_file.get_field_by_index(field.get_number()) + assert same is not None + assert same.get_name() == name diff --git a/tests/dcparser/test_dcpacker.py b/tests/dcparser/test_dcpacker.py index 9bf8e5252ef..609fd5e9a67 100644 --- a/tests/dcparser/test_dcpacker.py +++ b/tests/dcparser/test_dcpacker.py @@ -3,7 +3,7 @@ direct = pytest.importorskip("panda3d.direct") -def test_pack_int8(): +def test_raw_pack_int8(): for num in range(-128, 128): packer = direct.DCPacker() packer.raw_pack_int8(num) @@ -11,7 +11,7 @@ def test_pack_int8(): assert packer.raw_unpack_int8() == num -def test_pack_uint8(): +def test_raw_pack_uint8(): for num in range(256): packer = direct.DCPacker() packer.raw_pack_uint8(num) @@ -19,7 +19,7 @@ def test_pack_uint8(): assert packer.raw_unpack_uint8() == num -def test_pack_int64(): +def test_raw_pack_int64(): for num in (0, -1, 0x7fffffff, -0x80000000, 0x7fffffffffffffff, 0x7ffffffffffffffe, -0x8000000000000000, -0x7fffffffffffffff): packer = direct.DCPacker() packer.raw_pack_int64(num) @@ -27,10 +27,204 @@ def test_pack_int64(): assert packer.raw_unpack_int64() == num -def test_pack_uint64(): +def test_raw_pack_uint64(): for num in (0, 1, 0x7fffffff, 0xffffffff, 0x7fffffffffffffff, 0xfffffffffffffffe, 0xffffffffffffffff): packer = direct.DCPacker() packer.raw_pack_uint64(num) packer.set_unpack_data(packer.get_bytes()) assert packer.raw_unpack_uint64() == num + +def test_raw_pack_string(): + for value in ("", "a", "hello", "x" * 1024, "embedded\x00null", "utf8 é中"): + packer = direct.DCPacker() + packer.raw_pack_string(value) + packer.set_unpack_data(packer.get_bytes()) + assert packer.raw_unpack_string() == value + + +def _field(dc_file, class_name, field_name): + cls = dc_file.get_class_by_name(class_name) + assert cls is not None, class_name + field = cls.get_field_by_name(field_name) + assert field is not None, field_name + return field + + +def test_pack_format_parse_roundtrip_atomic(dc_file): + # Pack via pack_object, format to text, parse the text back, and verify + # the bytes match. Exercises both unpack_and_format() and the + # parse_and_pack(string) overload that now moves its source by value. + field = _field(dc_file, "Avatar", "setPos") + packer = direct.DCPacker() + packer.begin_pack(field) + packer.pack_object((1, -2, 3)) + assert packer.end_pack() + data = packer.get_bytes() + + formatted = field.format_data(data, False) + again = field.parse_string(formatted) + assert bytes(again) == bytes(data) + + +def test_pack_format_parse_roundtrip_string(dc_file): + field = _field(dc_file, "Avatar", "setName") + packer = direct.DCPacker() + packer.begin_pack(field) + packer.pack_object(("hello world",)) + assert packer.end_pack() + data = packer.get_bytes() + + formatted = field.format_data(data, False) + again = field.parse_string(formatted) + assert bytes(again) == bytes(data) + + +def test_pack_object_roundtrip_atomic(dc_file): + field = _field(dc_file, "Inventory", "setColor") + packer = direct.DCPacker() + packer.begin_pack(field) + packer.pack_object((10, 20, 30)) + assert packer.end_pack() + data = packer.get_bytes() + + packer = direct.DCPacker() + packer.set_unpack_data(data) + packer.begin_unpack(field) + value = packer.unpack_object() + assert packer.end_unpack() + assert tuple(value) == (10, 20, 30) + + +def test_pack_object_roundtrip_blob(dc_file): + field = _field(dc_file, "Inventory", "setBlob") + payload = bytes(range(256)) + b"\x00\x01\x00\x02" + packer = direct.DCPacker() + packer.begin_pack(field) + packer.pack_object((payload,)) + assert packer.end_pack() + data = packer.get_bytes() + + packer = direct.DCPacker() + packer.set_unpack_data(data) + packer.begin_unpack(field) + value = packer.unpack_object() + assert packer.end_unpack() + # unpack_object returns a tuple-ish container for atomic fields. + assert bytes(value[0]) == payload + + +def test_pack_object_roundtrip_nested_struct_array(dc_file): + field = _field(dc_file, "Inventory", "setItems") + items = [ + (1, "sword", 1), + (2, "potion", 5), + (3, "", 0), + ] + packer = direct.DCPacker() + packer.begin_pack(field) + packer.pack_object((items,)) + assert packer.end_pack() + data = packer.get_bytes() + + packer = direct.DCPacker() + packer.set_unpack_data(data) + packer.begin_unpack(field) + unpacked = packer.unpack_object() + assert packer.end_unpack() + out = [tuple(item) for item in unpacked[0]] + assert out == items + + +def test_pack_range_error(dc_file): + # setRanged restricts int16 to (-100, 100); an out-of-range value must + # be flagged as an error rather than silently truncated. + field = _field(dc_file, "Inventory", "setRanged") + packer = direct.DCPacker() + packer.begin_pack(field) + packer.pack_object((9999,)) + # end_pack() returns False once the packer is in the error state, so we + # don't assert on it here. had_error() is the signal we care about. + packer.end_pack() + assert packer.had_error() + + +def test_pack_seek_by_name_repack(dc_file): + # setItem(Item item) gives us a packable field whose nested struct fields + # (itemId, label, quantity) can be reached by name via DCPacker::seek(). + field = _field(dc_file, "Inventory", "setItem") + + # Pack an initial Item value. + packer = direct.DCPacker() + packer.begin_pack(field) + packer.pack_object(((42, "potion", 5),)) + assert packer.end_pack() + data = packer.get_bytes() + + # Re-open in repack mode and seek by (local) name to overwrite just + # 'quantity'. The catalog indexes both fully-qualified ("item.quantity") + # and local ("quantity") names, so either spelling must resolve. + packer = direct.DCPacker() + packer.set_unpack_data(data) + packer.begin_repack(field) + assert packer.seek("quantity"), "seek by local name failed" + packer.pack_object(99) + assert packer.end_repack() + new_data = packer.get_bytes() + + # Unpack everything and verify only 'quantity' changed. + packer = direct.DCPacker() + packer.set_unpack_data(new_data) + packer.begin_unpack(field) + unpacked = packer.unpack_object() + assert packer.end_unpack() + item = tuple(unpacked[0]) + assert item == (42, "potion", 99) + + # Verify the qualified-name spelling resolves too. We can't chain two + # seeks in a single repack cycle (the first seek leaves _current_field + # set), so run a fresh repack on the original data. + packer = direct.DCPacker() + packer.set_unpack_data(data) + packer.begin_repack(field) + assert packer.seek("item.quantity"), "seek by qualified name failed" + packer.pack_object(7) + assert packer.end_repack() + qualified_data = packer.get_bytes() + + packer = direct.DCPacker() + packer.set_unpack_data(qualified_data) + packer.begin_unpack(field) + unpacked = packer.unpack_object() + assert packer.end_unpack() + assert tuple(unpacked[0]) == (42, "potion", 7) + + +def test_pack_seek_by_name_missing(dc_file): + field = _field(dc_file, "Inventory", "setItem") + packer = direct.DCPacker() + packer.begin_pack(field) + packer.pack_object(((1, "x", 1),)) + assert packer.end_pack() + data = packer.get_bytes() + + packer = direct.DCPacker() + packer.set_unpack_data(data) + packer.begin_repack(field) + # A non-existent name, a substring of a real name, and an empty string + # should all fail the seek rather than silently land on something. + assert not packer.seek("nonexistent") + assert not packer.seek("quant") + assert not packer.seek("item.quanti") + assert not packer.seek("") + # A valid seek after the failed ones must still work--the failures + # shouldn't have left the packer in a bad state. + assert packer.seek("quantity") + + # And the qualified spelling also recovers from failed seeks, on a + # fresh repack cycle (chained seeks in one cycle aren't allowed). + packer = direct.DCPacker() + packer.set_unpack_data(data) + packer.begin_repack(field) + assert not packer.seek("nonexistent") + assert packer.seek("item.quantity") diff --git a/tests/downloader/test_http_cookie.py b/tests/downloader/test_http_cookie.py new file mode 100644 index 00000000000..a971a0b89fd --- /dev/null +++ b/tests/downloader/test_http_cookie.py @@ -0,0 +1,191 @@ +import pytest +from panda3d import core + + +# HTTPCookie is only available when OpenSSL support is compiled in. +HTTPCookie = getattr(core, "HTTPCookie", None) +URLSpec = core.URLSpec +HTTPDate = core.HTTPDate + +pytestmark = pytest.mark.skipif(HTTPCookie is None, + reason="Requires OpenSSL") + + +def _url(s="http://example.com/some/path"): + return URLSpec(s) + + +def test_http_cookie_default_construct(): + c = HTTPCookie() + assert c.get_name() == "" + assert c.get_value() == "" + assert c.get_path() == "" + assert c.get_domain() == "" + assert not c.get_secure() + assert c.get_samesite() == HTTPCookie.SS_unspecified + + +def test_http_cookie_construct_with_name_path_domain(): + c = HTTPCookie("sessionid", "/foo", "example.com") + assert c.get_name() == "sessionid" + assert c.get_path() == "/foo" + assert c.get_domain() == "example.com" + + +def test_http_cookie_parse_simple_name_value(): + c = HTTPCookie("k=v", _url()) + assert c.get_name() == "k" + assert c.get_value() == "v" + # The path defaults to the URL path. + assert c.get_path() == "/some/path" + # The domain defaults to the URL server. + assert c.get_domain() == "example.com" + + +def test_http_cookie_parse_empty_value(): + c = HTTPCookie("k=", _url()) + assert c.get_name() == "k" + assert c.get_value() == "" + + +def test_http_cookie_parse_no_equals_in_first_param(): + # A first parameter without '=' is treated as the name with empty value. + c = HTTPCookie("flag", _url()) + assert c.get_name() == "flag" + assert c.get_value() == "" + + +def test_http_cookie_parse_path_attribute(): + c = HTTPCookie("k=v; path=/api", _url()) + assert c.get_path() == "/api" + + +def test_http_cookie_parse_domain_attribute_adds_leading_dot(): + # RFC 2965: if domain doesn't start with a dot, the user agent adds one. + c = HTTPCookie("k=v; domain=example.com", _url()) + assert c.get_domain() == ".example.com" + + +def test_http_cookie_parse_domain_attribute_preserves_leading_dot(): + c = HTTPCookie("k=v; domain=.example.com", _url()) + assert c.get_domain() == ".example.com" + + +def test_http_cookie_parse_domain_lowercased(): + c = HTTPCookie("k=v; domain=Example.COM", _url()) + assert c.get_domain() == ".example.com" + + +def test_http_cookie_parse_secure_flag(): + c = HTTPCookie("k=v; secure", _url()) + assert c.get_secure() + + +def test_http_cookie_parse_without_secure_flag(): + c = HTTPCookie("k=v", _url()) + assert not c.get_secure() + + +def test_http_cookie_parse_samesite_lax(): + c = HTTPCookie("k=v; samesite=Lax", _url()) + assert c.get_samesite() == HTTPCookie.SS_lax + + +def test_http_cookie_parse_samesite_strict(): + c = HTTPCookie("k=v; samesite=Strict", _url()) + assert c.get_samesite() == HTTPCookie.SS_strict + + +def test_http_cookie_parse_samesite_none(): + c = HTTPCookie("k=v; samesite=None", _url()) + assert c.get_samesite() == HTTPCookie.SS_none + + +def test_http_cookie_parse_samesite_unknown_kept_unspecified(): + c = HTTPCookie("k=v; samesite=Bogus", _url()) + assert c.get_samesite() == HTTPCookie.SS_unspecified + + +def test_http_cookie_parse_expires(): + c = HTTPCookie("k=v; expires=Wed, 21 Oct 2015 07:28:00 GMT", _url()) + # Note: the embedded comma after "Wed" is itself a token separator in + # parse_set_cookie, so we don't worry here whether the weekday was + # consumed -- the resulting date must just be the one we wrote. + assert c.has_expires() + assert c.get_expires().get_time() == 1445412480 + + +def test_http_cookie_parse_all_attributes_together(): + raw = ("sid=abc123; path=/api; domain=example.com; " + "secure; samesite=Strict") + c = HTTPCookie(raw, _url()) + assert c.get_name() == "sid" + assert c.get_value() == "abc123" + assert c.get_path() == "/api" + assert c.get_domain() == ".example.com" + assert c.get_secure() + assert c.get_samesite() == HTTPCookie.SS_strict + + +def test_http_cookie_parse_leading_whitespace_between_params(): + c = HTTPCookie("k=v; path=/api ; secure", _url()) + assert c.get_name() == "k" + assert c.get_path() == "/api " # Trailing space inside value is preserved + assert c.get_secure() + + +def test_http_cookie_setters_update_fields(): + c = HTTPCookie() + c.set_name("foo") + c.set_value("bar") + c.set_path("/abc") + c.set_domain(".example.com") + c.set_secure(True) + c.set_samesite(HTTPCookie.SS_lax) + assert c.get_name() == "foo" + assert c.get_value() == "bar" + assert c.get_path() == "/abc" + assert c.get_domain() == ".example.com" + assert c.get_secure() + assert c.get_samesite() == HTTPCookie.SS_lax + + +def test_http_cookie_matches_url_same_domain(): + c = HTTPCookie("k=v; domain=example.com", _url("http://example.com/")) + assert c.matches_url(URLSpec("http://example.com/anything")) + + +def test_http_cookie_matches_url_path_prefix(): + c = HTTPCookie("k=v; path=/api", _url("http://example.com/")) + assert c.matches_url(URLSpec("http://example.com/api/v1/items")) + assert not c.matches_url(URLSpec("http://example.com/other")) + + +def test_http_cookie_matches_url_secure_requires_https(): + c = HTTPCookie("k=v; secure", _url("https://example.com/")) + assert c.matches_url(URLSpec("https://example.com/anything")) + assert not c.matches_url(URLSpec("http://example.com/anything")) + + +def test_http_cookie_is_expired(): + c = HTTPCookie("k=v; expires=Wed, 21 Oct 2015 07:28:00 GMT", _url()) + # 2015 is comfortably in the past. + assert c.is_expired() + + +def test_http_cookie_not_expired_when_no_expiry(): + c = HTTPCookie("k=v", _url()) + # is_expired() is only true when an expiry is set AND past. + assert not c.is_expired() + + +def test_http_cookie_ordering_by_domain_then_path(): + a = HTTPCookie("k=v; domain=a.example.com; path=/", _url()) + b = HTTPCookie("k=v; domain=b.example.com; path=/", _url()) + assert a < b + + # Same domain: paths are sorted in reverse lexicographic order, so a more + # specific (longer) sub-path of a common prefix sorts before its parent. + longer = HTTPCookie("k=v; domain=x.example.com; path=/api/v1/items", _url()) + shorter = HTTPCookie("k=v; domain=x.example.com; path=/api", _url()) + assert longer < shorter diff --git a/tests/downloader/test_http_date.py b/tests/downloader/test_http_date.py new file mode 100644 index 00000000000..67238b17532 --- /dev/null +++ b/tests/downloader/test_http_date.py @@ -0,0 +1,112 @@ +import time + +from panda3d.core import HTTPDate + + +def test_http_date_default_invalid(): + d = HTTPDate() + assert not d.is_valid() + + +def test_http_date_from_time_t(): + d = HTTPDate(0) + assert d.is_valid() + # Unix epoch + assert d.get_string() == "Thu, 01 Jan 1970 00:00:00 GMT" + + +def test_http_date_known_epoch(): + # 21 Oct 2015 07:28:00 GMT == 1445412480 + d = HTTPDate(1445412480) + assert d.is_valid() + assert d.get_string() == "Wed, 21 Oct 2015 07:28:00 GMT" + + +def test_http_date_parse_rfc1123(): + d = HTTPDate("Wed, 21 Oct 2015 07:28:00 GMT") + assert d.is_valid() + assert d.get_time() == 1445412480 + + +def test_http_date_parse_without_weekday(): + # The weekday is optional in get_token-based parser; the parser figures it out. + d = HTTPDate("21 Oct 2015 07:28:00 GMT") + assert d.is_valid() + assert d.get_time() == 1445412480 + + +def test_http_date_parse_lowercase_components(): + d = HTTPDate("wed, 21 oct 2015 07:28:00 gmt") + assert d.is_valid() + assert d.get_time() == 1445412480 + + +def test_http_date_parse_mixed_separators(): + # The parser accepts a range of separators; commas and spaces are skipped. + d = HTTPDate("Wed 21 Oct 2015 07:28:00 GMT") + assert d.is_valid() + assert d.get_time() == 1445412480 + + +def test_http_date_parse_invalid_garbage(): + d = HTTPDate("not a real date") + assert not d.is_valid() + + +def test_http_date_parse_missing_fields(): + # No year/hour/minute -> invalid. + d = HTTPDate("Wed, 21 Oct") + assert not d.is_valid() + + +def test_http_date_parse_out_of_range_month(): + # Month name not recognized. + d = HTTPDate("Wed, 21 Foo 2015 07:28:00 GMT") + assert not d.is_valid() + + +def test_http_date_get_string_roundtrip(): + original = HTTPDate(1445412480) + s = original.get_string() + reparsed = HTTPDate(s) + assert reparsed.is_valid() + assert reparsed.get_time() == original.get_time() + assert reparsed.get_string() == s + + +def test_http_date_now_is_close(): + # HTTPDate::now() should be close to current time. + before = int(time.time()) + d = HTTPDate.now() + after = int(time.time()) + assert d.is_valid() + assert before <= d.get_time() <= after + + +def test_http_date_comparison(): + early = HTTPDate(1000000) + late = HTTPDate(2000000) + assert early < late + assert late > early + assert early != late + + same = HTTPDate(1000000) + assert early == same + assert not (early < same) + + +def test_http_date_addition_subtraction(): + d = HTTPDate(1000) + d += 60 + assert d.get_time() == 1060 + d -= 30 + assert d.get_time() == 1030 + + assert (d + 10).get_time() == 1040 + assert (d - 10).get_time() == 1020 + + +def test_http_date_difference(): + a = HTTPDate(1000) + b = HTTPDate(1500) + assert b - a == 500 diff --git a/tests/downloader/test_http_entity_tag.py b/tests/downloader/test_http_entity_tag.py new file mode 100644 index 00000000000..b695556bb33 --- /dev/null +++ b/tests/downloader/test_http_entity_tag.py @@ -0,0 +1,129 @@ +from panda3d.core import HTTPEntityTag + + +def test_http_entity_tag_default(): + tag = HTTPEntityTag() + assert tag.get_tag() == "" + assert not tag.is_weak() + + +def test_http_entity_tag_explicit_strong(): + tag = HTTPEntityTag(False, "abc") + assert tag.get_tag() == "abc" + assert not tag.is_weak() + + +def test_http_entity_tag_explicit_weak(): + tag = HTTPEntityTag(True, "abc") + assert tag.get_tag() == "abc" + assert tag.is_weak() + + +def test_http_entity_tag_parse_unquoted(): + tag = HTTPEntityTag("abc") + assert tag.get_tag() == "abc" + assert not tag.is_weak() + + +def test_http_entity_tag_parse_quoted(): + tag = HTTPEntityTag('"abc"') + assert tag.get_tag() == "abc" + assert not tag.is_weak() + + +def test_http_entity_tag_parse_weak(): + tag = HTTPEntityTag('W/"abc"') + assert tag.get_tag() == "abc" + assert tag.is_weak() + + +def test_http_entity_tag_parse_weak_lowercase(): + # The original parser accepts a lowercase "w/" prefix as well. + tag = HTTPEntityTag('w/"abc"') + assert tag.get_tag() == "abc" + assert tag.is_weak() + + +def test_http_entity_tag_parse_empty(): + tag = HTTPEntityTag("") + assert tag.get_tag() == "" + assert not tag.is_weak() + + +def test_http_entity_tag_parse_empty_quotes(): + tag = HTTPEntityTag('""') + assert tag.get_tag() == "" + assert not tag.is_weak() + + +def test_http_entity_tag_parse_backslash_escape(): + # Inside a quoted string, a backslash escapes the next character. + tag = HTTPEntityTag(r'"a\"b"') + assert tag.get_tag() == 'a"b' + + +def test_http_entity_tag_get_string_roundtrip_strong(): + tag = HTTPEntityTag(False, "abc") + s = tag.get_string() + assert s == '"abc"' + + parsed = HTTPEntityTag(s) + assert parsed.get_tag() == "abc" + assert not parsed.is_weak() + + +def test_http_entity_tag_get_string_roundtrip_weak(): + tag = HTTPEntityTag(True, "abc") + s = tag.get_string() + assert s == 'W/"abc"' + + parsed = HTTPEntityTag(s) + assert parsed.get_tag() == "abc" + assert parsed.is_weak() + + +def test_http_entity_tag_get_string_quotes_special_chars(): + tag = HTTPEntityTag(False, 'a"b\\c') + s = tag.get_string() + # Double-quotes and backslashes inside the tag must be backslash-escaped. + assert s == r'"a\"b\\c"' + + parsed = HTTPEntityTag(s) + assert parsed.get_tag() == 'a"b\\c' + + +def test_http_entity_tag_equality_strong_strong(): + a = HTTPEntityTag(False, "abc") + b = HTTPEntityTag(False, "abc") + assert a == b + assert a.strong_equiv(b) + assert a.weak_equiv(b) + + +def test_http_entity_tag_equality_different_tag(): + a = HTTPEntityTag(False, "abc") + b = HTTPEntityTag(False, "xyz") + assert a != b + assert not a.strong_equiv(b) + assert not a.weak_equiv(b) + + +def test_http_entity_tag_equality_weak_vs_strong(): + strong = HTTPEntityTag(False, "abc") + weak = HTTPEntityTag(True, "abc") + assert strong != weak + # Strong equivalence requires both to be strong. + assert not strong.strong_equiv(weak) + # Weak equivalence allows weakness on either side. + assert strong.weak_equiv(weak) + + +def test_http_entity_tag_ordering(): + weak_a = HTTPEntityTag(True, "abc") + strong_a = HTTPEntityTag(False, "abc") + strong_b = HTTPEntityTag(False, "xyz") + + # Strong sorts before weak when the tags differ in weakness. + assert strong_a < weak_a + # Same weakness orders by tag string. + assert strong_a < strong_b diff --git a/tests/downloader/test_url_spec.py b/tests/downloader/test_url_spec.py new file mode 100644 index 00000000000..7e83d654ab9 --- /dev/null +++ b/tests/downloader/test_url_spec.py @@ -0,0 +1,510 @@ +from panda3d.core import URLSpec, Filename + + +def test_urlspec_construct_empty(): + u = URLSpec() + assert u.empty() + assert not u + assert u.get_url() == "" + assert u.length() == 0 + assert len(u) == 0 + + u = URLSpec("") + assert u.empty() + assert not u + assert u.get_url() == "" + assert u.length() == 0 + assert len(u) == 0 + + +def test_urlspec_construct_url(): + u = URLSpec("http://example.com/path?q=1") + assert not u.empty() + assert bool(u) + assert u.get_url() == "http://example.com/path?q=1" + assert u.length() == len("http://example.com/path?q=1") + + +def test_urlspec_construct_server_name(): + # Without the hint a bare hostname is parsed as a path. + plain = URLSpec("example.com") + assert plain.get_path() == "example.com" + assert not plain.has_server() + + # With the hint we get a server (and a leading "//" inserted). + with_hint = URLSpec("example.com", True) + assert with_hint.has_server() + assert with_hint.get_server() == "example.com" + assert with_hint.get_url().startswith("//example.com") + + +def test_urlspec_construct_append_path(): + base = URLSpec("http://example.com/a/") + u = URLSpec(base, Filename("b/c")) + assert u.get_path() == "/a/b/c" + + # Both ends have a slash: one is dropped. + base = URLSpec("http://example.com/a/") + u = URLSpec(base, Filename("/b")) + assert u.get_path() == "/a/b" + + # Neither has a slash: one is inserted. + base = URLSpec("http://example.com/a") + u = URLSpec(base, Filename("b")) + assert u.get_path() == "/a/b" + + # Empty path is noop. + base = URLSpec("http://example.com/a/") + u = URLSpec(base, Filename("")) + assert u.get_path() == "/a/" + + +def test_urlspec_parse(): + u = URLSpec("http://user@example.com:8080/some/path?q=1&z=2") + assert u.has_scheme() + assert u.has_authority() + assert u.has_username() + assert u.has_server() + assert u.has_port() + assert u.has_path() + assert u.has_query() + assert u.get_scheme() == "http" + assert u.get_authority() == "user@example.com:8080" + assert u.get_username() == "user" + assert u.get_server() == "example.com" + assert u.get_server_and_port() == "example.com:8080" + assert u.get_port() == 8080 + assert u.get_port_str() == "8080" + assert u.get_path() == "/some/path" + assert u.get_query() == "q=1&z=2" + + u = URLSpec("ftp://") + assert u.has_scheme() + assert u.get_scheme() == "ftp" + assert u.has_authority() + # No actual server, but the authority slot still exists (empty). + assert u.get_server() == "" + + # Scheme is lowercased + u = URLSpec("HTTP://example.com/") + assert u.get_scheme() == "http" + + # Server is lowercased + u = URLSpec("http://Example.COM/") + assert u.get_server() == "example.com" + assert u.get_server_and_port() == "example.com" + + # Trailing dot is stripped from server + u = URLSpec("http://example.com./path") + assert u.get_server() == "example.com" + assert u.get_server_and_port() == "example.com" + assert u.get_path() == "/path" + + # No leading slashes and no scheme: treated as a bare path. + u = URLSpec("foo/bar") + assert not u.has_authority() + assert u.has_path() + assert u.get_path() == "foo/bar" + + u = URLSpec("/just/a/path") + assert not u.has_scheme() + assert not u.has_authority() + assert u.get_path() == "/just/a/path" + + # Query-only + u = URLSpec("?q=1") + assert not u.has_path() + assert u.has_query() + assert u.get_query() == "q=1" + # Path defaults to "/" even when not explicitly present. + assert u.get_path() == "/" + assert u.get_path_and_query() == "/?q=1" + + # Converts backslashes to forward slashes + u = URLSpec("http:\\\\example.com\\foo") + assert u.get_server() == "example.com" + assert u.get_path() == "/foo" + + u = URLSpec("http://example.com/foo?a\\b") + assert u.get_path() == "/foo" + # Backslashes after '?' are not normalized. + assert u.get_query() == "a\\b" + + # %% is a literal escaped %, not a hex sequence. + u = URLSpec("http://example.com/a%%b") + assert u.get_path() == "/a%%b" + + # Trims whitespace + u = URLSpec(" http://example.com/ ") + assert u.get_url() == "http://example.com/" + + +def test_urlspec_parse_ipv6(): + u = URLSpec("http://[::1]:8080/path") + assert u.get_server() == "::1" + assert u.get_port() == 8080 + assert u.get_path() == "/path" + + u = URLSpec("http://[2001:db8::1]/") + assert u.get_server() == "2001:db8::1" + assert not u.has_port() + + u = URLSpec("http://[::1]:8080/") + assert u.get_server_and_port() == "[::1]:8080" + + # The implementation only appends ":port" when has_port() is true + # (i.e. the port was explicit in the URL), independent of IPv6 brackets. + u = URLSpec("http://[::1]/") + assert u.get_server_and_port() == "[::1]" + + u = URLSpec("http://[::1]:80/") + assert u.get_server_and_port() == "[::1]:80" + + +def test_urlspec_default_port_for_scheme(): + assert URLSpec.get_default_port_for_scheme("http") == 80 + assert URLSpec.get_default_port_for_scheme("https") == 443 + assert URLSpec.get_default_port_for_scheme("socks") == 1080 + # Empty falls back to http. + assert URLSpec.get_default_port_for_scheme("") == 80 + # Unknown scheme is 0. + assert URLSpec.get_default_port_for_scheme("gopher") == 0 + + assert URLSpec("http://example.com/").get_port() == 80 + assert URLSpec("https://example.com/").get_port() == 443 + assert URLSpec("socks://example.com/").get_port() == 1080 + + +def test_urlspec_is_default_port(): + assert URLSpec("http://example.com/").is_default_port() + assert URLSpec("http://example.com:80/").is_default_port() + assert not URLSpec("http://example.com:8080/").is_default_port() + assert URLSpec("https://example.com:443/").is_default_port() + + +def test_urlspec_is_ssl(): + assert not URLSpec("http://example.com/").is_ssl() + assert URLSpec("https://example.com/").is_ssl() + # The implementation treats any scheme ending in 's' as SSL, EXCEPT socks. + assert not URLSpec("socks://example.com/").is_ssl() + assert not URLSpec("ftp://example.com/").is_ssl() + # No scheme at all isn't SSL. + assert not URLSpec("//example.com/").is_ssl() + + +def test_urlspec_get_path_and_query(): + u = URLSpec("http://example.com") + assert not u.has_path() + assert u.get_path() == "/" + assert u.get_path_and_query() == "/" + + u = URLSpec("http://example.com/foo") + assert u.get_path_and_query() == "/foo" + + u = URLSpec("http://example.com?q=1") + assert u.get_path_and_query() == "/?q=1" + + u = URLSpec("http://example.com/foo?q=1") + assert u.get_path_and_query() == "/foo?q=1" + + +def test_urlspec_set_scheme(): + u = URLSpec("//example.com/foo") + u.set_scheme("http") + assert u.has_scheme() + assert u.get_scheme() == "http" + assert u.get_url() == "http://example.com/foo" + + # The setter is supposed to be tolerant of an appended ':' on the scheme. + u = URLSpec("//example.com/foo") + u.set_scheme("https:") + assert u.get_scheme() == "https" + assert u.get_url() == "https://example.com/foo" + + u = URLSpec("http://example.com/foo") + u.set_scheme("ftp") + assert u.get_scheme() == "ftp" + assert u.get_url() == "ftp://example.com/foo" + + # Lowercases + u = URLSpec("//example.com/foo") + u.set_scheme("HTTP") + assert u.get_scheme() == "http" + + +def test_urlspec_clear_scheme(): + u = URLSpec("http://example.com/foo") + u.set_scheme("") + assert not u.has_scheme() + # The "//example.com/foo" remainder is preserved. + assert u.get_url() == "//example.com/foo" + assert u.has_authority() + assert u.get_server() == "example.com" + + u = URLSpec("//example.com/foo") + u.set_scheme("") + assert u.get_url() == "//example.com/foo" + + +def test_urlspec_set_authority(): + # When inserting an authority and the existing URL has a path that doesn't + # start with '/', the setter must insert one. This branch is exercised + # primarily by the buffer-rebuild code path that replaced the old + # `s + auth + s` concatenation. + u = URLSpec("foo") + assert u.has_path() and not u.has_authority() + assert u.get_path() == "foo" + u.set_authority("example.com") + assert u.get_url() == "//example.com/foo" + assert u.get_server() == "example.com" + assert u.get_path() == "/foo" + + # Mirror of the above, but the path already starts with '/', so no extra + # slash must be inserted. + u = URLSpec("/foo") + assert u.has_path() and not u.has_authority() + u.set_authority("example.com") + assert u.get_url() == "//example.com/foo" + assert u.get_server() == "example.com" + assert u.get_path() == "/foo" + + u = URLSpec("http://old.example.com:1234/foo?q=1") + u.set_authority("new.example.com:5678") + assert u.get_url() == "http://new.example.com:5678/foo?q=1" + assert u.get_server() == "new.example.com" + assert u.get_port() == 5678 + assert u.get_path() == "/foo" + assert u.get_query() == "q=1" + + u = URLSpec("http://example.com/foo") + u.set_authority("user@example.com:8080") + assert u.has_username() + assert u.get_username() == "user" + assert u.get_server() == "example.com" + assert u.get_port() == 8080 + assert u.get_path() == "/foo" + + u = URLSpec("http://example.com/foo") + u.set_authority("") + assert not u.has_authority() + assert not u.has_server() + assert not u.has_port() + # The path is preserved. + assert u.has_path() + assert u.get_path() == "/foo" + + +def test_urlspec_set_username(): + u = URLSpec("http://old@example.com:8080/foo") + u.set_username("new") + assert u.get_username() == "new" + assert u.get_server() == "example.com" + assert u.get_port() == 8080 + assert u.get_path() == "/foo" + + u = URLSpec("http://example.com/foo") + u.set_username("user") + assert u.has_username() + assert u.get_username() == "user" + assert u.get_server() == "example.com" + + u = URLSpec("http://user@example.com/foo") + u.set_username("") + assert not u.has_username() + assert u.get_server() == "example.com" + + u = URLSpec("http://example.com:8080/foo") + u.set_server("other.example.com") + assert u.get_server() == "other.example.com" + assert u.get_port() == 8080 + assert u.get_path() == "/foo" + + +def test_urlspec_set_server(): + # set_server is allowed to accept a bare IPv6 address; it must add the + # square brackets back automatically when rebuilding the authority. + u = URLSpec("http://example.com:8080/foo") + u.set_server("::1") + assert u.get_server() == "::1" + assert u.get_port() == 8080 + assert "[::1]" in u.get_url() + + +def test_urlspec_set_port(): + # Accepts string + u = URLSpec("http://example.com/foo") + u.set_port("8443") + assert u.has_port() + assert u.get_port() == 8443 + assert u.get_url() == "http://example.com:8443/foo" + + # Accepts int + u = URLSpec("http://example.com/foo") + u.set_port(9999) + assert u.get_port() == 9999 + + # Empty removes port + u = URLSpec("http://example.com:1234/foo") + u.set_port("") + assert not u.has_port() + # The default for http kicks in. + assert u.get_port() == 80 + + +def test_urlspec_set_server_and_port(): + u = URLSpec("http://example.com/foo") + u.set_server_and_port("other:1234") + assert u.get_server() == "other" + assert u.get_port() == 1234 + + u = URLSpec("http://example.com/foo") + u.set_server_and_port("[::1]:1234") + assert u.get_server() == "::1" + assert u.get_port() == 1234 + + +def test_urlspec_set_path(): + u = URLSpec("http://example.com") + u.set_path("/foo") + assert u.has_path() + assert u.get_path() == "/foo" + assert u.get_url() == "http://example.com/foo" + + u = URLSpec("http://example.com") + u.set_path("foo") + assert u.get_path() == "/foo" + + u = URLSpec("http://example.com/old?q=1") + u.set_path("/new") + assert u.get_path() == "/new" + assert u.get_query() == "q=1" + assert u.get_url() == "http://example.com/new?q=1" + + u = URLSpec("http://example.com/old?q=1") + u.set_path("new") + assert u.get_path() == "/new" + assert u.get_url() == "http://example.com/new?q=1" + + u = URLSpec("http://example.com/foo") + u.set_path("") + assert not u.has_path() + + +def test_urlspec_set_query(): + u = URLSpec("http://example.com/foo") + u.set_query("q=1") + assert u.has_query() + assert u.get_query() == "q=1" + assert u.get_url() == "http://example.com/foo?q=1" + + u = URLSpec("http://example.com/foo?old=1") + u.set_query("new=2") + assert u.get_query() == "new=2" + assert u.get_url() == "http://example.com/foo?new=2" + + u = URLSpec("http://example.com/foo?q=1") + u.set_query("") + assert not u.has_query() + assert u.get_url() == "http://example.com/foo" + + +def test_urlspec_set_url(): + u = URLSpec("http://old.example.com/foo") + u.set_url("https://new.example.com:8443/bar?baz=1") + assert u.get_scheme() == "https" + assert u.get_server() == "new.example.com" + assert u.get_port() == 8443 + assert u.get_path() == "/bar" + assert u.get_query() == "baz=1" + + u = URLSpec("http://example.com/foo") + u.set_url("") + assert u.empty() + assert not u.has_scheme() + assert not u.has_authority() + assert not u.has_path() + + u = URLSpec() + u.set_url("example.com:1234", True) + assert u.has_server() + assert u.get_server() == "example.com" + assert u.get_port() == 1234 + + +def test_urlspec_quote(): + assert URLSpec.quote("abcXYZ0189_,.-") == "abcXYZ0189_,.-" + + # By default '/' is in the safe set; space is not. + assert URLSpec.quote("a b") == "a%20b" + + assert URLSpec.quote("a/b") == "a/b" + + # With an empty safe set, '/' is escaped. + assert URLSpec.quote("a/b", "") == "a%2fb" + + +def test_urlspec_quote_plus(): + assert URLSpec.quote_plus("a b") == "a+b" + + # '&' is not safe so it's escaped, while space becomes '+'. + assert URLSpec.quote_plus("a&b c", "") == "a%26b+c" + + +def test_urlspec_unquote(): + assert URLSpec.unquote("a%20b") == "a b" + # Case-insensitive hex. + assert URLSpec.unquote("a%2Fb") == "a/b" + assert URLSpec.unquote("a%2fb") == "a/b" + + assert URLSpec.unquote("hello") == "hello" + + raw = "Hello, World! 100% / safe?" + assert URLSpec.unquote(URLSpec.quote(raw, "")) == raw + + +def test_urlspec_unquote_plus(): + assert URLSpec.unquote_plus("a+b") == "a b" + assert URLSpec.unquote_plus("a%2Bb") == "a+b" + + raw = "key=value&other=thing with spaces" + assert URLSpec.unquote_plus(URLSpec.quote_plus(raw, "")) == raw + + +def test_urlspec_equality(): + a = URLSpec("http://example.com/foo") + b = URLSpec("http://example.com/foo") + assert a == b + assert not (a != b) + + a = URLSpec("http://example.com/foo") + b = URLSpec("http://example.com/bar") + assert a != b + + # compare_to does cmp_nocase on the scheme. + a = URLSpec("http://example.com/") + b = URLSpec("HTTP://example.com/") + assert a == b + + a = URLSpec("http://example.com/") + b = URLSpec("http://EXAMPLE.com/") + assert a == b + + +def test_urlspec_ordering(): + a = URLSpec("ftp://example.com/") + b = URLSpec("http://example.com/") + assert a < b + assert not (b < a) + + +def test_urlspec_hash(): + a = URLSpec("http://example.com/") + b = URLSpec("HTTP://Example.COM/") + # Equality already covers this, but the hash must match equal-objects too. + assert a.get_hash() == b.get_hash() + + +def test_urlspec_indexing(): + u = URLSpec("http://example.com/") + assert u[0] == "h" + assert u[4] == ":" diff --git a/tests/dtoolutil/test_filename.py b/tests/dtoolutil/test_filename.py index 13692e0784c..c251ede5524 100644 --- a/tests/dtoolutil/test_filename.py +++ b/tests/dtoolutil/test_filename.py @@ -13,6 +13,20 @@ def test_filename_open(): open(fn, 'rb') +def test_filename_set_extension(): + fn = Filename('test.txt') + fn.set_extension('abc') + assert fn.get_fullpath() == 'test.abc' + + fn = Filename('test.a.b') + fn.set_extension('c') + assert fn.get_fullpath() == 'test.a.c' + + fn = Filename('test') + fn.set_extension('ext') + assert fn.get_fullpath() == 'test.ext' + + def test_filename_ctor_pathlib(): pathlib = pytest.importorskip('pathlib')