diff --git a/Redcraft.Utility/Source/Public/Containers/Array.h b/Redcraft.Utility/Source/Public/Containers/Array.h index d5adbea..90b7d9f 100644 --- a/Redcraft.Utility/Source/Public/Containers/Array.h +++ b/Redcraft.Utility/Source/Public/Containers/Array.h @@ -288,38 +288,22 @@ public: { if (LHS.Num() != RHS.Num()) return false; - ConstIterator LHSIter = LHS.Begin(); - ConstIterator RHSIter = RHS.Begin(); - - while (LHSIter != LHS.End()) + for (size_t Index = 0; Index < LHS.Num(); ++Index) { - if (*LHSIter != *RHSIter) return false; - - ++LHSIter; - ++RHSIter; + if (LHS[Index] != RHS[Index]) return false; } - check(RHSIter == RHS.End()); - return true; } /** Compares the contents of 'LHS' and 'RHS' lexicographically. */ NODISCARD friend auto operator<=>(const TArray& LHS, const TArray& RHS) requires (CSynthThreeWayComparable) { - using OrderingType = TSynthThreeWayResult; + const size_t NumToCompare = LHS.Num() < RHS.Num() ? LHS.Num() : RHS.Num(); - ConstIterator LHSIter = LHS.Begin(); - ConstIterator RHSIter = RHS.Begin(); - - while (LHSIter != LHS.End() || RHSIter != RHS.End()) + for (size_t Index = 0; Index < NumToCompare; ++Index) { - TSynthThreeWayResult Ordering = SynthThreeWayCompare(*LHSIter, *RHSIter); - - if (Ordering != OrderingType::equivalent) return Ordering; - - ++LHSIter; - ++RHSIter; + if (const auto Result = SynthThreeWayCompare(LHS[Index], RHS[Index]); Result != 0) return Result; } return LHS.Num() <=> RHS.Num(); diff --git a/Redcraft.Utility/Source/Public/Containers/ArrayView.h b/Redcraft.Utility/Source/Public/Containers/ArrayView.h index c18f68f..06f0ae9 100644 --- a/Redcraft.Utility/Source/Public/Containers/ArrayView.h +++ b/Redcraft.Utility/Source/Public/Containers/ArrayView.h @@ -134,46 +134,25 @@ public: { if (LHS.Num() != RHS.Num()) return false; - Iterator LHSIter = LHS.Begin(); - Iterator RHSIter = RHS.Begin(); - - while (LHSIter != LHS.End()) + for (size_t Index = 0; Index < LHS.Num(); ++Index) { - if (*LHSIter != *RHSIter) return false; - - ++LHSIter; - ++RHSIter; + if (LHS[Index] != RHS[Index]) return false; } - check(RHSIter == RHS.End()); - return true; } /** Compares the contents of two array views. */ NODISCARD friend constexpr auto operator<=>(TArrayView LHS, TArrayView RHS) requires (CSynthThreeWayComparable) { - using OrderingType = TSynthThreeWayResult; + const size_t NumToCompare = LHS.Num() < RHS.Num() ? LHS.Num() : RHS.Num(); - if (LHS.Num() < RHS.Num()) return OrderingType::less; - if (LHS.Num() > RHS.Num()) return OrderingType::greater; - - Iterator LHSIter = LHS.Begin(); - Iterator RHSIter = RHS.Begin(); - - while (LHSIter != LHS.End()) + for (size_t Index = 0; Index < NumToCompare; ++Index) { - TSynthThreeWayResult Ordering = SynthThreeWayCompare(*LHSIter, *RHSIter); - - if (Ordering != OrderingType::equivalent) return Ordering; - - ++LHSIter; - ++RHSIter; + if (const auto Result = SynthThreeWayCompare(LHS[Index], RHS[Index]); Result != 0) return Result; } - check(RHSIter == RHS.End()); - - return OrderingType::equivalent; + return LHS.Num() <=> RHS.Num(); } /** Obtains an array view that is a view over the first 'Count' elements of this array view. */ diff --git a/Redcraft.Utility/Source/Public/Containers/StaticArray.h b/Redcraft.Utility/Source/Public/Containers/StaticArray.h index d6fad67..c7c4dd3 100644 --- a/Redcraft.Utility/Source/Public/Containers/StaticArray.h +++ b/Redcraft.Utility/Source/Public/Containers/StaticArray.h @@ -46,38 +46,22 @@ public: { if (LHS.Num() != RHS.Num()) return false; - ConstIterator LHSIter = LHS.Begin(); - ConstIterator RHSIter = RHS.Begin(); - - while (LHSIter != LHS.End()) + for (size_t Index = 0; Index < LHS.Num(); ++Index) { - if (*LHSIter != *RHSIter) return false; - - ++LHSIter; - ++RHSIter; + if (LHS[Index] != RHS[Index]) return false; } - check(RHSIter == RHS.End()); - return true; } /** Compares the contents of 'LHS' and 'RHS' lexicographically. */ NODISCARD friend constexpr auto operator<=>(const TStaticArray& LHS, const TStaticArray& RHS) requires (CSynthThreeWayComparable) { - using OrderingType = TSynthThreeWayResult; + const size_t NumToCompare = LHS.Num() < RHS.Num() ? LHS.Num() : RHS.Num(); - ConstIterator LHSIter = LHS.Begin(); - ConstIterator RHSIter = RHS.Begin(); - - while (LHSIter != LHS.End() || RHSIter != RHS.End()) + for (size_t Index = 0; Index < NumToCompare; ++Index) { - TSynthThreeWayResult Ordering = SynthThreeWayCompare(*LHSIter, *RHSIter); - - if (Ordering != OrderingType::equivalent) return Ordering; - - ++LHSIter; - ++RHSIter; + if (const auto Result = SynthThreeWayCompare(LHS[Index], RHS[Index]); Result != 0) return Result; } return LHS.Num() <=> RHS.Num();