style fix - initializing and assigning empty std::string properly

std::string s(""); s = ""; calls the copy constructor, which in turn calls strlen(), … assigning a default-constructed string generates fewer instructions and is therefore preferred.

With C++11 uniform initialization, you’d simply write s = { } instead.
pull/4101/head
Krishty 2021-04-16 23:43:56 +02:00
parent cd42b9954b
commit f761dc72f4
34 changed files with 48 additions and 48 deletions

View File

@ -212,7 +212,7 @@ void Discreet3DSImporter::ConvertMaterial(D3DS::Material &oldMat,
mat.AddProperty(&tex, AI_MATKEY_GLOBAL_BACKGROUND_IMAGE); mat.AddProperty(&tex, AI_MATKEY_GLOBAL_BACKGROUND_IMAGE);
// Be sure this is only done for the first material // Be sure this is only done for the first material
mBackgroundImage = std::string(""); mBackgroundImage = std::string();
} }
// At first add the base ambient color of the scene to the material // At first add the base ambient color of the scene to the material

View File

@ -164,7 +164,7 @@ void Discreet3DSImporter::InternReadFile(const std::string &pFile,
mRootNode->mHierarchyIndex = -1; mRootNode->mHierarchyIndex = -1;
mRootNode->mParent = nullptr; mRootNode->mParent = nullptr;
mMasterScale = 1.0f; mMasterScale = 1.0f;
mBackgroundImage = ""; mBackgroundImage = std::string();
bHasBG = false; bHasBG = false;
bIsPrj = false; bIsPrj = false;

View File

@ -188,7 +188,7 @@ bool D3MFOpcPackage::validate() {
std::string D3MFOpcPackage::ReadPackageRootRelationship(IOStream *stream) { std::string D3MFOpcPackage::ReadPackageRootRelationship(IOStream *stream) {
XmlParser xmlParser; XmlParser xmlParser;
if (!xmlParser.parse(stream)) { if (!xmlParser.parse(stream)) {
return ""; return std::string();
} }
OpcPackageRelationshipReader reader(xmlParser); OpcPackageRelationshipReader reader(xmlParser);

View File

@ -123,9 +123,9 @@ public:
struct Object { struct Object {
Object() : Object() :
type(World), type(World),
name(""), name(),
children(), children(),
texture(""), texture(),
texRepeat(1.f, 1.f), texRepeat(1.f, 1.f),
texOffset(0.0f, 0.0f), texOffset(0.0f, 0.0f),
rotation(), rotation(),

View File

@ -685,7 +685,7 @@ void Parser::ParseLV3MapBlock(Texture &map) {
// Files with 'None' as map name are produced by // Files with 'None' as map name are produced by
// an Maja to ASE exporter which name I forgot .. // an Maja to ASE exporter which name I forgot ..
ASSIMP_LOG_WARN("ASE: Skipping invalid map entry"); ASSIMP_LOG_WARN("ASE: Skipping invalid map entry");
map.mMapName = ""; map.mMapName = std::string();
} }
continue; continue;

View File

@ -1241,7 +1241,7 @@ void ColladaLoader::CreateAnimation(aiScene *pScene, const ColladaParser &pParse
continue; continue;
} }
entry.mTargetId = entry.mTransformId; entry.mTargetId = entry.mTransformId;
entry.mTransformId = ""; entry.mTransformId = std::string();
} }
entry.mChannel = &(*cit); entry.mChannel = &(*cit);

View File

@ -330,7 +330,7 @@ void MeshGeometry::ReadVertexData(const std::string& type, int index, const Scop
} }
const Element* Name = source["Name"]; const Element* Name = source["Name"];
m_uvNames[index] = ""; m_uvNames[index] = std::string();
if(Name) { if(Name) {
m_uvNames[index] = ParseTokenAsString(GetRequiredToken(*Name,0)); m_uvNames[index] = ParseTokenAsString(GetRequiredToken(*Name,0));
} }

View File

@ -462,7 +462,7 @@ std::string ParseTokenAsString(const Token& t, const char*& err_out)
if (t.Type() != TokenType_DATA) { if (t.Type() != TokenType_DATA) {
err_out = "expected TOK_DATA token"; err_out = "expected TOK_DATA token";
return ""; return std::string();
} }
if(t.IsBinary()) if(t.IsBinary())
@ -470,7 +470,7 @@ std::string ParseTokenAsString(const Token& t, const char*& err_out)
const char* data = t.begin(); const char* data = t.begin();
if (data[0] != 'S') { if (data[0] != 'S') {
err_out = "failed to parse S(tring), unexpected data type (binary)"; err_out = "failed to parse S(tring), unexpected data type (binary)";
return ""; return std::string();
} }
// read string length // read string length
@ -484,13 +484,13 @@ std::string ParseTokenAsString(const Token& t, const char*& err_out)
const size_t length = static_cast<size_t>(t.end() - t.begin()); const size_t length = static_cast<size_t>(t.end() - t.begin());
if(length < 2) { if(length < 2) {
err_out = "token is too short to hold a string"; err_out = "token is too short to hold a string";
return ""; return std::string();
} }
const char* s = t.begin(), *e = t.end() - 1; const char* s = t.begin(), *e = t.end() - 1;
if (*s != '\"' || *e != '\"') { if (*s != '\"' || *e != '\"') {
err_out = "expected double quoted string"; err_out = "expected double quoted string";
return ""; return std::string();
} }
return std::string(s+1,length-2); return std::string(s+1,length-2);

View File

@ -155,7 +155,7 @@ std::string PeekPropertyName(const Element& element)
ai_assert(element.KeyToken().StringContents() == "P"); ai_assert(element.KeyToken().StringContents() == "P");
const TokenList& tok = element.Tokens(); const TokenList& tok = element.Tokens();
if(tok.size() < 4) { if(tok.size() < 4) {
return ""; return std::string();
} }
return ParseTokenAsString(*tok[0]); return ParseTokenAsString(*tok[0]);

View File

@ -567,7 +567,7 @@ typedef std::map<std::string, std::string> Metadata;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void ProcessMetadata(const Schema_2x3::ListOf<Schema_2x3::Lazy<Schema_2x3::IfcProperty>, 1, 0> &set, ConversionData &conv, Metadata &properties, void ProcessMetadata(const Schema_2x3::ListOf<Schema_2x3::Lazy<Schema_2x3::IfcProperty>, 1, 0> &set, ConversionData &conv, Metadata &properties,
const std::string &prefix = "", const std::string &prefix = std::string(),
unsigned int nest = 0) { unsigned int nest = 0) {
for (const Schema_2x3::IfcProperty &property : set) { for (const Schema_2x3::IfcProperty &property : set) {
const std::string &key = prefix.length() > 0 ? (prefix + "." + property.Name) : property.Name; const std::string &key = prefix.length() > 0 ? (prefix + "." + property.Name) : property.Name;
@ -618,7 +618,7 @@ void ProcessMetadata(const Schema_2x3::ListOf<Schema_2x3::Lazy<Schema_2x3::IfcPr
ProcessMetadata(complexProp->HasProperties, conv, properties, key, nest + 1); ProcessMetadata(complexProp->HasProperties, conv, properties, key, nest + 1);
} }
} else { } else {
properties[key] = ""; properties[key] = std::string();
} }
} }
} }

