From 27fd1ba438eecbe184a5deda6d9f468509ec4f42 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 21 Aug 2025 09:23:13 +0200 Subject: feat: refactor and fixed python scripts. Signed-off-by: Amlal El Mahrouss --- dev/kernel/NeKit/Macros.h | 2 +- dev/kernel/NeKit/OwnPtr.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'dev/kernel/NeKit') diff --git a/dev/kernel/NeKit/Macros.h b/dev/kernel/NeKit/Macros.h index e80e2e47..b46ffaa8 100644 --- a/dev/kernel/NeKit/Macros.h +++ b/dev/kernel/NeKit/Macros.h @@ -16,7 +16,7 @@ #endif #ifndef kib_cast -#define kib_cast(X) (Kernel::UInt64)((X) * 1024) +#define kib_cast(X) (Kernel::UInt64)((X) *1024) #endif #ifndef MIB diff --git a/dev/kernel/NeKit/OwnPtr.h b/dev/kernel/NeKit/OwnPtr.h index f5ff4b54..674f9ff3 100644 --- a/dev/kernel/NeKit/OwnPtr.h +++ b/dev/kernel/NeKit/OwnPtr.h @@ -50,7 +50,7 @@ class OwnPtr final { Ref AsRef() { return Ref(fCls); } - operator bool() { return fCls; } + operator bool() { return fCls; } bool operator!() { return !fCls; } private: -- cgit v1.2.3 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/CFKit/Property.h | 4 +- dev/kernel/FSKit/IndexableProperty.h | 2 +- dev/kernel/NeKit/Json.h | 10 +- dev/kernel/NeKit/KString.h | 28 +++--- dev/kernel/NeKit/KString.inl | 181 +++++++++++++++++++++++++++++++++++ dev/kernel/src/KString.cc | 180 ---------------------------------- dev/kernel/src/Property.cc | 4 +- dev/kernel/src/UtfUtils.cc | 2 +- 8 files changed, 209 insertions(+), 202 deletions(-) create mode 100644 dev/kernel/NeKit/KString.inl delete mode 100644 dev/kernel/src/KString.cc (limited to 'dev/kernel/NeKit') diff --git a/dev/kernel/CFKit/Property.h b/dev/kernel/CFKit/Property.h index 9d35dc60..e872896d 100644 --- a/dev/kernel/CFKit/Property.h +++ b/dev/kernel/CFKit/Property.h @@ -32,9 +32,9 @@ class Property { Property& operator=(const Property&) = default; Property(const Property&) = default; - BOOL StringEquals(KString& name); + BOOL StringEquals(BasicKString<>& name); PropertyId& GetValue(); - KString& GetKey(); + BasicKString<>& GetKey(); private: KString fName{kMaxPropLen}; diff --git a/dev/kernel/FSKit/IndexableProperty.h b/dev/kernel/FSKit/IndexableProperty.h index 3f2c42ac..8be6d7c3 100644 --- a/dev/kernel/FSKit/IndexableProperty.h +++ b/dev/kernel/FSKit/IndexableProperty.h @@ -25,7 +25,7 @@ namespace Indexer { class IndexableProperty final : public Property { public: explicit IndexableProperty() : Property() { - Kernel::KString strProp(kMaxPropLen); + Kernel::BasicKString<> strProp(kMaxPropLen); strProp += "/prop/indexable"; this->GetKey() = strProp; diff --git a/dev/kernel/NeKit/Json.h b/dev/kernel/NeKit/Json.h index 2b2c9c04..ebd4acf9 100644 --- a/dev/kernel/NeKit/Json.h +++ b/dev/kernel/NeKit/Json.h @@ -26,7 +26,7 @@ class Json final { public: explicit Json() { auto len = kJSONMaxLen; - KString key = KString(len); + BasicKString<> key = KString(len); key += kJSONNullObj; this->AsKey() = key; @@ -43,17 +43,17 @@ class Json final { private: Bool fUndefined; // is this instance undefined? - KString fKey; - KString fValue; + BasicKString<> fKey; + BasicKString<> fValue; public: /// @brief returns the key of the json /// @return the key as string view. - KString& AsKey() { return fKey; } + BasicKString<>& AsKey() { return fKey; } /// @brief returns the value of the json. /// @return the key as string view. - KString& AsValue() { return fValue; } + BasicKString<>& AsValue() { return fValue; } static Json kNull; }; 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 diff --git a/dev/kernel/NeKit/KString.inl b/dev/kernel/NeKit/KString.inl new file mode 100644 index 00000000..a0dd3623 --- /dev/null +++ b/dev/kernel/NeKit/KString.inl @@ -0,0 +1,181 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#include + +/// @file BasicKString<>.cc +/// @brief Kernel String manipulation file. + +namespace Kernel { +inline void rt_string_append(Char* lhs, const Char* rhs, Int32 cur) { + SizeT sz_rhs = rt_string_len(rhs); + SizeT rhs_i = 0; + + for (; rhs_i < sz_rhs; ++rhs_i) { + lhs[rhs_i + cur] = rhs[rhs_i]; + } +} + +template<> +inline Char* BasicKString<>::Data() { + return this->fData; +} + +template<> +inline const Char* BasicKString<>::CData() const { + return const_cast(this->fData); +} + +template<> +inline SizeT BasicKString<>::Length() const { + return this->fDataSz; +} + +template<> +inline bool BasicKString<>::operator==(const BasicKString<>& rhs) const { + if (rhs.Length() != this->Length()) return false; + + for (Size index = 0; index < this->Length(); ++index) { + if (rhs.fData[index] != this->fData[index]) return false; + } + + return true; +} + +template<> +inline bool BasicKString<>::operator==(const Char* rhs) const { + if (rt_string_len(rhs) != this->Length()) return false; + + for (Size index = 0; index < rt_string_len(rhs); ++index) { + if (rhs[index] != this->fData[index]) return false; + } + + return true; +} + +template<> +inline bool BasicKString<>::operator!=(const BasicKString<>& rhs) const { + if (rhs.Length() != this->Length()) return false; + + for (Size index = 0; index < rhs.Length(); ++index) { + if (rhs.fData[index] == this->fData[index]) return false; + } + + return true; +} + +template<> +inline bool BasicKString<>::operator!=(const Char* rhs) const { + if (rt_string_len(rhs) != this->Length()) return false; + + for (Size index = 0; index < rt_string_len(rhs); ++index) { + if (rhs[index] == this->fData[index]) return false; + } + + return true; +} + +template<> +inline BasicKString<>& BasicKString<>::operator+=(const BasicKString<>& rhs) { + if (rt_string_len(rhs.fData) > this->Length()) return *this; + + rt_string_append(this->fData, const_cast(rhs.fData), this->fCur); + this->fCur += rt_string_len(const_cast(rhs.fData)); + + return *this; +} + +template<> +inline BasicKString<>& BasicKString<>::operator+=(const Char* rhs) { + rt_string_append(this->fData, const_cast(rhs), this->fCur); + this->fCur += rt_string_len(const_cast(rhs)); + + return *this; +} + +inline ErrorOr> KStringBuilder::Construct(const Char* data) { + if (!data || *data == 0) return ErrorOr>(new BasicKString<>(0)); + + BasicKString<>* view = new BasicKString<>(rt_string_len(data)); + (*view) += data; + + return ErrorOr>(*view); +} + +inline const Char* KStringBuilder::FromBool(const Char* fmt, bool i) { + if (!fmt) return ("?"); + + const Char* boolean_expr = i ? "YES" : "NO"; + Char* ret = (Char*) RTL_ALLOCA(rt_string_len(boolean_expr) + rt_string_len(fmt)); + + if (!ret) return ("?"); + + const auto fmt_len = rt_string_len(fmt); + const auto res_len = rt_string_len(boolean_expr); + + for (Size idx = 0; idx < fmt_len; ++idx) { + if (fmt[idx] == '%') { + SizeT result_cnt = idx; + + for (auto y_idx = idx; y_idx < res_len; ++y_idx) { + ret[result_cnt] = boolean_expr[y_idx]; + ++result_cnt; + } + + break; + } + + ret[idx] = fmt[idx]; + } + + return ret; +} + +inline bool KStringBuilder::Equals(const Char* lhs, const Char* rhs) { + if (rt_string_len(rhs) != rt_string_len(lhs)) return false; + + for (Size index = 0; index < rt_string_len(rhs); ++index) { + if (rhs[index] != lhs[index]) return false; + } + + return true; +} + +inline bool KStringBuilder::Equals(const Utf8Char* lhs, const Utf8Char* rhs) { + if (urt_string_len(rhs) != urt_string_len(lhs)) return false; + + for (Size index = 0; rhs[index] != 0; ++index) { + if (rhs[index] != lhs[index]) return false; + } + + return true; +} + +inline const Char* KStringBuilder::Format(const Char* fmt, const Char* fmt2) { + if (!fmt || !fmt2) return ("?"); + + Char* ret = (Char*) RTL_ALLOCA(sizeof(char) * (rt_string_len(fmt2) + rt_string_len(fmt))); + + if (!ret) return ("?"); + + const auto len = rt_string_len(fmt); + + for (Size idx = 0; idx < len; ++idx) { + if (fmt[idx] == '%' && idx < rt_string_len(fmt) && fmt[idx] == 's') { + Size result_cnt = idx; + + for (Size y_idx = 0; y_idx < rt_string_len(fmt2); ++y_idx) { + ret[result_cnt] = fmt2[y_idx]; + ++result_cnt; + } + } + + ret[idx] = fmt[idx]; + } + + return ret; +} +} // namespace Kernel diff --git a/dev/kernel/src/KString.cc b/dev/kernel/src/KString.cc deleted file mode 100644 index f5732280..00000000 --- a/dev/kernel/src/KString.cc +++ /dev/null @@ -1,180 +0,0 @@ -/* ------------------------------------------- - - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - -------------------------------------------- */ - -#include -#include - -/// @file KString.cc -/// @brief Kernel String manipulation file. - -namespace Kernel { -Char* KString::Data() { - return this->fData; -} - -const Char* KString::CData() const { - return const_cast(this->fData); -} - -Size KString::Length() const { - return this->fDataSz; -} - -bool KString::operator==(const KString& rhs) const { - if (rhs.Length() != this->Length()) return false; - - for (Size index = 0; index < this->Length(); ++index) { - if (rhs.fData[index] != this->fData[index]) return false; - } - - return true; -} - -bool KString::operator==(const Char* rhs) const { - if (rt_string_len(rhs) != this->Length()) return false; - - for (Size index = 0; index < rt_string_len(rhs); ++index) { - if (rhs[index] != this->fData[index]) return false; - } - - return true; -} - -bool KString::operator!=(const KString& rhs) const { - if (rhs.Length() != this->Length()) return false; - - for (Size index = 0; index < rhs.Length(); ++index) { - if (rhs.fData[index] == this->fData[index]) return false; - } - - return true; -} - -bool KString::operator!=(const Char* rhs) const { - if (rt_string_len(rhs) != this->Length()) return false; - - for (Size index = 0; index < rt_string_len(rhs); ++index) { - if (rhs[index] == this->fData[index]) return false; - } - - return true; -} - -ErrorOr KStringBuilder::Construct(const Char* data) { - if (!data || *data == 0) return ErrorOr(new KString(0)); - - KString* view = new KString(rt_string_len(data)); - (*view) += data; - - return ErrorOr(*view); -} - -const Char* KStringBuilder::FromBool(const Char* fmt, bool i) { - if (!fmt) return ("?"); - - const Char* boolean_expr = i ? "YES" : "NO"; - Char* ret = (Char*) RTL_ALLOCA(rt_string_len(boolean_expr) + rt_string_len(fmt)); - - if (!ret) return ("?"); - - const auto fmt_len = rt_string_len(fmt); - const auto res_len = rt_string_len(boolean_expr); - - for (Size idx = 0; idx < fmt_len; ++idx) { - if (fmt[idx] == '%') { - SizeT result_cnt = idx; - - for (auto y_idx = idx; y_idx < res_len; ++y_idx) { - ret[result_cnt] = boolean_expr[y_idx]; - ++result_cnt; - } - - break; - } - - ret[idx] = fmt[idx]; - } - - return ret; -} - -bool KStringBuilder::Equals(const Char* lhs, const Char* rhs) { - if (rt_string_len(rhs) != rt_string_len(lhs)) return false; - - for (Size index = 0; index < rt_string_len(rhs); ++index) { - if (rhs[index] != lhs[index]) return false; - } - - return true; -} - -/// @note This is unsafe!!! -bool KStringBuilder::Equals(const Utf8Char* lhs, const Utf8Char* rhs) { - for (Size index = 0; index < urt_string_len(rhs); ++index) { - if (rhs[index] != lhs[index]) return false; - } - - return true; -} - -bool KStringBuilder::Equals(const WideChar* lhs, const WideChar* rhs) { - for (Size index = 0; rhs[index] != 0; ++index) { - if (rhs[index] != lhs[index]) return false; - } - - return true; -} - -const Char* KStringBuilder::Format(const Char* fmt, const Char* fmt2) { - if (!fmt || !fmt2) return ("?"); - - Char* ret = (Char*) RTL_ALLOCA(sizeof(char) * (rt_string_len(fmt2) + rt_string_len(fmt))); - - if (!ret) return ("?"); - - const auto len = rt_string_len(fmt); - - for (Size idx = 0; idx < len; ++idx) { - if (fmt[idx] == '%' && idx < rt_string_len(fmt) && fmt[idx] == 's') { - Size result_cnt = idx; - - for (Size y_idx = 0; y_idx < rt_string_len(fmt2); ++y_idx) { - ret[result_cnt] = fmt2[y_idx]; - ++result_cnt; - } - } - - ret[idx] = fmt[idx]; - } - - return ret; -} - -STATIC void rt_string_append(Char* lhs, const Char* rhs, Int32 cur) { - SizeT sz_rhs = rt_string_len(rhs); - SizeT rhs_i = 0; - - for (; rhs_i < sz_rhs; ++rhs_i) { - lhs[rhs_i + cur] = rhs[rhs_i]; - } -} - -KString& KString::operator+=(const Char* rhs) { - rt_string_append(this->fData, rhs, this->fCur); - this->fCur += rt_string_len(rhs); - - return *this; -} - -KString& KString::operator+=(const KString& rhs) { - if (rt_string_len(rhs.fData) > this->Length()) return *this; - - rt_string_append(this->fData, const_cast(rhs.fData), this->fCur); - this->fCur += rt_string_len(const_cast(rhs.fData)); - - return *this; -} -} // namespace Kernel diff --git a/dev/kernel/src/Property.cc b/dev/kernel/src/Property.cc index 62aa6ef2..581da501 100644 --- a/dev/kernel/src/Property.cc +++ b/dev/kernel/src/Property.cc @@ -21,14 +21,14 @@ Property::Property() = default; /// @brief Check if property's name equals to name. /// @param name string to check. /***********************************************************************************/ -Bool Property::StringEquals(KString& name) { +Bool Property::StringEquals(BasicKString<>& name) { return this->fName && this->fName == name; } /***********************************************************************************/ /// @brief Gets the key (name) of property. /***********************************************************************************/ -KString& Property::GetKey() { +BasicKString<>& Property::GetKey() { return this->fName; } diff --git a/dev/kernel/src/UtfUtils.cc b/dev/kernel/src/UtfUtils.cc index a5c03b85..907632ad 100644 --- a/dev/kernel/src/UtfUtils.cc +++ b/dev/kernel/src/UtfUtils.cc @@ -27,7 +27,7 @@ Void urt_set_memory(const voidPtr src, UInt32 dst, Size len) { } } -Int32 rt_string_cmp(const Utf8Char* src, const Utf8Char* cmp, Size size) { +Int32 urt_string_cmp(const Utf8Char* src, const Utf8Char* cmp, Size size) { Int32 counter = 0; for (Size index = 0; index < size; ++index) { -- cgit v1.2.3 From b6ce3d25357b4e01daf212a955a6093133bc2fe4 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 21 Aug 2025 15:19:01 +0200 Subject: feat: Reworked `hefsi_hash_64` to follow the codebase's conventions. Signed-off-by: Amlal El Mahrouss --- dev/kernel/CFKit/Property.h | 6 +++--- dev/kernel/KernelKit/KernelTaskScheduler.h | 2 +- dev/kernel/KernelKit/UserProcessScheduler.h | 2 +- dev/kernel/NeKit/Json.h | 4 ++-- dev/kernel/NeKit/KString.inl | 18 +++++++++--------- dev/kernel/src/FS/HeFS+FileSystemParser.cc | 8 ++++---- 6 files changed, 20 insertions(+), 20 deletions(-) (limited to 'dev/kernel/NeKit') diff --git a/dev/kernel/CFKit/Property.h b/dev/kernel/CFKit/Property.h index e872896d..7fc9bf07 100644 --- a/dev/kernel/CFKit/Property.h +++ b/dev/kernel/CFKit/Property.h @@ -32,9 +32,9 @@ class Property { Property& operator=(const Property&) = default; Property(const Property&) = default; - BOOL StringEquals(BasicKString<>& name); - PropertyId& GetValue(); - BasicKString<>& GetKey(); + BOOL StringEquals(BasicKString<>& name); + PropertyId& GetValue(); + BasicKString<>& GetKey(); private: KString fName{kMaxPropLen}; diff --git a/dev/kernel/KernelKit/KernelTaskScheduler.h b/dev/kernel/KernelKit/KernelTaskScheduler.h index 78aea53c..527da9f0 100644 --- a/dev/kernel/KernelKit/KernelTaskScheduler.h +++ b/dev/kernel/KernelKit/KernelTaskScheduler.h @@ -28,7 +28,7 @@ class KERNEL_TASK final { HAL::StackFramePtr StackFrame{nullptr}; UInt8* StackReserve{nullptr}; SizeT StackSize{kSchedMaxStackSz}; - ProcessImage Image{}; + ProcessImage Image{}; /// @brief a KID is a Kernel Identification Descriptor, it is used to find a task running within /// the kernel. KID Kid{0}; diff --git a/dev/kernel/KernelKit/UserProcessScheduler.h b/dev/kernel/KernelKit/UserProcessScheduler.h index 9fa15f17..69a631be 100644 --- a/dev/kernel/KernelKit/UserProcessScheduler.h +++ b/dev/kernel/KernelKit/UserProcessScheduler.h @@ -48,7 +48,7 @@ class USER_PROCESS final { AffinityKind Affinity{AffinityKind::kStandard}; ProcessStatusKind Status{ProcessStatusKind::kKilled}; UInt8 StackReserve[kSchedMaxStackSz]; - ProcessImage Image{}; + ProcessImage Image{}; SizeT StackSize{kSchedMaxStackSz}; IDylibObject* DylibDelegate{nullptr}; SizeT MemoryCursor{0UL}; diff --git a/dev/kernel/NeKit/Json.h b/dev/kernel/NeKit/Json.h index ebd4acf9..24357dd7 100644 --- a/dev/kernel/NeKit/Json.h +++ b/dev/kernel/NeKit/Json.h @@ -25,7 +25,7 @@ namespace Kernel { class Json final { public: explicit Json() { - auto len = kJSONMaxLen; + auto len = kJSONMaxLen; BasicKString<> key = KString(len); key += kJSONNullObj; @@ -42,7 +42,7 @@ class Json final { Bool& IsUndefined() { return fUndefined; } private: - Bool fUndefined; // is this instance undefined? + Bool fUndefined; // is this instance undefined? BasicKString<> fKey; BasicKString<> fValue; diff --git a/dev/kernel/NeKit/KString.inl b/dev/kernel/NeKit/KString.inl index a0dd3623..1faefb08 100644 --- a/dev/kernel/NeKit/KString.inl +++ b/dev/kernel/NeKit/KString.inl @@ -19,22 +19,22 @@ inline void rt_string_append(Char* lhs, const Char* rhs, Int32 cur) { } } -template<> +template <> inline Char* BasicKString<>::Data() { return this->fData; } -template<> +template <> inline const Char* BasicKString<>::CData() const { return const_cast(this->fData); } -template<> +template <> inline SizeT BasicKString<>::Length() const { return this->fDataSz; } -template<> +template <> inline bool BasicKString<>::operator==(const BasicKString<>& rhs) const { if (rhs.Length() != this->Length()) return false; @@ -45,7 +45,7 @@ inline bool BasicKString<>::operator==(const BasicKString<>& rhs) const { return true; } -template<> +template <> inline bool BasicKString<>::operator==(const Char* rhs) const { if (rt_string_len(rhs) != this->Length()) return false; @@ -56,7 +56,7 @@ inline bool BasicKString<>::operator==(const Char* rhs) const { return true; } -template<> +template <> inline bool BasicKString<>::operator!=(const BasicKString<>& rhs) const { if (rhs.Length() != this->Length()) return false; @@ -67,7 +67,7 @@ inline bool BasicKString<>::operator!=(const BasicKString<>& rhs) const { return true; } -template<> +template <> inline bool BasicKString<>::operator!=(const Char* rhs) const { if (rt_string_len(rhs) != this->Length()) return false; @@ -78,7 +78,7 @@ inline bool BasicKString<>::operator!=(const Char* rhs) const { return true; } -template<> +template <> inline BasicKString<>& BasicKString<>::operator+=(const BasicKString<>& rhs) { if (rt_string_len(rhs.fData) > this->Length()) return *this; @@ -88,7 +88,7 @@ inline BasicKString<>& BasicKString<>::operator+=(const BasicKString<>& rhs) { return *this; } -template<> +template <> inline BasicKString<>& BasicKString<>::operator+=(const Char* rhs) { rt_string_append(this->fData, const_cast(rhs), this->fCur); this->fCur += rt_string_len(const_cast(rhs)); diff --git a/dev/kernel/src/FS/HeFS+FileSystemParser.cc b/dev/kernel/src/FS/HeFS+FileSystemParser.cc index 344369d5..f1531b4c 100644 --- a/dev/kernel/src/FS/HeFS+FileSystemParser.cc +++ b/dev/kernel/src/FS/HeFS+FileSystemParser.cc @@ -91,14 +91,14 @@ namespace Detail { STATIC UInt64 hefsi_hash_64(const Utf8Char* path) { if (!path || *path == 0) return 0; - const UInt64 FNV_OFFSET_BASIS = 0xcbf29ce484222325ULL; - const UInt64 FNV_PRIME = 0x100000001b3ULL; + const UInt64 kFnvBaseOffset = 0xcbf29ce484222325ULL; + const UInt64 kFnvPrimeNumber = 0x100000001b3ULL; - UInt64 hash = FNV_OFFSET_BASIS; + UInt64 hash = kFnvBaseOffset; while (*path) { hash ^= (Utf8Char) (*path++); - hash *= FNV_PRIME; + hash *= kFnvPrimeNumber; } return hefsi_to_big_endian_64(hash); -- 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') 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 From 10925d6b125dd6bd41b7bdc7332298f7bbb00b2f Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 22 Aug 2025 05:19:37 +0200 Subject: feat: strings: Fix function arugments of `urt_string_cmp` Signed-off-by: Amlal El Mahrouss --- dev/kernel/NeKit/Utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dev/kernel/NeKit') diff --git a/dev/kernel/NeKit/Utils.h b/dev/kernel/NeKit/Utils.h index 11566008..a7576e77 100644 --- a/dev/kernel/NeKit/Utils.h +++ b/dev/kernel/NeKit/Utils.h @@ -34,7 +34,7 @@ voidPtr rt_set_memory_safe(voidPtr dst, UInt32 value, Size len, Size dst_size); /// UNICODE API -Int urt_string_cmp(const Char* src, const Char* cmp, Size len); +Int urt_string_cmp(const Utf8Char* src, const Utf8Char* cmp, Size len); Void urt_set_memory(const voidPtr src, UInt32 dst, Size len); Int urt_copy_memory(const voidPtr src, voidPtr dst, Size len); Size urt_string_len(const Utf8Char* str); -- cgit v1.2.3