Core/StringExt: Don't pass string_view by ref

https://quuxplusone.github.io/blog/2021/11/09/pass-string-view-by-value/
This commit is contained in:
SirLynix
2023-08-24 08:23:14 +02:00
parent 1b7a89213d
commit bd53245f42
51 changed files with 115 additions and 115 deletions

View File

@@ -26,7 +26,7 @@ namespace Nz
template<typename T> ByteArray ComputeHash(HashType hash, T&& v);
template<typename T> ByteArray ComputeHash(AbstractHash& hash, T&& v);
inline bool HashAppend(AbstractHash* hash, const std::string_view& v);
inline bool HashAppend(AbstractHash* hash, std::string_view v);
template<typename T>
bool Serialize(SerializationContext& context, T&& value);

View File

@@ -57,7 +57,7 @@ namespace Nz
return hash.End();
}
inline bool HashAppend(AbstractHash& hash, const std::string_view& v)
inline bool HashAppend(AbstractHash& hash, std::string_view v)
{
hash.Append(reinterpret_cast<const UInt8*>(v.data()), v.size());
return true;

View File

@@ -43,8 +43,8 @@ namespace Nz
template<typename... Args> static void Write(std::string_view str, Args&&... args);
static void WriteError(ErrorType type, std::string_view error, unsigned int line = 0, const char* file = nullptr, const char* function = nullptr);
NazaraStaticSignal(OnLogWrite, const std::string_view& /*string*/);
NazaraStaticSignal(OnLogWriteError, ErrorType /*type*/, const std::string_view& /*error*/, unsigned int /*line*/, const char* /*file*/, const char* /*function*/);
NazaraStaticSignal(OnLogWrite, std::string_view /*string*/);
NazaraStaticSignal(OnLogWriteError, ErrorType /*type*/, std::string_view /*error*/, unsigned int /*line*/, const char* /*file*/, const char* /*function*/);
private:
static bool Initialize();

View File

@@ -43,7 +43,7 @@ namespace Nz
void Clear();
bool IsExtensionSupported(const std::string_view& extension) const;
bool IsExtensionSupported(std::string_view extension) const;
std::shared_ptr<Type> LoadFromFile(const std::filesystem::path& filePath, const Parameters& parameters = Parameters()) const;
std::shared_ptr<Type> LoadFromMemory(const void* data, std::size_t size, const Parameters& parameters = Parameters()) const;

View File

@@ -34,7 +34,7 @@ namespace Nz
* \param extension Extension of the file (ex: ".png")
*/
template<typename Type, typename Parameters>
bool ResourceLoader<Type, Parameters>::IsExtensionSupported(const std::string_view& extension) const
bool ResourceLoader<Type, Parameters>::IsExtensionSupported(std::string_view extension) const
{
NazaraAssert(extension.size() >= 2 || extension.front() != '.', "extension should start with a .");

View File

@@ -29,7 +29,7 @@ namespace Nz
public:
struct Entry;
using FormatSupport = std::function<bool(const std::string_view& format)>;
using FormatSupport = std::function<bool(std::string_view format)>;
using FileSaver = std::function<bool(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters)>;
using StreamSaver = std::function<bool(const Type& resource, const std::string& format, Stream& stream, const Parameters& parameters)>;
@@ -40,7 +40,7 @@ namespace Nz
void Clear();
bool IsExtensionSupported(const std::string_view& extension) const;
bool IsExtensionSupported(std::string_view extension) const;
bool SaveToFile(const Type& resource, const std::filesystem::path& filePath, const Parameters& parameters = Parameters()) const;
bool SaveToStream(const Type& resource, Stream& stream, const std::string& format, const Parameters& parameters = Parameters()) const;

View File

@@ -34,7 +34,7 @@ namespace Nz
* \param extension Extension of the file
*/
template<typename Type, typename Parameters>
bool ResourceSaver<Type, Parameters>::IsExtensionSupported(const std::string_view& extension) const
bool ResourceSaver<Type, Parameters>::IsExtensionSupported(std::string_view extension) const
{
NazaraAssert(extension.size() >= 2 || extension.front() != '.', "extension should start with a .");

View File

@@ -18,55 +18,55 @@ namespace Nz
struct UnicodeAware {};
// std::string is assumed to contains UTF-8
NAZARA_CORE_API std::size_t ComputeCharacterCount(const std::string_view& str);
NAZARA_CORE_API std::size_t ComputeCharacterCount(std::string_view str);
inline bool EndsWith(const std::string_view& str, const std::string_view& s);
NAZARA_CORE_API bool EndsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent);
NAZARA_CORE_API bool EndsWith(const std::string_view& lhs, const std::string_view& rhs, UnicodeAware);
NAZARA_CORE_API bool EndsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent, UnicodeAware);
inline bool EndsWith(std::string_view str, std::string_view s);
NAZARA_CORE_API bool EndsWith(std::string_view lhs, std::string_view rhs, CaseIndependent);
NAZARA_CORE_API bool EndsWith(std::string_view lhs, std::string_view rhs, UnicodeAware);
NAZARA_CORE_API bool EndsWith(std::string_view lhs, std::string_view rhs, CaseIndependent, UnicodeAware);
NAZARA_CORE_API std::string FromUtf16String(const std::u16string_view& u16str);
NAZARA_CORE_API std::string FromUtf32String(const std::u32string_view& u32str);
NAZARA_CORE_API std::string FromWideString(const std::wstring_view& str);
NAZARA_CORE_API std::string FromUtf16String(std::u16string_view u16str);
NAZARA_CORE_API std::string FromUtf32String(std::u32string_view u32str);
NAZARA_CORE_API std::string FromWideString(std::wstring_view str);
NAZARA_CORE_API std::size_t GetCharacterPosition(const std::string_view& str, std::size_t characterIndex);
NAZARA_CORE_API std::string_view GetWord(const std::string_view& str, std::size_t wordIndex);
NAZARA_CORE_API std::string_view GetWord(const std::string_view& str, std::size_t wordIndex, UnicodeAware);
NAZARA_CORE_API std::size_t GetCharacterPosition(std::string_view str, std::size_t characterIndex);
NAZARA_CORE_API std::string_view GetWord(std::string_view str, std::size_t wordIndex);
NAZARA_CORE_API std::string_view GetWord(std::string_view str, std::size_t wordIndex, UnicodeAware);
inline bool IsNumber(std::string_view str);
NAZARA_CORE_API bool MatchPattern(const std::string_view& str, const std::string_view& pattern);
NAZARA_CORE_API bool MatchPattern(std::string_view str, std::string_view pattern);
inline std::string NumberToString(long long number, UInt8 radix = 10);
NAZARA_CORE_API std::string PointerToString(const void* ptr);
inline std::string& ReplaceStr(std::string& str, const std::string_view& from, const std::string_view& to);
inline std::string& ReplaceStr(std::string& str, std::string_view from, std::string_view to);
inline bool StartsWith(const std::string_view& str, const std::string_view& s);
NAZARA_CORE_API bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent);
NAZARA_CORE_API bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, UnicodeAware);
NAZARA_CORE_API bool StartsWith(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent, UnicodeAware);
inline bool StartsWith(std::string_view str, std::string_view s);
NAZARA_CORE_API bool StartsWith(std::string_view lhs, std::string_view rhs, CaseIndependent);
NAZARA_CORE_API bool StartsWith(std::string_view lhs, std::string_view rhs, UnicodeAware);
NAZARA_CORE_API bool StartsWith(std::string_view lhs, std::string_view rhs, CaseIndependent, UnicodeAware);
template<typename F> bool SplitString(const std::string_view& str, const std::string_view& token, F&& func);
template<typename F> bool SplitStringAny(const std::string_view& str, const std::string_view& token, F&& func);
template<typename F> bool SplitString(std::string_view str, std::string_view token, F&& func);
template<typename F> bool SplitStringAny(std::string_view str, std::string_view token, F&& func);
inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs);
inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent);
NAZARA_CORE_API bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, UnicodeAware);
NAZARA_CORE_API bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent, UnicodeAware);
inline bool StringEqual(std::string_view lhs, std::string_view rhs);
inline bool StringEqual(std::string_view lhs, std::string_view rhs, CaseIndependent);
NAZARA_CORE_API bool StringEqual(std::string_view lhs, std::string_view rhs, UnicodeAware);
NAZARA_CORE_API bool StringEqual(std::string_view lhs, std::string_view rhs, CaseIndependent, UnicodeAware);
inline long long StringToNumber(const std::string_view& str, UInt8 radix = 10, bool* ok = nullptr);
inline long long StringToNumber(std::string_view str, UInt8 radix = 10, bool* ok = nullptr);
NAZARA_CORE_API std::string ToLower(const std::string_view& str);
NAZARA_CORE_API std::string ToLower(const std::string_view& str, UnicodeAware);
NAZARA_CORE_API std::string ToLower(std::string_view str);
NAZARA_CORE_API std::string ToLower(std::string_view str, UnicodeAware);
NAZARA_CORE_API std::string ToUpper(const std::string_view& str);
NAZARA_CORE_API std::string ToUpper(const std::string_view& str, UnicodeAware);
NAZARA_CORE_API std::string ToUpper(std::string_view str);
NAZARA_CORE_API std::string ToUpper(std::string_view str, UnicodeAware);
NAZARA_CORE_API std::u16string ToUtf16String(const std::string_view& str);
NAZARA_CORE_API std::u32string ToUtf32String(const std::string_view& str);
NAZARA_CORE_API std::wstring ToWideString(const std::string_view& str);
NAZARA_CORE_API std::u16string ToUtf16String(std::string_view str);
NAZARA_CORE_API std::u32string ToUtf32String(std::string_view str);
NAZARA_CORE_API std::wstring ToWideString(std::string_view str);
inline std::string_view Trim(std::string_view str);
inline std::string_view Trim(std::string_view str, char c);

