Skip to content

Commit 12d611b

Browse files
authored
Update Sys.Collections to use key hash code as parameter (#3025)
***NO_CI***
1 parent b00c7fc commit 12d611b

File tree

3 files changed

+38
-23
lines changed

3 files changed

+38
-23
lines changed

src/nanoFramework.System.Collections/nf_system_collections.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ static const CLR_RT_MethodHandler method_lookup[] =
3535
NULL,
3636
NULL,
3737
Library_nf_system_collections_System_Collections_Hashtable::Clear___VOID,
38-
Library_nf_system_collections_System_Collections_Hashtable::Contains___BOOLEAN__OBJECT,
39-
Library_nf_system_collections_System_Collections_Hashtable::Remove___VOID__OBJECT,
4038
NULL,
4139
NULL,
4240
NULL,
4341
NULL,
4442
NULL,
45-
Library_nf_system_collections_System_Collections_Hashtable::InsertNative___VOID__OBJECT__OBJECT__BOOLEAN,
46-
Library_nf_system_collections_System_Collections_Hashtable::GetNative___OBJECT__OBJECT,
43+
NULL,
44+
NULL,
45+
Library_nf_system_collections_System_Collections_Hashtable::InsertNative___VOID__OBJECT__OBJECT__BOOLEAN__I4,
46+
Library_nf_system_collections_System_Collections_Hashtable::GetNative___OBJECT__OBJECT__I4,
47+
Library_nf_system_collections_System_Collections_Hashtable::ContainsNative___BOOLEAN__OBJECT__I4,
48+
Library_nf_system_collections_System_Collections_Hashtable::RemoveNative___VOID__OBJECT__I4,
4749
Library_nf_system_collections_System_Collections_Hashtable::GetPrimeNative___STATIC__I4__I4,
4850
NULL,
4951
NULL,
@@ -100,9 +102,9 @@ static const CLR_RT_MethodHandler method_lookup[] =
100102
const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_nanoFramework_System_Collections =
101103
{
102104
"nanoFramework.System.Collections",
103-
0x2DC2B090,
105+
0x40DC251F,
104106
method_lookup,
105-
{ 100, 0, 1, 0 }
107+
{ 100, 0, 2, 0 }
106108
};
107109

108110
// clang-format on

src/nanoFramework.System.Collections/nf_system_collections.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ struct Library_nf_system_collections_System_Collections_Hashtable
3131
static const int FIELD___version = 5;
3232

3333
NANOCLR_NATIVE_DECLARE(Clear___VOID);
34-
NANOCLR_NATIVE_DECLARE(Contains___BOOLEAN__OBJECT);
35-
NANOCLR_NATIVE_DECLARE(Remove___VOID__OBJECT);
36-
NANOCLR_NATIVE_DECLARE(InsertNative___VOID__OBJECT__OBJECT__BOOLEAN);
37-
NANOCLR_NATIVE_DECLARE(GetNative___OBJECT__OBJECT);
34+
NANOCLR_NATIVE_DECLARE(InsertNative___VOID__OBJECT__OBJECT__BOOLEAN__I4);
35+
NANOCLR_NATIVE_DECLARE(GetNative___OBJECT__OBJECT__I4);
36+
NANOCLR_NATIVE_DECLARE(ContainsNative___BOOLEAN__OBJECT__I4);
37+
NANOCLR_NATIVE_DECLARE(RemoveNative___VOID__OBJECT__I4);
3838
NANOCLR_NATIVE_DECLARE(GetPrimeNative___STATIC__I4__I4);
3939

4040
//--//
4141

4242
static HRESULT Expand(CLR_RT_StackFrame &stack);
43-
static uint32_t InitHash(CLR_RT_HeapBlock *key, int32_t hashsize, uint32_t *seed, uint32_t *incr);
43+
static uint32_t InitHash(const int32_t keyHashCode, int32_t hashsize, uint32_t *seed, uint32_t *incr);
4444
};
4545

