diff --git a/BeefLibs/corlib/src/Collections/HashSet.bf b/BeefLibs/corlib/src/Collections/HashSet.bf index bc26bfa1..08553cba 100644 --- a/BeefLibs/corlib/src/Collections/HashSet.bf +++ b/BeefLibs/corlib/src/Collections/HashSet.bf @@ -1217,14 +1217,14 @@ namespace System.Collections public int32 mNext; // Index of next entry, -1 if last } - public struct Enumerator : IEnumerator + public struct Enumerator : IRefEnumerator, IEnumerator { private HashSet mSet; private int_cosize mIndex; #if VERSION_HASHSET private int32 mVersion; #endif - private T mCurrent; + private T* mCurrent; public this(HashSet set) { @@ -1233,7 +1233,7 @@ namespace System.Collections #if VERSION_HASHSET mVersion = set.mVersion; #endif - mCurrent = default; + mCurrent = null; } #if VERSION_HASHSET @@ -1257,14 +1257,14 @@ namespace System.Collections { if (mSet.mSlots[mIndex].mHashCode >= 0) { - mCurrent = mSet.mSlots[mIndex].mValue; + mCurrent = &mSet.mSlots[mIndex].mValue; mIndex++; return true; } mIndex++; } mIndex = mSet.mLastIndex + 1; - mCurrent = default(T); + mCurrent = null; return false; } @@ -1272,7 +1272,15 @@ namespace System.Collections { get { - return mCurrent; + return *mCurrent; + } + } + + public ref T CurrentRef + { + get + { + return ref *mCurrent; } } @@ -1292,7 +1300,7 @@ namespace System.Collections CheckVersion(); #endif mIndex = 0; - mCurrent = default(T); + mCurrent = null; } public Result GetNext() mut @@ -1301,6 +1309,13 @@ namespace System.Collections return .Err; return Current; } + + public Result GetNextRef() mut + { + if (!MoveNext()) + return .Err; + return &CurrentRef; + } } }