@@ -207,36 +207,33 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
207
207
}
208
208
209
209
210
- void InstallInCache (Isolate* isolate, int serial_number,
211
- Handle <JSFunction> function) {
210
+ void CacheFunction (Isolate* isolate, Handle <Smi> serial_number,
211
+ Handle <JSFunction> function) {
212
212
auto cache = isolate->function_cache ();
213
- if (cache-> length () <= serial_number) {
214
- int new_size ;
215
- if (isolate-> next_serial_number () < 50 ) {
216
- new_size = 100 ;
217
- } else {
218
- new_size = 3 * isolate-> next_serial_number () / 2 ;
219
- }
220
- cache = FixedArray::CopySize (cache, new_size) ;
221
- isolate-> native_context ()-> set_function_cache (* cache);
222
- }
223
- cache-> set (serial_number, *function );
213
+ auto new_cache = ObjectHashTable::Put (cache, serial_number, function);
214
+ isolate-> native_context ()-> set_function_cache (*new_cache) ;
215
+ }
216
+
217
+
218
+ void UncacheFunction (Isolate * isolate, Handle <Smi> serial_number) {
219
+ auto cache = isolate-> function_cache ();
220
+ bool was_present = false ;
221
+ auto new_cache = ObjectHashTable::Remove ( cache, serial_number, &was_present );
222
+ DCHECK (was_present);
223
+ isolate-> native_context ()-> set_function_cache (*new_cache );
224
224
}
225
225
226
226
227
227
MaybeHandle<JSFunction> InstantiateFunction (Isolate* isolate,
228
228
Handle <FunctionTemplateInfo> data,
229
229
Handle <Name> name) {
230
- int serial_number = Smi::cast (data->serial_number ())-> value ( );
230
+ auto serial_number = handle ( Smi::cast (data->serial_number ()), isolate );
231
231
// Probe cache.
232
232
if (!data->do_not_cache ()) {
233
233
auto cache = isolate->function_cache ();
234
- // Fast case: see if the function has already been instantiated
235
- if (serial_number < cache->length ()) {
236
- Handle <Object> element = FixedArray::get (cache, serial_number);
237
- if (element->IsJSFunction ()) {
238
- return Handle <JSFunction>::cast (element);
239
- }
234
+ Object* element = cache->Lookup (serial_number);
235
+ if (element->IsJSFunction ()) {
236
+ return handle (JSFunction::cast (element), isolate);
240
237
}
241
238
}
242
239
// Enter a new scope. Recursion could otherwise create a lot of handles.
@@ -279,15 +276,14 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
279
276
function->shared ()->set_name (*name);
280
277
}
281
278
if (!data->do_not_cache ()) {
282
- // Cache the function to limit recursion .
283
- InstallInCache (isolate, serial_number, function);
279
+ // Cache the function.
280
+ CacheFunction (isolate, serial_number, function);
284
281
}
285
282
auto result = ConfigureInstance (isolate, function, data);
286
283
if (result.is_null ()) {
287
- // uncache on error.
284
+ // Uncache on error.
288
285
if (!data->do_not_cache ()) {
289
- auto cache = isolate->function_cache ();
290
- cache->set (serial_number, isolate->heap ()->undefined_value ());
286
+ UncacheFunction (isolate, serial_number);
291
287
}
292
288
return MaybeHandle<JSFunction>();
293
289
}
0 commit comments