4646
struct Library_nf_system_collections_System_Collections_Hashtable__HashtableEnumerator

src/nanoFramework.System.Collections/nf_system_collections_System_Collections_Hashtable.cpp

+25-12
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@ HRESULT Library_nf_system_collections_System_Collections_Hashtable::Clear___VOID
6262
NANOCLR_NOCLEANUP();
6363
}
6464

65-
HRESULT Library_nf_system_collections_System_Collections_Hashtable::Contains___BOOLEAN__OBJECT(CLR_RT_StackFrame &stack)
65+
HRESULT Library_nf_system_collections_System_Collections_Hashtable::ContainsNative___BOOLEAN__OBJECT__I4(
66+
CLR_RT_StackFrame &stack)
6667
{
6768
NANOCLR_HEADER();
6869

6970
int32_t entry = 0;
7071
int32_t bucketNumber;
7172
uint32_t hashcode;
73+
int32_t keyHashCode;
7274
uint32_t seed;
7375
uint32_t incr;
7476
int32_t bucketsLength;
@@ -85,10 +87,12 @@ HRESULT Library_nf_system_collections_System_Collections_Hashtable::Contains___B
8587
key = stack.Arg1().Dereference();
8688
FAULT_ON_NULL_ARG(key);
8789

90+
keyHashCode = stack.Arg2().NumericByRef().s4;
91+
8892
buckets = pThis[FIELD___buckets].DereferenceArray();
8993
bucketsLength = buckets->m_numOfElements;
9094

91-
hashcode = InitHash(key, bucketsLength, &seed, &incr);
95+
hashcode = InitHash(keyHashCode, bucketsLength, &seed, &incr);
9296

9397
bucketNumber = (int)(seed % (uint32_t)bucketsLength);
9498

@@ -117,13 +121,15 @@ HRESULT Library_nf_system_collections_System_Collections_Hashtable::Contains___B
117121
NANOCLR_NOCLEANUP();
118122
}
119123

120-
HRESULT Library_nf_system_collections_System_Collections_Hashtable::Remove___VOID__OBJECT(CLR_RT_StackFrame &stack)
124+
HRESULT Library_nf_system_collections_System_Collections_Hashtable::RemoveNative___VOID__OBJECT__I4(
125+
CLR_RT_StackFrame &stack)
121126
{
122127
NANOCLR_HEADER();
123128

124129
int32_t entry = 0;
125130
int32_t bucketNumber;
126131
uint32_t hashcode;
132+
int32_t keyHashCode;
127133
uint32_t seed;
128134
uint32_t incr;
129135
int32_t bucketsLength;
@@ -140,10 +146,12 @@ HRESULT Library_nf_system_collections_System_Collections_Hashtable::Remove___VOI
140146
key = stack.Arg1().Dereference();
141147
FAULT_ON_NULL_ARG(key);
142148

149+
keyHashCode = stack.Arg2().NumericByRef().s4;
150+
143151
buckets = pThis[FIELD___buckets].DereferenceArray();
144152
bucketsLength = buckets->m_numOfElements;
145153

146-
hashcode = InitHash(key, bucketsLength, &seed, &incr);
154+
hashcode = InitHash(keyHashCode, bucketsLength, &seed, &incr);
147155

148156
bucketNumber = (int)(seed % (uint32_t)bucketsLength);
149157

@@ -178,7 +186,7 @@ HRESULT Library_nf_system_collections_System_Collections_Hashtable::Remove___VOI
178186
NANOCLR_NOCLEANUP();
179187
}
180188

