Index: src/factory.cc |
diff --git a/src/factory.cc b/src/factory.cc |
index 796fd13c089f541c37f73ee2632fc3c1526cad77..e68ac9b6fa41e91586e547a311a247e4841c0436 100644 |
--- a/src/factory.cc |
+++ b/src/factory.cc |
@@ -2420,35 +2420,42 @@ Handle<JSFunction> Factory::CreateApiFunction( |
} |
-Handle<MapCache> Factory::AddToMapCache(Handle<Context> context, |
- Handle<FixedArray> keys, |
- Handle<Map> map) { |
- Handle<MapCache> map_cache = handle(MapCache::cast(context->map_cache())); |
- Handle<MapCache> result = MapCache::Put(map_cache, keys, map); |
- context->set_map_cache(*result); |
- return result; |
-} |
- |
- |
Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context, |
- Handle<FixedArray> keys) { |
+ int number_of_properties, |
+ bool* is_result_from_cache) { |
+ const int kMapCacheSize = 128; |
+ |
+ if (number_of_properties > kMapCacheSize) { |
+ *is_result_from_cache = false; |
+ return Map::Create(isolate(), number_of_properties); |
+ } |
+ *is_result_from_cache = true; |
+ if (number_of_properties == 0) { |
+ // Reuse the initial map of the Object function if the literal has no |
+ // predeclared properties. |
+ return handle(context->object_function()->initial_map(), isolate()); |
+ } |
+ int cache_index = number_of_properties - 1; |
if (context->map_cache()->IsUndefined()) { |
// Allocate the new map cache for the native context. |
- Handle<MapCache> new_cache = MapCache::New(isolate(), 24); |
+ Handle<FixedArray> new_cache = NewFixedArray(kMapCacheSize, TENURED); |
context->set_map_cache(*new_cache); |
} |
// Check to see whether there is a matching element in the cache. |
- Handle<MapCache> cache = |
- Handle<MapCache>(MapCache::cast(context->map_cache())); |
- Handle<Object> result = Handle<Object>(cache->Lookup(*keys), isolate()); |
- if (result->IsMap()) return Handle<Map>::cast(result); |
- int length = keys->length(); |
- // Create a new map and add it to the cache. Reuse the initial map of the |
- // Object function if the literal has no predeclared properties. |
- Handle<Map> map = length == 0 |
- ? handle(context->object_function()->initial_map()) |
- : Map::Create(isolate(), length); |
- AddToMapCache(context, keys, map); |
+ Handle<FixedArray> cache(FixedArray::cast(context->map_cache())); |
+ { |
+ Object* result = cache->get(cache_index); |
+ if (result->IsWeakCell()) { |
+ WeakCell* cell = WeakCell::cast(result); |
+ if (!cell->cleared()) { |
+ return handle(Map::cast(cell->value()), isolate()); |
+ } |
+ } |
+ } |
+ // Create a new map and add it to the cache. |
+ Handle<Map> map = Map::Create(isolate(), number_of_properties); |
+ Handle<WeakCell> cell = NewWeakCell(map); |
+ cache->set(cache_index, *cell); |
return map; |
} |
@@ -2467,6 +2474,7 @@ void Factory::SetRegExpAtomData(Handle<JSRegExp> regexp, |
regexp->set_data(*store); |
} |
+ |
void Factory::SetRegExpIrregexpData(Handle<JSRegExp> regexp, |
JSRegExp::Type type, |
Handle<String> source, |
@@ -2488,7 +2496,6 @@ void Factory::SetRegExpIrregexpData(Handle<JSRegExp> regexp, |
} |
- |
MaybeHandle<FunctionTemplateInfo> Factory::ConfigureInstance( |
Handle<FunctionTemplateInfo> desc, Handle<JSObject> instance) { |
// Configure the instance by adding the properties specified by the |