From 00143afc01dbca797471181105738042e89f15ae Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sat, 13 Apr 2024 00:04:42 +0200 Subject: Use string view everywhere --- deimos/core/base.h | 5 +++++ deimos/core/format.cpp | 2 +- deimos/core/format.h | 11 ++--------- deimos/core/log.cpp | 3 +-- deimos/core/log.h | 3 +-- 5 files changed, 10 insertions(+), 14 deletions(-) (limited to 'deimos/core') diff --git a/deimos/core/base.h b/deimos/core/base.h index 1022ae8..1e9b4a9 100644 --- a/deimos/core/base.h +++ b/deimos/core/base.h @@ -128,6 +128,11 @@ public: constexpr int64_t size() const { return m_size; } }; +inline Span AsBytes(StringView span) +{ + return { reinterpret_cast(span.data()), span.size() }; +} + deimos_StaticAssert(std::is_trivially_destructible_v); deimos_StaticAssert(std::is_trivially_copyable_v); diff --git a/deimos/core/format.cpp b/deimos/core/format.cpp index b9a0ca3..af0a851 100644 --- a/deimos/core/format.cpp +++ b/deimos/core/format.cpp @@ -19,7 +19,7 @@ public: m_writer->Write(AsBytes(Span(&c, 1))); } - void PushString(Span str) + void PushString(StringView str) { m_writer->Write(AsBytes(str)); } diff --git a/deimos/core/format.h b/deimos/core/format.h index be2e4bf..3424dc2 100644 --- a/deimos/core/format.h +++ b/deimos/core/format.h @@ -22,9 +22,7 @@ struct FormatArg { int64_t integer; uint64_t unsigned_integer; - - // @Todo Use string views - Span string; + StringView string; }; explicit FormatArg(std::signed_integral auto value) : @@ -37,15 +35,10 @@ struct FormatArg unsigned_integer{value} {} - explicit FormatArg(Span value) : + explicit FormatArg(StringView value) : type{kString}, string{value} {} - - explicit FormatArg(gsl::czstring value) : - type{kString}, - string{value, (int64_t)__builtin_strlen(value)} - {} }; template diff --git a/deimos/core/log.cpp b/deimos/core/log.cpp index 3ba4fbc..e05c360 100644 --- a/deimos/core/log.cpp +++ b/deimos/core/log.cpp @@ -35,8 +35,7 @@ public: m_writer(os_console_api, OsConsoleType::kStdOut) {} - // @Todo Use string views - void Log(LogSeverity severity, const SourceLocation& location, Span msg) override + void Log(LogSeverity severity, const SourceLocation& location, StringView msg) override { Format(&m_writer, "$[ $ ] $:$: $\033[0m\n", SeverityToColor(severity), SeverityToStr(severity), location.file, location.line, msg); diff --git a/deimos/core/log.h b/deimos/core/log.h index 323d246..9bb4dbb 100644 --- a/deimos/core/log.h +++ b/deimos/core/log.h @@ -21,8 +21,7 @@ public: deimos_NO_COPY_MOVE(ILogger); virtual ~ILogger() = default; - // @Todo Use string view - virtual void Log(LogSeverity, const SourceLocation&, Span) = 0; + virtual void Log(LogSeverity, const SourceLocation&, StringView) = 0; }; // Just a helper to pass a SourceLocation without having to write {} to logging functions. -- cgit