181-
HRESULT Library_nf_system_collections_System_Collections_Hashtable::InsertNative___VOID__OBJECT__OBJECT__BOOLEAN(
189+
HRESULT Library_nf_system_collections_System_Collections_Hashtable::InsertNative___VOID__OBJECT__OBJECT__BOOLEAN__I4(
182190
CLR_RT_StackFrame &stack)
183191
{
184192
NANOCLR_HEADER();
@@ -187,6 +195,7 @@ HRESULT Library_nf_system_collections_System_Collections_Hashtable::InsertNative
187195
uint32_t entry = 0;
188196
int32_t bucketNumber;
189197
uint32_t hashcode;
198+
int32_t keyHashCode;
190199
uint32_t seed;
191200
uint32_t incr;
192201
uint32_t bucketsLength;
@@ -208,6 +217,8 @@ HRESULT Library_nf_system_collections_System_Collections_Hashtable::InsertNative
208217

209218
add = (bool)stack.Arg3().NumericByRef().u1;
210219

220+
keyHashCode = stack.Arg4().NumericByRef().s4;
221+
211222
if (pThis[FIELD___count].NumericByRef().s4 >= pThis[FIELD___loadsize].NumericByRef().s4)
212223
{
213224
NANOCLR_CHECK_HRESULT(Expand(stack));
@@ -216,7 +227,7 @@ HRESULT Library_nf_system_collections_System_Collections_Hashtable::InsertNative
216227
buckets = pThis[FIELD___buckets].DereferenceArray();
217228
bucketsLength = buckets->m_numOfElements;
218229

219-
hashcode = InitHash(key, bucketsLength, &seed, &incr);
230+
hashcode = InitHash(keyHashCode, bucketsLength, &seed, &incr);
220231

221232
bucketNumber = (int)(seed % bucketsLength);
222233

@@ -286,13 +297,15 @@ HRESULT Library_nf_system_collections_System_Collections_Hashtable::InsertNative
286297
NANOCLR_NOCLEANUP();
287298
}
288299

289-
HRESULT Library_nf_system_collections_System_Collections_Hashtable::GetNative___OBJECT__OBJECT(CLR_RT_StackFrame &stack)
300+
HRESULT Library_nf_system_collections_System_Collections_Hashtable::GetNative___OBJECT__OBJECT__I4(
301+
CLR_RT_StackFrame &stack)
290302
{
291303
NANOCLR_HEADER();
292304

293305
int32_t entry = 0;
294306
int32_t bucketNumber;
295307
uint32_t hashcode;
308+
int32_t keyHashCode;
296309
uint32_t seed;
297310
uint32_t incr;
298311
int32_t bucketsLength;
@@ -309,10 +322,12 @@ HRESULT Library_nf_system_collections_System_Collections_Hashtable::GetNative___
309322
key = stack.Arg1().Dereference();
310323
FAULT_ON_NULL_ARG(key);
311324

325+
keyHashCode = stack.Arg2().NumericByRef().s4;
326+
312327
buckets = pThis[FIELD___buckets].DereferenceArray();
313328
bucketsLength = buckets->m_numOfElements;
314329

315-
hashcode = InitHash(key, bucketsLength, &seed, &incr);
330+
hashcode = InitHash(keyHashCode, bucketsLength, &seed, &incr);
316331

317332
bucketNumber = (int)(seed % (uint32_t)bucketsLength);
318333

@@ -485,15 +500,13 @@ HRESULT Library_nf_system_collections_System_Collections_Hashtable::Expand(CLR_R
485500
}
486501

487502
uint32_t Library_nf_system_collections_System_Collections_Hashtable::InitHash(
488-
CLR_RT_HeapBlock *key,
503+
const int32_t keyHashCode,
489504
int32_t hashsize,
490505
uint32_t *seed,
491506
uint32_t *incr)
492507
{
493-
uint32_t hashcode;
508+
uint32_t hashcode = keyHashCode;
494509

495-
// compute hash code for key
496-
hashcode = CLR_RT_HeapBlock::GetHashCode(key, true, 0);
497510
*seed = hashcode;
498511

499512
// compute and store incr value

0 commit comments

Comments
 (0)