View File

@@ -10,7 +10,7 @@
namespace Nz
{
inline bool EndsWith(const std::string_view& str, const std::string_view& s)
inline bool EndsWith(std::string_view str, std::string_view s)
{
#if NAZARA_CPP_VER >= NAZARA_CPP20
// C++20
@@ -77,7 +77,7 @@ namespace Nz
return str;
}
inline std::string& ReplaceStr(std::string& str, const std::string_view& from, const std::string_view& to)
inline std::string& ReplaceStr(std::string& str, std::string_view from, std::string_view to)
{
if (str.empty())
return str;
@@ -92,7 +92,7 @@ namespace Nz
return str;
}
inline bool StartsWith(const std::string_view& str, const std::string_view& s)
inline bool StartsWith(std::string_view str, std::string_view s)
{
#if NAZARA_CPP_VER >= NAZARA_CPP20
// C++20
@@ -103,7 +103,7 @@ namespace Nz
}
template<typename F>
bool SplitString(const std::string_view& str, const std::string_view& token, F&& func)
bool SplitString(std::string_view str, std::string_view token, F&& func)
{
std::size_t pos = 0;
std::size_t previousPos = 0;
@@ -123,7 +123,7 @@ namespace Nz
}
template<typename F>
bool SplitStringAny(const std::string_view& str, const std::string_view& token, F&& func)
bool SplitStringAny(std::string_view str, std::string_view token, F&& func)
{
std::size_t pos = 0;
std::size_t previousPos = 0;
@@ -139,12 +139,12 @@ namespace Nz
return func(str.substr(previousPos));
}
inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs)
inline bool StringEqual(std::string_view lhs, std::string_view rhs)
{
return lhs == rhs;
}
inline bool StringEqual(const std::string_view& lhs, const std::string_view& rhs, CaseIndependent)
inline bool StringEqual(std::string_view lhs, std::string_view rhs, CaseIndependent)
{
if (lhs.size() != rhs.size())
return false;
@@ -170,7 +170,7 @@ namespace Nz
* \remark radix is meant to be between 2 and 36, other values are potentially undefined behavior
* \remark With NAZARA_MATH_SAFE, a NazaraError is produced and 0 is returned
*/
inline long long StringToNumber(const std::string_view& str, UInt8 radix, bool* ok)
inline long long StringToNumber(std::string_view str, UInt8 radix, bool* ok)
{
NazaraAssert(radix >= 2 && radix <= 36, "base must be between 2 and 36");

View File

@@ -38,7 +38,7 @@ namespace Nz
OpenGLCommandBuffer(OpenGLCommandBuffer&&) = delete;
~OpenGLCommandBuffer() = default;
inline void BeginDebugRegion(const std::string_view& regionName, const Color& color);
inline void BeginDebugRegion(std::string_view regionName, const Color& color);
inline void BindComputePipeline(const OpenGLComputePipeline* pipeline);
inline void BindComputeShaderBinding(const OpenGLRenderPipelineLayout& pipelineLayout, UInt32 set, const OpenGLShaderBinding* binding);

View File

@@ -23,7 +23,7 @@ namespace Nz
{
}
inline void OpenGLCommandBuffer::BeginDebugRegion(const std::string_view& regionName, const Color& color)
inline void OpenGLCommandBuffer::BeginDebugRegion(std::string_view regionName, const Color& color)
{
BeginDebugRegionCommand beginDebugRegion;
beginDebugRegion.color = color;

View File

@@ -24,7 +24,7 @@ namespace Nz
OpenGLCommandBufferBuilder(OpenGLCommandBufferBuilder&&) noexcept = default;
~OpenGLCommandBufferBuilder() = default;
void BeginDebugRegion(const std::string_view& regionName, const Color& color) override;
void BeginDebugRegion(std::string_view regionName, const Color& color) override;
void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect, const ClearValues* clearValues, std::size_t clearValueCount) override;
void BindComputePipeline(const ComputePipeline& pipeline) override;

View File

@@ -208,7 +208,7 @@ namespace Nz::GL
virtual const Loader& GetLoader() = 0;
void OnContextRelease();
virtual bool ImplementFallback(const std::string_view& function);
virtual bool ImplementFallback(std::string_view function);
static void NotifyContextDestruction(Context* context);

View File

@@ -34,7 +34,7 @@ namespace Nz::GL
const Context* GetContext() const;
GLuint GetObjectId() const;
void SetDebugName(const std::string_view& name);
void SetDebugName(std::string_view name);
ContextObject& operator=(const ContextObject&) = delete;
ContextObject& operator=(ContextObject&& object) noexcept = default;

View File

@@ -85,7 +85,7 @@ namespace Nz::GL
}
template<typename C, GLenum ObjectType, typename... CreateArgs>
void ContextObject<C, ObjectType, CreateArgs...>::SetDebugName(const std::string_view& name)
void ContextObject<C, ObjectType, CreateArgs...>::SetDebugName(std::string_view name)
{
EnsureContext();

View File

@@ -35,7 +35,7 @@ namespace Nz::GL
OpenGLDevice* GetDevice() const;
GLuint GetObjectId() const;
void SetDebugName(const std::string_view& name);
void SetDebugName(std::string_view name);
DeviceObject& operator=(const DeviceObject&) = delete;
DeviceObject& operator=(DeviceObject&& object) noexcept = default;

View File

@@ -91,7 +91,7 @@ namespace Nz::GL
}
template<typename C, GLenum ObjectType, typename... CreateArgs>
void DeviceObject<C, ObjectType, CreateArgs...>::SetDebugName(const std::string_view& name)
void DeviceObject<C, ObjectType, CreateArgs...>::SetDebugName(std::string_view name)
{
const Context& context = EnsureDeviceContext();

View File

@@ -57,7 +57,7 @@ namespace Nz::GL
EGLSurface m_surface;
private:
bool ImplementFallback(const std::string_view& function) override;
bool ImplementFallback(std::string_view function) override;
bool Activate() const override;
void Desactivate() const override;

View File

@@ -41,7 +41,7 @@ namespace Nz::GL
static const char* TranslateError(EGLint errorId);
private:
bool ImplementFallback(const std::string_view& function);
bool ImplementFallback(std::string_view function);
ContextType m_preferredContextType;
EGLDisplay m_defaultDisplay;

View File

@@ -31,7 +31,7 @@ namespace Nz::GL
inline void SetBinarySource(GLenum binaryFormat, const void* binary, GLsizei length);
inline void SetSource(const char* source, GLint length);
inline void SetSource(const std::string_view& source);
inline void SetSource(std::string_view source);
// GL_ARB_gl_spirv
inline void SpecializeShader(const GLchar* pEntryPoint, GLuint numSpecializationConstants, const GLuint* pConstantIndex, const GLuint* pConstantValue);

View File

@@ -80,7 +80,7 @@ namespace Nz::GL
m_device->GetReferenceContext().glShaderSource(m_objectId, 1U, &source, &length);
}
inline void Shader::SetSource(const std::string_view& source)
inline void Shader::SetSource(std::string_view source)
{
return SetSource(source.data(), GLint(source.size()));
}

View File

@@ -47,7 +47,7 @@ namespace Nz::GL
private:
bool CreateInternal(const WGLContext* baseContext, const ContextParams& params, const WGLContext* shareContext = nullptr);
bool ImplementFallback(const std::string_view& function) override;
bool ImplementFallback(std::string_view function) override;
bool Activate() const override;
void Desactivate() const override;

View File

@@ -51,7 +51,7 @@ namespace Nz::GL
const WebLoader& m_loader;
private:
bool ImplementFallback(const std::string_view& function) override;
bool ImplementFallback(std::string_view function) override;
bool Activate() const override;
void Desactivate() const override;

View File

@@ -31,7 +31,7 @@ namespace Nz::GL
static const char* TranslateError(EMSCRIPTEN_RESULT errorId);
private:
bool ImplementFallback(const std::string_view& function);
bool ImplementFallback(std::string_view function);
};
}

