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

Unified Diff: src/factory.cc

Issue 4078: - Added a map cache for literal objects. This will... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 12 years, 3 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 | « src/factory.h ('k') | src/flag-definitions.h » ('j') | src/objects.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/factory.cc
===================================================================
--- src/factory.cc (revision 369)
+++ src/factory.cc (working copy)
@@ -211,12 +211,8 @@
// Store the object, regexp and array functions in the literals
// array prefix. These functions will be used when creating
// object, regexp and array literals in this function.
- literals->set(JSFunction::kLiteralObjectFunctionIndex,
- context->global_context()->object_function());
- literals->set(JSFunction::kLiteralRegExpFunctionIndex,
- context->global_context()->regexp_function());
- literals->set(JSFunction::kLiteralArrayFunctionIndex,
- context->global_context()->array_function());
+ literals->set(JSFunction::kLiteralGlobalContextIndex,
+ context->global_context());
}
result->set_literals(*literals);
ASSERT(!result->IsBoilerplate());
@@ -558,6 +554,12 @@
}
+Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map) {
+ CALL_HEAP_FUNCTION(Heap::AllocateJSObjectFromMap(*map, NOT_TENURED),
+ JSObject);
+}
+
+
Handle<JSObject> Factory::NewObjectLiteral(int expected_number_of_properties) {
Handle<Map> map = Handle<Map>(Top::object_function()->initial_map());
map = Factory::CopyMap(map);
@@ -749,6 +751,47 @@
}
+Handle<MapCache> Factory::NewMapCache(int at_least_space_for) {
+ CALL_HEAP_FUNCTION(MapCache::Allocate(at_least_space_for), MapCache);
+}
+
+
+static Object* UpdateMapCacheWith(Context* context,
+ FixedArray* keys,
+ Map* map) {
+ Object* result = MapCache::cast(context->map_cache())->Put(keys, map);
+ if (!result->IsFailure()) context->set_map_cache(MapCache::cast(result));
+ return result;
+}
+
+
+Handle<MapCache> Factory::AddToMapCache(Handle<Context> context,
+ Handle<FixedArray> keys,
Mads Ager (chromium) 2008/09/25 07:23:19 Indentation slightly off here.
+ Handle<Map> map) {
+ CALL_HEAP_FUNCTION(UpdateMapCacheWith(*context, *keys, *map), MapCache);
+}
+
+
+Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
+ Handle<FixedArray> keys) {
+ if (context->map_cache()->IsUndefined()) {
+ // Allocate the new map cache for the global context.
+ Handle<MapCache> new_cache = NewMapCache(24);
+ context->set_map_cache(*new_cache);
+ }
+ // Check to see whether there is a maching element in the cache.
+ Handle<MapCache> cache =
+ Handle<MapCache>(MapCache::cast(context->map_cache()));
+ Handle<Object> result = Handle<Object>(cache->Lookup(*keys));
+ if (result->IsMap()) return Handle<Map>::cast(result);
+ // Create a new map and add it to the cache.
+ Handle<Map> map =
+ CopyMap(Handle<Map>(context->object_function()->initial_map()));
+ AddToMapCache(context, keys, map);
+ return Handle<Map>(map);
+}
+
+
void Factory::ConfigureInstance(Handle<FunctionTemplateInfo> desc,
Handle<JSObject> instance,
bool* pending_exception) {
« no previous file with comments | « src/factory.h ('k') | src/flag-definitions.h » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698