@@ -45,7 +45,7 @@ public LuaValue this[LuaValue key]
4545 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4646 get
4747 {
48- ref LuaValue value = ref FindValue ( key ) ;
48+ ref LuaValue value = ref FindValue ( key , out _ ) ;
4949 if ( ! Unsafe . IsNullRef ( ref value ) )
5050 {
5151 return value ;
@@ -77,7 +77,7 @@ public void Clear()
7777 }
7878
7979 public bool ContainsKey ( LuaValue key ) =>
80- ! Unsafe . IsNullRef ( ref FindValue ( key ) ) ;
80+ ! Unsafe . IsNullRef ( ref FindValue ( key , out _ ) ) ;
8181
8282 public bool ContainsValue ( LuaValue value )
8383 {
@@ -97,8 +97,9 @@ public bool ContainsValue(LuaValue value)
9797
9898 public Enumerator GetEnumerator ( ) => new Enumerator ( this ) ;
9999
100- internal ref LuaValue FindValue ( LuaValue key )
100+ internal ref LuaValue FindValue ( LuaValue key , out int index )
101101 {
102+ index = - 1 ;
102103 ref Entry entry = ref Unsafe . NullRef < Entry > ( ) ;
103104 if ( _buckets != null )
104105 {
@@ -123,6 +124,7 @@ internal ref LuaValue FindValue(LuaValue key)
123124 entry = ref entries [ i ] ;
124125 if ( entry . hashCode == hashCode && entry . key . Equals ( key ) )
125126 {
127+ index = i ;
126128 goto ReturnFound ;
127129 }
128130
@@ -352,7 +354,7 @@ public bool Remove(LuaValue key)
352354 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
353355 public bool TryGetValue ( LuaValue key , out LuaValue value )
354356 {
355- ref LuaValue valRef = ref FindValue ( key ) ;
357+ ref LuaValue valRef = ref FindValue ( key , out _ ) ;
356358 if ( ! Unsafe . IsNullRef ( ref valRef ) )
357359 {
358360 value = valRef ;
@@ -363,6 +365,27 @@ public bool TryGetValue(LuaValue key, out LuaValue value)
363365 return false ;
364366 }
365367
368+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
369+ public bool TryGetNext ( LuaValue key , out KeyValuePair < LuaValue , LuaValue > pair )
370+ {
371+ ref LuaValue valRef = ref FindValue ( key , out var index ) ;
372+ if ( ! Unsafe . IsNullRef ( ref valRef ) )
373+ {
374+ Entry [ ] entries = _entries ! ;
375+ while ( ++ index < _count )
376+ {
377+ ref Entry entry = ref entries [ index ] ;
378+ if ( entry is { next : >= - 1 , value . Type : not LuaValueType . Nil } )
379+ {
380+ pair = new ( entry . key , entry . value ) ;
381+ return true ;
382+ }
383+ }
384+ }
385+
386+ pair = default ;
387+ return false ;
388+ }
366389
367390 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
368391 private ref int GetBucket ( uint hashCode )
@@ -428,6 +451,7 @@ public bool MoveNext()
428451
429452 public KeyValuePair < LuaValue , LuaValue > Current => _current ;
430453 }
454+
431455 static class ThrowHelper
432456 {
433457 public static void ThrowInvalidOperationException_ConcurrentOperationsNotSupported ( )
0 commit comments