-
Notifications
You must be signed in to change notification settings - Fork 0
/
strudelify-mri.patch
201 lines (178 loc) · 5.38 KB
/
strudelify-mri.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
commit b7254751953c3a9d6789ae17444616116cbce5f9
Author: Ryan Lopopolo <rjl@hyperbo.la>
Date: Wed Jul 8 15:45:41 2020 -0700
Patch strudel hash backend into MRI
diff --git a/st.c b/st.c
index ed235c674e..7c49e38d00 100644
--- a/st.c
+++ b/st.c
@@ -139,6 +139,8 @@ struct st_table_entry {
st_data_t record;
};
+#ifndef STRUDEL
+
#define type_numhash st_hashtype_num
static const struct st_hash_type st_hashtype_num = {
st_numcmp,
@@ -158,6 +160,8 @@ static const struct st_hash_type type_strcasehash = {
strcasehash,
};
+#endif
+
/* Value used to catch uninitialized entries/bins during debugging.
There is a possibility for a false alarm, but its probability is
extremely small. */
@@ -188,6 +192,8 @@ static const struct st_hash_type type_strcasehash = {
rebuilt_p = _old_rebuilds_num != (tab)->rebuilds_num; \
} while (FALSE)
+#ifndef STRUDEL
+
/* Features of a table. */
struct st_features {
/* Power of 2 used for number of allocated entries. */
@@ -311,6 +317,8 @@ static const struct st_features features[] = {
#endif
+#endif
+
/* The reserved hash value and its substitution. */
#define RESERVED_HASH_VAL (~(st_hash_t) 0)
#define RESERVED_HASH_SUBSTITUTION_VAL ((st_hash_t) 0)
@@ -318,6 +326,8 @@ static const struct st_features features[] = {
const st_hash_t st_reserved_hash_val = RESERVED_HASH_VAL;
const st_hash_t st_reserved_hash_substitution_val = RESERVED_HASH_SUBSTITUTION_VAL;
+#ifndef STRUDEL
+
/* Return hash value of KEY for table TAB. */
static inline st_hash_t
do_hash(st_data_t key, st_table *tab)
@@ -489,6 +499,8 @@ make_tab_empty(st_table *tab)
initialize_bins(tab);
}
+#endif
+
#ifdef ST_DEBUG
#define st_assert_notinitial(ent) \
do { \
@@ -570,6 +582,7 @@ stat_col(void)
}
#endif
+#ifndef STRUDEL
/* Create and return table with TYPE which can hold at least SIZE
entries. The real number of entries which the table can hold is
the nearest power of two for SIZE. */
@@ -702,6 +715,10 @@ st_memsize(const st_table *tab)
+ get_allocated_entries(tab) * sizeof(st_table_entry));
}
+#endif
+
+#ifndef STRUDEL
+
static st_index_t
find_table_entry_ind(st_table *tab, st_hash_t hash_value, st_data_t key);
@@ -1074,6 +1091,10 @@ find_table_bin_ptr_and_reserve(st_table *tab, st_hash_t *hash_value,
return entry_index;
}
+#endif
+
+#ifndef STRUDEL
+
/* Find an entry with KEY in table TAB. Return non-zero if we found
it. Set up *RECORD to the found entry record. */
int
@@ -1132,6 +1153,10 @@ st_get_key(st_table *tab, st_data_t key, st_data_t *result)
return 1;
}
+#endif
+
+#ifndef STRUDEL
+
/* Check the table and rebuild it if it is necessary. */
static inline void
rebuild_table_if_necessary (st_table *tab)
@@ -1143,6 +1168,10 @@ rebuild_table_if_necessary (st_table *tab)
st_assert(tab->entries_bound < get_allocated_entries(tab));
}
+#endif
+
+#ifndef STRUDEL
+
/* Insert (KEY, VALUE) into table TAB and return zero. If there is
already entry with KEY in the table, return nonzero and and update
the value of the found entry. */
@@ -1737,6 +1766,8 @@ st_values_check(st_table *tab, st_data_t *values, st_index_t size,
return st_general_values(tab, values, size);
}
+#endif
+
#define FNV1_32A_INIT 0x811c9dc5
/*
@@ -1769,6 +1800,9 @@ st_values_check(st_table *tab, st_data_t *values, st_index_t size,
#define C1 BIG_CONSTANT(0x87c37b91,0x114253d5);
#define C2 BIG_CONSTANT(0x4cf5ad43,0x2745937f);
#endif
+
+#ifndef STRUDEL
+
NO_SANITIZE("unsigned-integer-overflow", static inline st_index_t murmur_step(st_index_t h, st_index_t k));
NO_SANITIZE("unsigned-integer-overflow", static inline st_index_t murmur_finish(st_index_t h));
NO_SANITIZE("unsigned-integer-overflow", extern st_index_t st_hash(const void *ptr, size_t len, st_index_t h));
@@ -2237,6 +2271,8 @@ st_rehash(st_table *tab)
} while (rebuilt_p);
}
+#endif
+
#ifdef RUBY
static st_data_t
st_stringify(VALUE key)
@@ -2245,6 +2281,8 @@ st_stringify(VALUE key)
rb_hash_key_str(key) : key;
}
+#ifndef STRUDEL
+
static void
st_insert_single(st_table *tab, VALUE hash, VALUE key, VALUE val)
{
@@ -2260,6 +2298,8 @@ st_insert_single(st_table *tab, VALUE hash, VALUE key, VALUE val)
RB_OBJ_WRITTEN(hash, Qundef, val);
}
+#endif
+
static void
st_insert_linear(st_table *tab, long argc, const VALUE *argv, VALUE hash)
{
@@ -2274,6 +2314,8 @@ st_insert_linear(st_table *tab, long argc, const VALUE *argv, VALUE hash)
}
}
+#ifndef STRUDEL
+
static void
st_insert_generic(st_table *tab, long argc, const VALUE *argv, VALUE hash)
{
@@ -2290,15 +2332,20 @@ st_insert_generic(st_table *tab, long argc, const VALUE *argv, VALUE hash)
st_rehash(tab);
}
+#endif
+
/* Mimics ruby's { foo => bar } syntax. This function is subpart
of rb_hash_bulk_insert. */
void
rb_hash_bulk_insert_into_st_table(long argc, const VALUE *argv, VALUE hash)
{
+#ifndef STRUDEL
st_index_t n, size = argc / 2;
+#endif
st_table *tab = RHASH_ST_TABLE(hash);
tab = RHASH_TBL_RAW(hash);
+#ifndef STRUDEL
n = tab->entries_bound + size;
st_expand_table(tab, n);
if (UNLIKELY(tab->num_entries))
@@ -2309,5 +2356,8 @@ rb_hash_bulk_insert_into_st_table(long argc, const VALUE *argv, VALUE hash)
st_insert_linear(tab, argc, argv, hash);
else
st_insert_generic(tab, argc, argv, hash);
+#else
+ st_insert_linear(tab, argc, argv, hash);
+#endif
}
#endif