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

Side by Side Diff: src/ast.cc

Issue 9639011: Added support functions for using Literal keys in a HashMap. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review comments Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/ast.h ('k') | src/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 if (h2->IsSmi()) return false; 236 if (h2->IsSmi()) return false;
237 Handle<HeapNumber> n1 = Handle<HeapNumber>::cast(h1); 237 Handle<HeapNumber> n1 = Handle<HeapNumber>::cast(h1);
238 Handle<HeapNumber> n2 = Handle<HeapNumber>::cast(h2); 238 Handle<HeapNumber> n2 = Handle<HeapNumber>::cast(h2);
239 ASSERT(isfinite(n1->value())); 239 ASSERT(isfinite(n1->value()));
240 ASSERT(isfinite(n2->value())); 240 ASSERT(isfinite(n2->value()));
241 return n1->value() == n2->value(); 241 return n1->value() == n2->value();
242 } 242 }
243 243
244 244
245 void ObjectLiteral::CalculateEmitStore() { 245 void ObjectLiteral::CalculateEmitStore() {
246 ZoneHashMap properties(&IsEqualString); 246 ZoneHashMap table(Literal::Match);
247 ZoneHashMap elements(&IsEqualNumber); 247 for (int i = properties()->length() - 1; i >= 0; i--) {
248 for (int i = this->properties()->length() - 1; i >= 0; i--) { 248 ObjectLiteral::Property* property = properties()->at(i);
249 ObjectLiteral::Property* property = this->properties()->at(i);
250 Literal* literal = property->key(); 249 Literal* literal = property->key();
251 Handle<Object> handle = literal->handle(); 250 if (literal->handle()->IsNull()) continue;
252 251 uint32_t hash = literal->Hash();
253 if (handle->IsNull()) {
254 continue;
255 }
256
257 uint32_t hash;
258 ZoneHashMap* table;
259 void* key;
260 Factory* factory = Isolate::Current()->factory();
261 if (handle->IsSymbol()) {
262 Handle<String> name(String::cast(*handle));
263 if (name->AsArrayIndex(&hash)) {
264 Handle<Object> key_handle = factory->NewNumberFromUint(hash);
265 key = key_handle.location();
266 table = &elements;
267 } else {
268 key = name.location();
269 hash = name->Hash();
270 table = &properties;
271 }
272 } else if (handle->ToArrayIndex(&hash)) {
273 key = handle.location();
274 table = &elements;
275 } else {
276 ASSERT(handle->IsNumber());
277 double num = handle->Number();
278 char arr[100];
279 Vector<char> buffer(arr, ARRAY_SIZE(arr));
280 const char* str = DoubleToCString(num, buffer);
281 Handle<String> name = factory->NewStringFromAscii(CStrVector(str));
282 key = name.location();
283 hash = name->Hash();
284 table = &properties;
285 }
286 // If the key of a computed property is in the table, do not emit 252 // If the key of a computed property is in the table, do not emit
287 // a store for the property later. 253 // a store for the property later.
288 if (property->kind() == ObjectLiteral::Property::COMPUTED) { 254 if (property->kind() == ObjectLiteral::Property::COMPUTED &&
289 if (table->Lookup(key, hash, false) != NULL) { 255 table.Lookup(literal, hash, false) != NULL) {
290 property->set_emit_store(false); 256 property->set_emit_store(false);
291 } 257 } else {
258 // Add key to the table.
259 table.Lookup(literal, hash, true);
292 } 260 }
293 // Add key to the table.
294 table->Lookup(key, hash, true);
295 } 261 }
296 } 262 }
297 263
298 264
299 void TargetCollector::AddTarget(Label* target) { 265 void TargetCollector::AddTarget(Label* target) {
300 // Add the label to the collector, but discard duplicates. 266 // Add the label to the collector, but discard duplicates.
301 int length = targets_.length(); 267 int length = targets_.length();
302 for (int i = 0; i < length; i++) { 268 for (int i = 0; i < length; i++) {
303 if (targets_[i] == target) return; 269 if (targets_[i] == target) return;
304 } 270 }
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 } else if (node->function()->intrinsic_type == Runtime::INLINE && 1127 } else if (node->function()->intrinsic_type == Runtime::INLINE &&
1162 (node->name()->IsEqualTo(CStrVector("_ArgumentsLength")) || 1128 (node->name()->IsEqualTo(CStrVector("_ArgumentsLength")) ||
1163 node->name()->IsEqualTo(CStrVector("_Arguments")))) { 1129 node->name()->IsEqualTo(CStrVector("_Arguments")))) {
1164 // Don't inline the %_ArgumentsLength or %_Arguments because their 1130 // Don't inline the %_ArgumentsLength or %_Arguments because their
1165 // implementation will not work. There is no stack frame to get them 1131 // implementation will not work. There is no stack frame to get them
1166 // from. 1132 // from.
1167 add_flag(kDontInline); 1133 add_flag(kDontInline);
1168 } 1134 }
1169 } 1135 }
1170 1136
1137
1138 Handle<String> Literal::ToString() {
1139 if (handle_->IsString()) return Handle<String>::cast(handle_);
1140 ASSERT(handle_->IsNumber());
1141 char arr[100];
1142 Vector<char> buffer(arr, ARRAY_SIZE(arr));
1143 const char* str;
1144 if (handle_->IsSmi()) {
1145 // Optimization only, the heap number case would subsume this.
1146 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value());
1147 str = arr;
1148 } else {
1149 str = DoubleToCString(handle_->Number(), buffer);
1150 }
1151 return FACTORY->NewStringFromAscii(CStrVector(str));
1152 }
1153
1154
1171 } } // namespace v8::internal 1155 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698