Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Unified Diff: src/factory.cc

Issue 1159623008: Fix redundant map allocation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Correcter casting Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index f4b609a7f94fd882faacfe89847d8c495cf58456..daf4d27847d774d9edbd62dc3b8a8937398520b0 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -2384,29 +2384,20 @@ Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
: context->object_function()->initial_map(), isolate());
}
- // Create a new map and add it to the cache.
- Handle<Map> map = Map::Create(isolate(), number_of_properties);
int cache_index = number_of_properties - 1;
- Handle<FixedArray> cache;
- if (is_strong) {
- map->set_is_strong();
- if (context->strong_map_cache()->IsUndefined()) {
- // Allocate the new map cache for the native context.
- Handle<FixedArray> new_cache = NewFixedArray(kMapCacheSize, TENURED);
- context->set_strong_map_cache(*new_cache);
+ Handle<Object> maybe_cache(is_strong ? context->strong_map_cache()
+ : context->map_cache(), isolate());
+ if (maybe_cache->IsUndefined()) {
+ // Allocate the new map cache for the native context.
+ maybe_cache = NewFixedArray(kMapCacheSize, TENURED);
+ if (is_strong) {
+ context->set_strong_map_cache(*maybe_cache);
+ } else {
+ context->set_map_cache(*maybe_cache);
}
- // Check to see whether there is a matching element in the cache.
- cache = handle(FixedArray::cast(context->strong_map_cache()));
} else {
- if (context->map_cache()->IsUndefined()) {
- // Allocate the new map cache for the native context.
- 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.
- cache = handle(FixedArray::cast(context->map_cache()));
- }
- {
+ Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache);
Object* result = cache->get(cache_index);
if (result->IsWeakCell()) {
WeakCell* cell = WeakCell::cast(result);
@@ -2415,6 +2406,10 @@ Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
}
}
}
+ // Create a new map and add it to the cache.
+ Handle<FixedArray> cache = Handle<FixedArray>::cast(maybe_cache);
+ Handle<Map> map = Map::Create(isolate(), number_of_properties);
+ if (is_strong) map->set_is_strong();
Handle<WeakCell> cell = NewWeakCell(map);
cache->set(cache_index, *cell);
return map;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698