From 12396d0ce3786f7cc9f1289a674a37c7f0158a5d Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 30 Jan 2018 19:42:58 +0200 Subject: [PATCH 1/4] Ogre: Change OgreXmlSerializer::HasAttribute parameter from std::string to pointer It's immediately passed via string pointer and in most places it's already a raw string constant. --- code/OgreXmlSerializer.cpp | 16 ++++++++-------- code/OgreXmlSerializer.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/code/OgreXmlSerializer.cpp b/code/OgreXmlSerializer.cpp index a7e6b5a09..bcfe2d185 100644 --- a/code/OgreXmlSerializer.cpp +++ b/code/OgreXmlSerializer.cpp @@ -171,9 +171,9 @@ bool OgreXmlSerializer::ReadAttribute(const std::string &name) const } } -bool OgreXmlSerializer::HasAttribute(const std::string &name) const +bool OgreXmlSerializer::HasAttribute(const char *name) const { - return (m_reader->getAttributeValue(name.c_str()) != 0); + return (m_reader->getAttributeValue(name) != 0); } std::string &OgreXmlSerializer::NextNode() @@ -548,10 +548,10 @@ void OgreXmlSerializer::ReadSubMesh(MeshXml *mesh) SubMeshXml* submesh = new SubMeshXml(); - if (HasAttribute(anMaterial)) { + if (HasAttribute(anMaterial.c_str())) { submesh->materialRef = ReadAttribute(anMaterial); } - if (HasAttribute(anUseSharedVertices)) { + if (HasAttribute(anUseSharedVertices.c_str())) { submesh->usesSharedVertexData = ReadAttribute(anUseSharedVertices); } @@ -587,7 +587,7 @@ void OgreXmlSerializer::ReadSubMesh(MeshXml *mesh) face.mIndices[2] = ReadAttribute(anV3); /// @todo Support quads if Ogre even supports them in XML (I'm not sure but I doubt it) - if (!quadWarned && HasAttribute(anV4)) { + if (!quadWarned && HasAttribute(anV4.c_str())) { DefaultLogger::get()->warn("Submesh has quads with , only triangles are supported at the moment!"); quadWarned = true; } @@ -968,11 +968,11 @@ void OgreXmlSerializer::ReadBones(Skeleton *skeleton) } else { - if (HasAttribute(anX)) + if (HasAttribute(anX.c_str())) bone->scale.x = ReadAttribute(anX); - if (HasAttribute(anY)) + if (HasAttribute(anY.c_str())) bone->scale.y = ReadAttribute(anY); - if (HasAttribute(anZ)) + if (HasAttribute(anZ.c_str())) bone->scale.z = ReadAttribute(anZ); } } diff --git a/code/OgreXmlSerializer.h b/code/OgreXmlSerializer.h index 1ad46f95f..487bb65fa 100644 --- a/code/OgreXmlSerializer.h +++ b/code/OgreXmlSerializer.h @@ -99,7 +99,7 @@ private: template T ReadAttribute(const std::string &name) const; - bool HasAttribute(const std::string &name) const; + bool HasAttribute(const char *name) const; std::string &NextNode(); std::string &SkipCurrentNode(); From 0c66b3902eaf165daf92ab29dd408deb2240356a Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 30 Jan 2018 19:47:15 +0200 Subject: [PATCH 2/4] Ogre: Avoid creating static std::strings They're causing false positive race condition messages from Helgrind --- code/OgreXmlSerializer.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/code/OgreXmlSerializer.cpp b/code/OgreXmlSerializer.cpp index bcfe2d185..bf2680dcb 100644 --- a/code/OgreXmlSerializer.cpp +++ b/code/OgreXmlSerializer.cpp @@ -538,20 +538,20 @@ void OgreXmlSerializer::ReadGeometryVertexBuffer(VertexDataXml *dest) void OgreXmlSerializer::ReadSubMesh(MeshXml *mesh) { - static const std::string anMaterial = "material"; - static const std::string anUseSharedVertices = "usesharedvertices"; - static const std::string anCount = "count"; - static const std::string anV1 = "v1"; - static const std::string anV2 = "v2"; - static const std::string anV3 = "v3"; - static const std::string anV4 = "v4"; + static const char *anMaterial = "material"; + static const char *anUseSharedVertices = "usesharedvertices"; + static const char *anCount = "count"; + static const char *anV1 = "v1"; + static const char *anV2 = "v2"; + static const char *anV3 = "v3"; + static const char *anV4 = "v4"; SubMeshXml* submesh = new SubMeshXml(); - if (HasAttribute(anMaterial.c_str())) { + if (HasAttribute(anMaterial)) { submesh->materialRef = ReadAttribute(anMaterial); } - if (HasAttribute(anUseSharedVertices.c_str())) { + if (HasAttribute(anUseSharedVertices)) { submesh->usesSharedVertexData = ReadAttribute(anUseSharedVertices); } @@ -587,7 +587,7 @@ void OgreXmlSerializer::ReadSubMesh(MeshXml *mesh) face.mIndices[2] = ReadAttribute(anV3); /// @todo Support quads if Ogre even supports them in XML (I'm not sure but I doubt it) - if (!quadWarned && HasAttribute(anV4.c_str())) { + if (!quadWarned && HasAttribute(anV4)) { DefaultLogger::get()->warn("Submesh has quads with , only triangles are supported at the moment!"); quadWarned = true; } @@ -635,9 +635,9 @@ void OgreXmlSerializer::ReadBoneAssignments(VertexDataXml *dest) throw DeadlyImportError("Cannot read bone assignments, vertex data is null."); } - static const std::string anVertexIndex = "vertexindex"; - static const std::string anBoneIndex = "boneindex"; - static const std::string anWeight = "weight"; + static const char *anVertexIndex = "vertexindex"; + static const char *anBoneIndex = "boneindex"; + static const char *anWeight = "weight"; std::set influencedVertices; From cfc9a695121056c85a530bf8dc5b6b04e4fdf9ef Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 30 Jan 2018 20:03:28 +0200 Subject: [PATCH 3/4] Ogre: Don't create std::strings in global scope where char pointer will do --- code/OgreXmlSerializer.cpp | 94 +++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/code/OgreXmlSerializer.cpp b/code/OgreXmlSerializer.cpp index bf2680dcb..51a7c293b 100644 --- a/code/OgreXmlSerializer.cpp +++ b/code/OgreXmlSerializer.cpp @@ -231,75 +231,75 @@ std::string &OgreXmlSerializer::SkipCurrentNode() // Mesh XML constants // -const std::string nnMesh = "mesh"; -const std::string nnSharedGeometry = "sharedgeometry"; -const std::string nnSubMeshes = "submeshes"; -const std::string nnSubMesh = "submesh"; -const std::string nnSubMeshNames = "submeshnames"; -const std::string nnSkeletonLink = "skeletonlink"; -const std::string nnLOD = "levelofdetail"; -const std::string nnExtremes = "extremes"; -const std::string nnPoses = "poses"; -const std::string nnAnimations = "animations"; +const char *nnMesh = "mesh"; +const char *nnSharedGeometry = "sharedgeometry"; +const char *nnSubMeshes = "submeshes"; +const char *nnSubMesh = "submesh"; +const char *nnSubMeshNames = "submeshnames"; +const char *nnSkeletonLink = "skeletonlink"; +const char *nnLOD = "levelofdetail"; +const char *nnExtremes = "extremes"; +const char *nnPoses = "poses"; +const char *nnAnimations = "animations"; // -const std::string nnFaces = "faces"; -const std::string nnFace = "face"; -const std::string nnGeometry = "geometry"; -const std::string nnTextures = "textures"; +const char *nnFaces = "faces"; +const char *nnFace = "face"; +const char *nnGeometry = "geometry"; +const char *nnTextures = "textures"; // -const std::string nnBoneAssignments = "boneassignments"; +const char *nnBoneAssignments = "boneassignments"; // -const std::string nnVertexBuffer = "vertexbuffer"; +const char *nnVertexBuffer = "vertexbuffer"; // -const std::string nnVertex = "vertex"; -const std::string nnPosition = "position"; -const std::string nnNormal = "normal"; -const std::string nnTangent = "tangent"; -const std::string nnBinormal = "binormal"; -const std::string nnTexCoord = "texcoord"; -const std::string nnColorDiffuse = "colour_diffuse"; -const std::string nnColorSpecular = "colour_specular"; +const char *nnVertex = "vertex"; +const char *nnPosition = "position"; +const char *nnNormal = "normal"; +const char *nnTangent = "tangent"; +const char *nnBinormal = "binormal"; +const char *nnTexCoord = "texcoord"; +const char *nnColorDiffuse = "colour_diffuse"; +const char *nnColorSpecular = "colour_specular"; // -const std::string nnVertexBoneAssignment = "vertexboneassignment"; +const char *nnVertexBoneAssignment = "vertexboneassignment"; // Skeleton XML constants // -const std::string nnSkeleton = "skeleton"; -const std::string nnBones = "bones"; -const std::string nnBoneHierarchy = "bonehierarchy"; -const std::string nnAnimationLinks = "animationlinks"; +const char *nnSkeleton = "skeleton"; +const char *nnBones = "bones"; +const char *nnBoneHierarchy = "bonehierarchy"; +const char *nnAnimationLinks = "animationlinks"; // -const std::string nnBone = "bone"; -const std::string nnRotation = "rotation"; -const std::string nnAxis = "axis"; -const std::string nnScale = "scale"; +const char *nnBone = "bone"; +const char *nnRotation = "rotation"; +const char *nnAxis = "axis"; +const char *nnScale = "scale"; // -const std::string nnBoneParent = "boneparent"; +const char *nnBoneParent = "boneparent"; // -const std::string nnAnimation = "animation"; -const std::string nnTracks = "tracks"; +const char *nnAnimation = "animation"; +const char *nnTracks = "tracks"; // -const std::string nnTrack = "track"; -const std::string nnKeyFrames = "keyframes"; -const std::string nnKeyFrame = "keyframe"; -const std::string nnTranslate = "translate"; -const std::string nnRotate = "rotate"; +const char *nnTrack = "track"; +const char *nnKeyFrames = "keyframes"; +const char *nnKeyFrame = "keyframe"; +const char *nnTranslate = "translate"; +const char *nnRotate = "rotate"; // Common XML constants -const std::string anX = "x"; -const std::string anY = "y"; -const std::string anZ = "z"; +const char *anX = "x"; +const char *anY = "y"; +const char *anZ = "z"; // Mesh @@ -968,11 +968,11 @@ void OgreXmlSerializer::ReadBones(Skeleton *skeleton) } else { - if (HasAttribute(anX.c_str())) + if (HasAttribute(anX)) bone->scale.x = ReadAttribute(anX); - if (HasAttribute(anY.c_str())) + if (HasAttribute(anY)) bone->scale.y = ReadAttribute(anY); - if (HasAttribute(anZ.c_str())) + if (HasAttribute(anZ)) bone->scale.z = ReadAttribute(anZ); } } From 388ec8461caba97f06546b281e408a73c08097a5 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Tue, 30 Jan 2018 20:12:46 +0200 Subject: [PATCH 4/4] Ogre: Change OgreXmlSerializer::ReadAttribute parameter from std::string to pointer --- code/OgreXmlSerializer.cpp | 26 +++++++++++++------------- code/OgreXmlSerializer.h | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/code/OgreXmlSerializer.cpp b/code/OgreXmlSerializer.cpp index 51a7c293b..51b3a5607 100644 --- a/code/OgreXmlSerializer.cpp +++ b/code/OgreXmlSerializer.cpp @@ -72,11 +72,11 @@ AI_WONT_RETURN void ThrowAttibuteError(const XmlReader* reader, const std::strin } template<> -int32_t OgreXmlSerializer::ReadAttribute(const std::string &name) const +int32_t OgreXmlSerializer::ReadAttribute(const char *name) const { - if (HasAttribute(name.c_str())) + if (HasAttribute(name)) { - return static_cast(m_reader->getAttributeValueAsInt(name.c_str())); + return static_cast(m_reader->getAttributeValueAsInt(name)); } else { @@ -86,9 +86,9 @@ int32_t OgreXmlSerializer::ReadAttribute(const std::string &name) const } template<> -uint32_t OgreXmlSerializer::ReadAttribute(const std::string &name) const +uint32_t OgreXmlSerializer::ReadAttribute(const char *name) const { - if (HasAttribute(name.c_str())) + if (HasAttribute(name)) { /** @note This is hackish. But we are never expecting unsigned values that go outside the int32_t range. Just monitor for negative numbers and kill the import. */ @@ -110,9 +110,9 @@ uint32_t OgreXmlSerializer::ReadAttribute(const std::string &name) con } template<> -uint16_t OgreXmlSerializer::ReadAttribute(const std::string &name) const +uint16_t OgreXmlSerializer::ReadAttribute(const char *name) const { - if (HasAttribute(name.c_str())) + if (HasAttribute(name)) { return static_cast(ReadAttribute(name)); } @@ -124,11 +124,11 @@ uint16_t OgreXmlSerializer::ReadAttribute(const std::string &name) con } template<> -float OgreXmlSerializer::ReadAttribute(const std::string &name) const +float OgreXmlSerializer::ReadAttribute(const char *name) const { - if (HasAttribute(name.c_str())) + if (HasAttribute(name)) { - return m_reader->getAttributeValueAsFloat(name.c_str()); + return m_reader->getAttributeValueAsFloat(name); } else { @@ -138,9 +138,9 @@ float OgreXmlSerializer::ReadAttribute(const std::string &name) const } template<> -std::string OgreXmlSerializer::ReadAttribute(const std::string &name) const +std::string OgreXmlSerializer::ReadAttribute(const char *name) const { - const char* value = m_reader->getAttributeValue(name.c_str()); + const char* value = m_reader->getAttributeValue(name); if (value) { return std::string(value); @@ -153,7 +153,7 @@ std::string OgreXmlSerializer::ReadAttribute(const std::string &nam } template<> -bool OgreXmlSerializer::ReadAttribute(const std::string &name) const +bool OgreXmlSerializer::ReadAttribute(const char *name) const { std::string value = Ogre::ToLower(ReadAttribute(name)); if (ASSIMP_stricmp(value, "true") == 0) diff --git a/code/OgreXmlSerializer.h b/code/OgreXmlSerializer.h index 487bb65fa..c0f09096c 100644 --- a/code/OgreXmlSerializer.h +++ b/code/OgreXmlSerializer.h @@ -98,7 +98,7 @@ private: void ReadAnimationKeyFrames(Animation *anim, VertexAnimationTrack *dest); template - T ReadAttribute(const std::string &name) const; + T ReadAttribute(const char *name) const; bool HasAttribute(const char *name) const; std::string &NextNode();