View File

@ -859,7 +859,7 @@ void IRRImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
// Check whether we can read from the file // Check whether we can read from the file
if (file.get() == nullptr) { if (file.get() == nullptr) {
throw DeadlyImportError("Failed to open IRR file " + pFile + ""); throw DeadlyImportError("Failed to open IRR file " + pFile);
} }
// Construct the irrXML parser // Construct the irrXML parser

View File

@ -135,7 +135,7 @@ void IRRMeshImporter::InternReadFile(const std::string &pFile,
// Check whether we can read from the file // Check whether we can read from the file
if (file.get() == NULL) if (file.get() == NULL)
throw DeadlyImportError("Failed to open IRRMESH file " + pFile + ""); throw DeadlyImportError("Failed to open IRRMESH file " + pFile);
// Construct the irrXML parser // Construct the irrXML parser
XmlParser parser; XmlParser parser;

View File

@ -502,7 +502,7 @@ struct Surface {
Surface() : Surface() :
mColor(0.78431f, 0.78431f, 0.78431f), bDoubleSided(false), mDiffuseValue(1.f), mSpecularValue(0.f), mTransparency(0.f), mGlossiness(0.4f), mLuminosity(0.f), mColorHighlights(0.f), mMaximumSmoothAngle(0.f) // 0 == not specified, no smoothing mColor(0.78431f, 0.78431f, 0.78431f), bDoubleSided(false), mDiffuseValue(1.f), mSpecularValue(0.f), mTransparency(0.f), mGlossiness(0.4f), mLuminosity(0.f), mColorHighlights(0.f), mMaximumSmoothAngle(0.f) // 0 == not specified, no smoothing
, ,
mVCMap(""), mVCMap(),
mVCMapType(AI_LWO_RGBA), mVCMapType(AI_LWO_RGBA),
mIOR(1.f) // vakuum mIOR(1.f) // vakuum
, ,

View File

@ -88,7 +88,7 @@ struct NodeDesc {
id(), id(),
number(0), number(0),
parent(0), parent(0),
name(""), name(),
isPivotSet(false), isPivotSet(false),
lightColor(1.f, 1.f, 1.f), lightColor(1.f, 1.f, 1.f),
lightIntensity(1.f), lightIntensity(1.f),

View File

@ -95,7 +95,7 @@ void UniqueNameGenerator::make_unique(std::vector<std::string> &names) {
auto generate_unique_name = [&](const std::string &base_name) -> std::string { auto generate_unique_name = [&](const std::string &base_name) -> std::string {
auto *duplicate_info = &names_to_duplicates[base_name]; auto *duplicate_info = &names_to_duplicates[base_name];
std::string new_name = ""; std::string new_name;
bool found_identical_name; bool found_identical_name;
bool tried_with_base_name_only = false; bool tried_with_base_name_only = false;

View File

@ -75,7 +75,7 @@ using namespace std;
// Default constructor // Default constructor
MMDImporter::MMDImporter() : MMDImporter::MMDImporter() :
m_Buffer(), m_Buffer(),
m_strAbsPath("") { m_strAbsPath() {
DefaultIOSystem io; DefaultIOSystem io;
m_strAbsPath = io.getOsSeparator(); m_strAbsPath = io.getOsSeparator();
} }

View File

@ -91,7 +91,7 @@ namespace pmx
std::vector<char> buffer; std::vector<char> buffer;
if (size == 0) if (size == 0)
{ {
return std::string(""); return std::string();
} }
buffer.reserve(size); buffer.reserve(size);
stream->read((char*) buffer.data(), size); stream->read((char*) buffer.data(), size);

View File

@ -206,7 +206,7 @@ USE_ODDLPARSER_NS
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
static void propId2StdString(Property *prop, std::string &name, std::string &key) { static void propId2StdString(Property *prop, std::string &name, std::string &key) {
name = key = ""; name = key = std::string();
if (nullptr == prop) { if (nullptr == prop) {
return; return;
} }

View File

@ -79,7 +79,7 @@ struct MetricInfo {
int m_intValue; int m_intValue;
MetricInfo() MetricInfo()
: m_stringValue( "" ) : m_stringValue( )
, m_floatValue( 0.0f ) , m_floatValue( 0.0f )
, m_intValue( -1 ) { , m_intValue( -1 ) {
// empty // empty

View File

@ -178,7 +178,7 @@ struct Q3BSPModel {
m_Textures(), m_Textures(),
m_Lightmaps(), m_Lightmaps(),
m_EntityData(), m_EntityData(),
m_ModelName( "" ) m_ModelName()
{ {
// empty // empty
} }

View File

@ -113,7 +113,7 @@ static void extractIds(const std::string &key, int &id1, int &id2) {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Local helper function to normalize filenames. // Local helper function to normalize filenames.
static void normalizePathName(const std::string &rPath, std::string &normalizedPath) { static void normalizePathName(const std::string &rPath, std::string &normalizedPath) {
normalizedPath = ""; normalizedPath = std::string();
if (rPath.empty()) { if (rPath.empty()) {
return; return;
} }
@ -183,7 +183,7 @@ void Q3BSPFileImporter::InternReadFile(const std::string &rFile, aiScene *scene,
throw DeadlyImportError("Failed to open file ", rFile, "."); throw DeadlyImportError("Failed to open file ", rFile, ".");
} }
std::string archiveName(""), mapName(""); std::string archiveName, mapName;
separateMapName(rFile, archiveName, mapName); separateMapName(rFile, archiveName, mapName);
if (mapName.empty()) { if (mapName.empty()) {
@ -202,8 +202,8 @@ void Q3BSPFileImporter::InternReadFile(const std::string &rFile, aiScene *scene,
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Separates the map name from the import name. // Separates the map name from the import name.
void Q3BSPFileImporter::separateMapName(const std::string &importName, std::string &archiveName, std::string &mapName) { void Q3BSPFileImporter::separateMapName(const std::string &importName, std::string &archiveName, std::string &mapName) {
archiveName = ""; archiveName = std::string();
mapName = ""; mapName = std::string();
if (importName.empty()) { if (importName.empty()) {
return; return;
} }
@ -221,7 +221,7 @@ void Q3BSPFileImporter::separateMapName(const std::string &importName, std::stri
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Returns the first map in the map archive. // Returns the first map in the map archive.
bool Q3BSPFileImporter::findFirstMapInArchive(ZipArchiveIOSystem &bspArchive, std::string &mapName) { bool Q3BSPFileImporter::findFirstMapInArchive(ZipArchiveIOSystem &bspArchive, std::string &mapName) {
mapName = ""; mapName = std::string();
std::vector<std::string> fileList; std::vector<std::string> fileList;
bspArchive.getFileListExtension(fileList, "bsp"); bspArchive.getFileListExtension(fileList, "bsp");
if (fileList.empty()) { if (fileList.empty()) {
@ -440,7 +440,7 @@ void Q3BSPFileImporter::createMaterials(const Q3BSP::Q3BSPModel *pModel, aiScene
if (-1 != textureId) { if (-1 != textureId) {
sQ3BSPTexture *pTexture = pModel->m_Textures[textureId]; sQ3BSPTexture *pTexture = pModel->m_Textures[textureId];
if (nullptr != pTexture) { if (nullptr != pTexture) {
std::string tmp("*"), texName(""); std::string tmp("*"), texName;
tmp += pTexture->strName; tmp += pTexture->strName;
tmp += ".jpg"; tmp += ".jpg";
normalizePathName(tmp, texName); normalizePathName(tmp, texName);
@ -512,7 +512,7 @@ size_t Q3BSPFileImporter::countTriangles(const std::vector<Q3BSP::sQ3BSPFace *>
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Creates the faces-to-material map. // Creates the faces-to-material map.
void Q3BSPFileImporter::createMaterialMap(const Q3BSP::Q3BSPModel *pModel) { void Q3BSPFileImporter::createMaterialMap(const Q3BSP::Q3BSPModel *pModel) {
std::string key(""); std::string key;
std::vector<sQ3BSPFace *> *pCurFaceArray = nullptr; std::vector<sQ3BSPFace *> *pCurFaceArray = nullptr;
for (size_t idx = 0; idx < pModel->m_Faces.size(); idx++) { for (size_t idx = 0; idx < pModel->m_Faces.size(); idx++) {
Q3BSP::sQ3BSPFace *pQ3BSPFace = pModel->m_Faces[idx]; Q3BSP::sQ3BSPFace *pQ3BSPFace = pModel->m_Faces[idx];
@ -660,7 +660,7 @@ bool Q3BSPFileImporter::expandFile(ZipArchiveIOSystem *pArchive, const std::stri
if (rExtList.empty()) { if (rExtList.empty()) {
rFile = rFilename; rFile = rFilename;
rExt = ""; rExt = std::string();
return true; return true;
} }

View File

@ -130,7 +130,7 @@ struct Mesh {
std::vector<Bone> mBones; std::vector<Bone> mBones;
explicit Mesh(const std::string &pName = "") AI_NO_EXCEPT explicit Mesh(const std::string &pName = std::string()) AI_NO_EXCEPT
: mName( pName ) : mName( pName )
, mPositions() , mPositions()
, mPosFaces() , mPosFaces()

View File

@ -142,7 +142,7 @@ void XGLImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
// check whether we can read from the file // check whether we can read from the file
if (stream.get() == NULL) { if (stream.get() == NULL) {
throw DeadlyImportError("Failed to open XGL/ZGL file " + pFile + ""); throw DeadlyImportError("Failed to open XGL/ZGL file " + pFile);
} }
// see if its compressed, if so uncompress it // see if its compressed, if so uncompress it

View File

@ -1029,7 +1029,7 @@ namespace glTF
AssetMetadata() AssetMetadata()
: premultipliedAlpha(false) : premultipliedAlpha(false)
, version("") , version()
{ {
} }
}; };

View File

@ -1067,7 +1067,7 @@ struct AssetMetadata {
void Read(Document &doc); void Read(Document &doc);
AssetMetadata() : AssetMetadata() :
version("") {} version() {}
}; };
// //

View File

@ -271,7 +271,7 @@ std::string BaseImporter::GetExtension(const std::string &file) {
// no file extension at all // no file extension at all
if (pos == std::string::npos) { if (pos == std::string::npos) {
return ""; return std::string();
} }
// thanks to Andy Maloney for the hint // thanks to Andy Maloney for the hint

View File

@ -76,7 +76,7 @@ public:
if (std::string::npos != (ss2 = mBase.find_last_of("\\/"))) { if (std::string::npos != (ss2 = mBase.find_last_of("\\/"))) {
mBase.erase(ss2,mBase.length()-ss2); mBase.erase(ss2,mBase.length()-ss2);
} else { } else {
mBase = ""; mBase = std::string();
} }
// make sure the directory is terminated properly // make sure the directory is terminated properly

View File

@ -149,7 +149,7 @@ void AllocateFromAssimpHeap::operator delete[] ( void* data) {
Importer::Importer() Importer::Importer()
: pimpl( new ImporterPimpl ) { : pimpl( new ImporterPimpl ) {
pimpl->mScene = nullptr; pimpl->mScene = nullptr;
pimpl->mErrorString = ""; pimpl->mErrorString = std::string();
// Allocate a default IO handler // Allocate a default IO handler
pimpl->mIOHandler = new DefaultIOSystem; pimpl->mIOHandler = new DefaultIOSystem;
@ -387,7 +387,7 @@ void Importer::FreeScene( ) {
delete pimpl->mScene; delete pimpl->mScene;
pimpl->mScene = nullptr; pimpl->mScene = nullptr;
pimpl->mErrorString = ""; pimpl->mErrorString = std::string();
pimpl->mException = std::exception_ptr(); pimpl->mException = std::exception_ptr();
ASSIMP_END_EXCEPTION_REGION(void); ASSIMP_END_EXCEPTION_REGION(void);
} }
@ -434,7 +434,7 @@ aiScene* Importer::GetOrphanedScene() {
ASSIMP_BEGIN_EXCEPTION_REGION(); ASSIMP_BEGIN_EXCEPTION_REGION();
pimpl->mScene = nullptr; pimpl->mScene = nullptr;
pimpl->mErrorString = ""; // reset error string pimpl->mErrorString = std::string();
pimpl->mException = std::exception_ptr(); pimpl->mException = std::exception_ptr();
ASSIMP_END_EXCEPTION_REGION(aiScene*); ASSIMP_END_EXCEPTION_REGION(aiScene*);

View File

@ -43,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/scene.h> #include <assimp/scene.h>
aiNode::aiNode() aiNode::aiNode()
: mName("") : mName()
, mParent(nullptr) , mParent(nullptr)
, mNumChildren(0) , mNumChildren(0)
, mChildren(nullptr) , mChildren(nullptr)

View File

@ -81,7 +81,7 @@ public:
/** @brief Set list of fixed (inmutable) materials /** @brief Set list of fixed (inmutable) materials
* @param fixed See #AI_CONFIG_PP_RRM_EXCLUDE_LIST * @param fixed See #AI_CONFIG_PP_RRM_EXCLUDE_LIST
*/ */
void SetFixedMaterialsString(const std::string& fixed = "") { void SetFixedMaterialsString(const std::string& fixed = std::string()) {
mConfigFixedMaterials = fixed; mConfigFixedMaterials = fixed;
} }

View File

@ -119,7 +119,7 @@ private:
AI_FORCE_INLINE AI_FORCE_INLINE
DefaultIOStream::DefaultIOStream() AI_NO_EXCEPT DefaultIOStream::DefaultIOStream() AI_NO_EXCEPT
: mFile(nullptr) : mFile(nullptr)
, mFilename("") , mFilename()
, mCachedSize(SIZE_MAX) { , mCachedSize(SIZE_MAX) {
// empty // empty
} }

View File

@ -294,7 +294,7 @@ bool IOSystem::PushDirectory( const std::string &path ) {
AI_FORCE_INLINE AI_FORCE_INLINE
const std::string &IOSystem::CurrentDirectory() const { const std::string &IOSystem::CurrentDirectory() const {
if ( m_pathStack.empty() ) { if ( m_pathStack.empty() ) {
static const std::string Dummy(""); static const std::string Dummy;
return Dummy; return Dummy;
} }
return m_pathStack[ m_pathStack.size()-1 ]; return m_pathStack[ m_pathStack.size()-1 ];

View File

@ -286,7 +286,7 @@ public:
* @see GetPropertyInteger() * @see GetPropertyInteger()
*/ */
std::string GetPropertyString(const char *szName, std::string GetPropertyString(const char *szName,
const std::string &sErrorReturn = "") const; const std::string &sErrorReturn = std::string()) const;
// ------------------------------------------------------------------- // -------------------------------------------------------------------
/** Get a matrix configuration property /** Get a matrix configuration property

View File

@ -239,7 +239,7 @@ public:
} }
static inline bool getValueAsString( XmlNode &node, std::string &text ) { static inline bool getValueAsString( XmlNode &node, std::string &text ) {
text = ""; text = std::string();
if (node.empty()) { if (node.empty()) {
return false; return false;
} }