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

Side by Side Diff: src/runtime.cc

Issue 7016016: Extend the fast case of HasLocalProperty. (Closed)
Patch Set: Created 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 4148 matching lines...) Expand 10 before | Expand all | Expand 10 after
4159 } 4159 }
4160 return isolate->heap()->false_value(); 4160 return isolate->heap()->false_value();
4161 } 4161 }
4162 4162
4163 4163
4164 RUNTIME_FUNCTION(MaybeObject*, Runtime_HasLocalProperty) { 4164 RUNTIME_FUNCTION(MaybeObject*, Runtime_HasLocalProperty) {
4165 NoHandleAllocation ha; 4165 NoHandleAllocation ha;
4166 ASSERT(args.length() == 2); 4166 ASSERT(args.length() == 2);
4167 CONVERT_CHECKED(String, key, args[1]); 4167 CONVERT_CHECKED(String, key, args[1]);
4168 4168
4169 uint32_t index;
4170 const bool key_is_array_index = key->AsArrayIndex(&index);
4171
4169 Object* obj = args[0]; 4172 Object* obj = args[0];
4170 // Only JS objects can have properties. 4173 // Only JS objects can have properties.
4171 if (obj->IsJSObject()) { 4174 if (obj->IsJSObject()) {
4172 JSObject* object = JSObject::cast(obj); 4175 JSObject* object = JSObject::cast(obj);
4173 // Fast case - no interceptors. 4176 // Fast case: either the key is a real named property or it is not
4177 // an array index and there are no interceptors or hidden
4178 // prototypes.
4174 if (object->HasRealNamedProperty(key)) return isolate->heap()->true_value(); 4179 if (object->HasRealNamedProperty(key)) return isolate->heap()->true_value();
4175 // Slow case. Either it's not there or we have an interceptor. We should 4180 Map* map = object->map();
4176 // have handles for this kind of deal. 4181 if (!key_is_array_index &&
4182 !map->has_named_interceptor() &&
4183 !HeapObject::cast(map->prototype())->map()->is_hidden_prototype()) {
4184 return isolate->heap()->false_value();
4185 }
4186 // Slow case.
4177 HandleScope scope(isolate); 4187 HandleScope scope(isolate);
4178 return HasLocalPropertyImplementation(isolate, 4188 return HasLocalPropertyImplementation(isolate,
4179 Handle<JSObject>(object), 4189 Handle<JSObject>(object),
4180 Handle<String>(key)); 4190 Handle<String>(key));
4181 } else if (obj->IsString()) { 4191 } else if (obj->IsString() && key_is_array_index) {
4182 // Well, there is one exception: Handle [] on strings. 4192 // Well, there is one exception: Handle [] on strings.
4183 uint32_t index; 4193 String* string = String::cast(obj);
4184 if (key->AsArrayIndex(&index)) { 4194 if (index < static_cast<uint32_t>(string->length())) {
4185 String* string = String::cast(obj); 4195 return isolate->heap()->true_value();
4186 if (index < static_cast<uint32_t>(string->length()))
4187 return isolate->heap()->true_value();
4188 } 4196 }
4189 } 4197 }
4190 return isolate->heap()->false_value(); 4198 return isolate->heap()->false_value();
4191 } 4199 }
4192 4200
4193 4201
4194 RUNTIME_FUNCTION(MaybeObject*, Runtime_HasProperty) { 4202 RUNTIME_FUNCTION(MaybeObject*, Runtime_HasProperty) {
4195 NoHandleAllocation na; 4203 NoHandleAllocation na;
4196 ASSERT(args.length() == 2); 4204 ASSERT(args.length() == 2);
4197 4205
(...skipping 7976 matching lines...) Expand 10 before | Expand all | Expand 10 after
12174 } else { 12182 } else {
12175 // Handle last resort GC and make sure to allow future allocations 12183 // Handle last resort GC and make sure to allow future allocations
12176 // to grow the heap without causing GCs (if possible). 12184 // to grow the heap without causing GCs (if possible).
12177 isolate->counters()->gc_last_resort_from_js()->Increment(); 12185 isolate->counters()->gc_last_resort_from_js()->Increment();
12178 isolate->heap()->CollectAllGarbage(false); 12186 isolate->heap()->CollectAllGarbage(false);
12179 } 12187 }
12180 } 12188 }
12181 12189
12182 12190
12183 } } // namespace v8::internal 12191 } } // namespace v8::internal
OLDNEW
« 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