4
4
5
5
#include "duk_internal.h"
6
6
7
+ /* FIXME: check if it's useful to compute the slotcache key only once in property code
8
+ * (live range is not trivial so maybe not).
9
+ */
10
+
11
+ DUK_LOCAL DUK_ALWAYS_INLINE duk_uint32_t duk__slotcache_compute_key (duk_hobject * obj , duk_hstring * key ) {
12
+ DUK_ASSERT (obj != NULL );
13
+ DUK_ASSERT (key != NULL );
14
+
15
+ return (((duk_uint32_t ) obj ) ^ DUK_HSTRING_GET_HASH (key )) & (DUK_HEAP_SLOTCACHE_SIZE - 1 );
16
+ }
17
+
18
+ DUK_INTERNAL duk_uint32_t duk_heap_slotcache_getkey (duk_hobject * obj , duk_hstring * key ) {
19
+ DUK_ASSERT (obj != NULL );
20
+ DUK_ASSERT (key != NULL );
21
+
22
+ return duk__slotcache_compute_key (obj , key );
23
+ }
24
+
7
25
DUK_INTERNAL duk_uint32_t duk_heap_slotcache_lookup (duk_heap * heap , duk_hobject * obj , duk_hstring * key ) {
8
26
duk_uint32_t idx ;
9
27
duk_slotcache_entry * ent ;
@@ -14,8 +32,8 @@ DUK_INTERNAL duk_uint32_t duk_heap_slotcache_lookup(duk_heap *heap, duk_hobject
14
32
15
33
/* FIXME: assert: hashlimit <= 256 */
16
34
17
- idx = (( duk_uint32_t ) obj ) ^ DUK_HSTRING_GET_HASH ( key );
18
- ent = heap -> slotcache + ( idx & ( DUK_HEAP_SLOTCACHE_SIZE - 1 )) ;
35
+ idx = duk__slotcache_compute_key ( obj , key );
36
+ ent = heap -> slotcache + idx ;
19
37
return ent -> slot ;
20
38
}
21
39
@@ -25,10 +43,10 @@ DUK_INTERNAL void duk_heap_slotcache_insert(duk_heap *heap, duk_hobject *obj, du
25
43
26
44
/* FIXME: assert: hashlimit <= 256 */
27
45
/* FIXME: skip check if hash part present and hashlimit correct */
28
- if (DUK_UNLIKELY (slot >= DUK_UINT16_MAX )) {
46
+ if (DUK_UNLIKELY (slot >= DUK_UINT8_MAX )) {
29
47
return ;
30
48
}
31
- idx = (( duk_uint32_t ) obj ) ^ DUK_HSTRING_GET_HASH ( key );
32
- ent = heap -> slotcache + ( idx & ( DUK_HEAP_SLOTCACHE_SIZE - 1 )) ;
49
+ idx = duk__slotcache_compute_key ( obj , key );
50
+ ent = heap -> slotcache + idx ;
33
51
ent -> slot = (duk_uint16_t ) slot ;
34
52
}
0 commit comments