Optimize out a lot of std::string construction and allocations (#415)

Update CommandLineParameters.hpp

Update CommandLineParametersTests.cpp

Update WebContext.hpp

xmake check-files -f

Fix MaterialPassRegistry
This commit is contained in:
Jérôme Leclercq
2023-12-30 14:50:57 +01:00
committed by GitHub
parent f7c9060364
commit 79ec135af7
57 changed files with 219 additions and 210 deletions

View File

@@ -57,12 +57,12 @@ namespace Nz
private:
bool Advance(bool required = true);
void Error(const std::string& message);
void Error(std::string_view message);
bool ParseBaseframe();
bool ParseBounds();
bool ParseFrame();
bool ParseHierarchy();
void Warning(const std::string& message);
void Warning(std::string_view message);
void UnrecognizedLine(bool error = false);
std::vector<float> m_animatedComponents;

View File

@@ -66,10 +66,10 @@ namespace Nz
private:
bool Advance(bool required = true);
void Error(const std::string& message);
void Error(std::string_view message);
bool ParseJoints();
bool ParseMesh();
void Warning(const std::string& message);
void Warning(std::string_view message);
void UnrecognizedLine(bool error = false);
std::vector<Joint> m_joints;

View File

@@ -10,6 +10,7 @@
#include <NazaraUtils/Prerequisites.hpp>
#include <Nazara/Core/Color.hpp>
#include <Nazara/Utility/Config.hpp>
#include <NazaraUtils/StringHash.hpp>
#include <unordered_map>
namespace Nz
@@ -22,12 +23,12 @@ namespace Nz
MTLParser() = default;
~MTLParser() = default;
inline Material* AddMaterial(const std::string& matName);
inline Material* AddMaterial(std::string matName);
inline void Clear();
inline const Material* GetMaterial(const std::string& materialName) const;
inline const std::unordered_map<std::string, Material>& GetMaterials() const;
inline const Material* GetMaterial(std::string_view materialName) const;
inline const std::unordered_map<std::string, Material, StringHash<>, std::equal_to<>>& GetMaterials() const;
bool Parse(Stream& stream);
@@ -60,12 +61,12 @@ namespace Nz
template<typename T> void Emit(const T& text) const;
inline void EmitLine() const;
template<typename T> void EmitLine(const T& line) const;
inline void Error(const std::string& message);
inline void Error(std::string_view message);
inline void Flush() const;
inline void Warning(const std::string& message);
inline void Warning(std::string_view message);
inline void UnrecognizedLine(bool error = false);
std::unordered_map<std::string, Material> m_materials;
std::unordered_map<std::string, Material, StringHash<>, std::equal_to<>> m_materials;
mutable Stream* m_currentStream;
std::string m_currentLine;
mutable std::ostringstream m_outputStream;

View File

@@ -7,9 +7,9 @@
namespace Nz
{
inline MTLParser::Material* MTLParser::AddMaterial(const std::string& matName)
inline MTLParser::Material* MTLParser::AddMaterial(std::string matName)
{
return &m_materials[matName];
return &m_materials[std::move(matName)];
}
inline void MTLParser::Clear()
@@ -17,7 +17,7 @@ namespace Nz
m_materials.clear();
}
inline const MTLParser::Material* MTLParser::GetMaterial(const std::string& materialName) const
inline const MTLParser::Material* MTLParser::GetMaterial(std::string_view materialName) const
{
auto it = m_materials.find(materialName);
if (it != m_materials.end())
@@ -26,7 +26,7 @@ namespace Nz
return nullptr;
}
inline const std::unordered_map<std::string, MTLParser::Material>& MTLParser::GetMaterials() const
inline auto MTLParser::GetMaterials() const -> const std::unordered_map<std::string, Material, StringHash<>, std::equal_to<>>&
{
return m_materials;
}
@@ -51,7 +51,7 @@ namespace Nz
Emit('\n');
}
inline void MTLParser::Error(const std::string& message)
inline void MTLParser::Error(std::string_view message)
{
NazaraErrorFmt("{0} at line #{1}", message, m_lineCount);
}
@@ -62,7 +62,7 @@ namespace Nz
m_outputStream.str({});
}
inline void MTLParser::Warning(const std::string& message)
inline void MTLParser::Warning(std::string_view message)
{
NazaraWarningFmt("{0} at line #{1}", message, m_lineCount);
}

View File

@@ -81,9 +81,9 @@ namespace Nz
template<typename T> void Emit(const T& text) const;
inline void EmitLine() const;
template<typename T> void EmitLine(const T& line) const;
inline void Error(const std::string& message);
inline void Error(std::string_view message);
inline void Flush() const;
inline void Warning(const std::string& message);
inline void Warning(std::string_view message);
inline bool UnrecognizedLine(bool error = false);
std::vector<Mesh> m_meshes;

View File

@@ -151,7 +151,7 @@ namespace Nz
Emit('\n');
}
inline void OBJParser::Error(const std::string& message)
inline void OBJParser::Error(std::string_view message)
{
NazaraErrorFmt("{0} on line #{1}", message, m_lineCount);
}
@@ -162,7 +162,7 @@ namespace Nz
m_outputStream.str({});
}
inline void OBJParser::Warning(const std::string& message)
inline void OBJParser::Warning(std::string_view message)
{
NazaraWarningFmt("{0} on line #{1}", message, m_lineCount);
}