From 738833a0470ce93b7809ca4bdea253677f27fb57 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 21 Aug 2025 13:37:34 +0200 Subject: feat!: Breaking changes, reworked the KString API inside the ne_kernel. Signed-off-by: Amlal El Mahrouss --- dev/kernel/NeKit/KString.h | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'dev/kernel/NeKit/KString.h') diff --git a/dev/kernel/NeKit/KString.h b/dev/kernel/NeKit/KString.h index 16b09a78..35bdce97 100644 --- a/dev/kernel/NeKit/KString.h +++ b/dev/kernel/NeKit/KString.h @@ -16,10 +16,11 @@ namespace Kernel { /// @brief Kernel string class, not dynamic. -class KString final { +template +class BasicKString final { public: - explicit KString() { - fDataSz = kMinimumStringSize; + explicit BasicKString() { + fDataSz = MinSz; fData = new Char[fDataSz]; MUST_PASS(fData); @@ -27,7 +28,7 @@ class KString final { rt_set_memory(fData, 0, fDataSz); } - explicit KString(SizeT Sz) : fDataSz(Sz) { + explicit BasicKString(SizeT Sz) : fDataSz(Sz) { MUST_PASS(Sz > 1); fData = new Char[Sz]; @@ -36,14 +37,14 @@ class KString final { rt_set_memory(fData, 0, Sz); } - ~KString() { + ~BasicKString() { if (fData) { delete[] fData; fData = nullptr; } } - NE_COPY_DEFAULT(KString) + NE_COPY_DEFAULT(BasicKString) Char* Data(); const Char* CData() const; @@ -52,11 +53,13 @@ class KString final { bool operator==(const Char* rhs) const; bool operator!=(const Char* rhs) const; - bool operator==(const KString& rhs) const; - bool operator!=(const KString& rhs) const; + bool operator==(const BasicKString<>& rhs) const; + bool operator!=(const BasicKString<>& rhs) const; - KString& operator+=(const Char* rhs); - KString& operator+=(const KString& rhs); + BasicKString<>& operator+=(const Char* rhs); + BasicKString<>& operator+=(const BasicKString<>& rhs); + + operator const char*() { return fData; } operator bool() { return fData; } @@ -70,6 +73,8 @@ class KString final { friend class KStringBuilder; }; +using KString = BasicKString<>; + class KStringBuilder final { public: static ErrorOr Construct(const Char* data); @@ -77,6 +82,7 @@ class KStringBuilder final { static const Char* Format(const Char* fmt, const Char* from); static bool Equals(const Char* lhs, const Char* rhs); static bool Equals(const Utf8Char* lhs, const Utf8Char* rhs); - static bool Equals(const WideChar* lhs, const WideChar* rhs); }; } // namespace Kernel + +#include -- cgit v1.2.3 From c194049e5b39c2c249f3c290dc365f502dc156ac Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 22 Aug 2025 04:28:21 +0200 Subject: feat: Add `KStringOr` alias, and `mm_make_own_ptr` doesn't use `MUST_PASS` anymore. Signed-off-by: Amlal El Mahrouss --- dev/kernel/NeKit/KString.h | 3 ++- dev/kernel/NeKit/MutableArray.h | 20 ++++++++++---------- dev/kernel/NeKit/OwnPtr.h | 1 - 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'dev/kernel/NeKit/KString.h') diff --git a/dev/kernel/NeKit/KString.h b/dev/kernel/NeKit/KString.h index 35bdce97..bbe49f8e 100644 --- a/dev/kernel/NeKit/KString.h +++ b/dev/kernel/NeKit/KString.h @@ -73,7 +73,8 @@ class BasicKString final { friend class KStringBuilder; }; -using KString = BasicKString<>; +using KString = BasicKString<>; +using KStringOr = ErrorOr; class KStringBuilder final { public: diff --git a/dev/kernel/NeKit/MutableArray.h b/dev/kernel/NeKit/MutableArray.h index 8dee6e03..02c8dc2d 100644 --- a/dev/kernel/NeKit/MutableArray.h +++ b/dev/kernel/NeKit/MutableArray.h @@ -9,21 +9,21 @@ #include #include -#define TRY_FIND_NODE(NAME, NODE) \ +#define RTL_TRY_FIND_NODE(NAME, NODE) \ auto* NAME = NODE; \ while (NAME) { \ if (NAME->fIndex == Index) return NAME->fVal; \ NAME = NAME->fNext; \ } -#define TRY_FIND_NODE2(NAME, NODE) \ +#define RTL_TRY_FIND_NODE2(NAME, NODE) \ auto* NAME = NODE; \ while (NAME) { \ if (NAME->fIndex == Index) return Ref{NAME->fVal}; \ NAME = NAME->fNext; \ } -#define TRY_REMOVE_NODE(NODE) \ +#define RTL_TRY_REMOVE_NODE(NODE) \ if (NODE && NODE->fIndex == Index) { \ NODE->fUsed = false; \ NODE->fIndex = 0; \ @@ -31,7 +31,7 @@ return true; \ } -// FIXME: this is a shitty algorithm, which is consumer hungry. +// FIXME: this is a shitty algorithm, because it is memory heavy. // Remove and occurences of that, and remove that class. namespace Kernel { template @@ -81,8 +81,8 @@ class NullableMutableArray { public: T operator[](SizeT Index) const { - TRY_FIND_NODE(first, fFirstNode); - TRY_FIND_NODE(last, fLastNode); + RTL_TRY_FIND_NODE(first, fFirstNode); + RTL_TRY_FIND_NODE(last, fLastNode); return _PlaceHolderValue; } @@ -91,8 +91,8 @@ class NullableMutableArray { public: Boolean Remove(SizeT Index) { - TRY_REMOVE_NODE(fFirstNode); - TRY_REMOVE_NODE(fLastNode); + RTL_TRY_REMOVE_NODE(fFirstNode); + RTL_TRY_REMOVE_NODE(fLastNode); return false; } @@ -172,8 +172,8 @@ class MutableArray : public NullableMutableArray { public: Ref operator[](SizeT Index) const { - TRY_FIND_NODE2(first, fFirstNode); - TRY_FIND_NODE2(last, fLastNode); + RTL_TRY_FIND_NODE2(first, fFirstNode); + RTL_TRY_FIND_NODE2(last, fLastNode); return {}; } diff --git a/dev/kernel/NeKit/OwnPtr.h b/dev/kernel/NeKit/OwnPtr.h index 674f9ff3..22435118 100644 --- a/dev/kernel/NeKit/OwnPtr.h +++ b/dev/kernel/NeKit/OwnPtr.h @@ -61,7 +61,6 @@ template inline OwnPtr mm_make_own_ptr(Args... args) { OwnPtr ret; ret.template New(forward(args)...); - MUST_PASS(ret); return ret; } -- cgit v1.2.3