@@ -207,36 +207,33 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
207207}
208208
209209
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) {
212212 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 );
224224}
225225
226226
227227MaybeHandle<JSFunction> InstantiateFunction (Isolate* isolate,
228228 Handle<FunctionTemplateInfo> data,
229229 Handle<Name> name) {
230- int serial_number = Smi::cast (data->serial_number ())-> value ( );
230+ auto serial_number = handle ( Smi::cast (data->serial_number ()), isolate );
231231 // Probe cache.
232232 if (!data->do_not_cache ()) {
233233 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);
240237 }
241238 }
242239 // Enter a new scope. Recursion could otherwise create a lot of handles.
@@ -279,15 +276,14 @@ MaybeHandle<JSFunction> InstantiateFunction(Isolate* isolate,
279276 function->shared ()->set_name (*name);
280277 }
281278 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);
284281 }
285282 auto result = ConfigureInstance (isolate, function, data);
286283 if (result.is_null ()) {
287- // uncache on error.
284+ // Uncache on error.
288285 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);
291287 }
292288 return MaybeHandle<JSFunction>();
293289 }
0 commit comments