View File

@@ -38,7 +38,7 @@ namespace Nz
CommandBufferBuilder(CommandBufferBuilder&&) = default;
virtual ~CommandBufferBuilder();
virtual void BeginDebugRegion(const std::string_view& regionName, const Color& color) = 0;
virtual void BeginDebugRegion(std::string_view regionName, const Color& color) = 0;
virtual void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect, const ClearValues* clearValues, std::size_t clearValueCount) = 0;
inline void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect);
inline void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect, std::initializer_list<ClearValues> clearValues);

View File

@@ -23,7 +23,7 @@ namespace Nz
inline SimpleTextDrawer(SimpleTextDrawer&& drawer) noexcept;
~SimpleTextDrawer() = default;
inline void AppendText(const std::string_view& str);
inline void AppendText(std::string_view str);
void Clear() override;
@@ -75,7 +75,7 @@ namespace Nz
inline void DisconnectFontSlots();
bool GenerateGlyph(Glyph& glyph, char32_t character, float outlineThickness, bool lineWrap, Color color, int renderOrder, int* advance) const;
void GenerateGlyphs(const std::string_view& text) const;
void GenerateGlyphs(std::string_view text) const;
inline float GetLineHeight(const Font::SizeInfo& sizeInfo) const;

View File

@@ -42,7 +42,7 @@ namespace Nz
operator=(std::move(drawer));
}
inline void SimpleTextDrawer::AppendText(const std::string_view& str)
inline void SimpleTextDrawer::AppendText(std::string_view str)
{
m_text.append(str);
if (m_glyphUpdated)

View File

@@ -24,7 +24,7 @@ namespace Nz
VulkanCommandBufferBuilder(VulkanCommandBufferBuilder&&) noexcept = default;
~VulkanCommandBufferBuilder() = default;
void BeginDebugRegion(const std::string_view& regionName, const Color& color) override;
void BeginDebugRegion(std::string_view regionName, const Color& color) override;
void BeginRenderPass(const Framebuffer& framebuffer, const RenderPass& renderPass, const Recti& renderRect, const ClearValues* clearValues, std::size_t clearValueCount) override;
void BindComputePipeline(const ComputePipeline& pipeline) override;