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

Side by Side Diff: runtime/vm/dart_entry.cc

Issue 1888593003: Revert "- Use a hash table to canonicalize instances/arrays to avoid having to iterate over a linea… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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 | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/intermediate_language.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 (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/dart_entry.h" 5 #include "vm/dart_entry.h"
6 6
7 #include "vm/class_finalizer.h" 7 #include "vm/class_finalizer.h"
8 #include "vm/code_generator.h" 8 #include "vm/code_generator.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/debugger.h" 10 #include "vm/debugger.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 optional_arguments_names.IsNull() ? 0 : optional_arguments_names.Length(); 315 optional_arguments_names.IsNull() ? 0 : optional_arguments_names.Length();
316 if (num_named_args == 0) { 316 if (num_named_args == 0) {
317 return ArgumentsDescriptor::New(num_arguments); 317 return ArgumentsDescriptor::New(num_arguments);
318 } 318 }
319 const intptr_t num_pos_args = num_arguments - num_named_args; 319 const intptr_t num_pos_args = num_arguments - num_named_args;
320 320
321 // Build the arguments descriptor array, which consists of the total 321 // Build the arguments descriptor array, which consists of the total
322 // argument count; the positional argument count; a sequence of (name, 322 // argument count; the positional argument count; a sequence of (name,
323 // position) pairs, sorted by name, for each named optional argument; and 323 // position) pairs, sorted by name, for each named optional argument; and
324 // a terminating null to simplify iterating in generated code. 324 // a terminating null to simplify iterating in generated code.
325 Thread* thread = Thread::Current();
326 Zone* zone = thread->zone();
327 const intptr_t descriptor_len = LengthFor(num_named_args); 325 const intptr_t descriptor_len = LengthFor(num_named_args);
328 Array& descriptor = Array::Handle( 326 Array& descriptor = Array::Handle(Array::New(descriptor_len, Heap::kOld));
329 zone, Array::New(descriptor_len, Heap::kOld));
330 327
331 // Set total number of passed arguments. 328 // Set total number of passed arguments.
332 descriptor.SetAt(kCountIndex, Smi::Handle(Smi::New(num_arguments))); 329 descriptor.SetAt(kCountIndex, Smi::Handle(Smi::New(num_arguments)));
333 // Set number of positional arguments. 330 // Set number of positional arguments.
334 descriptor.SetAt(kPositionalCountIndex, Smi::Handle(Smi::New(num_pos_args))); 331 descriptor.SetAt(kPositionalCountIndex, Smi::Handle(Smi::New(num_pos_args)));
335 // Set alphabetically sorted entries for named arguments. 332 // Set alphabetically sorted entries for named arguments.
336 String& name = String::Handle(zone); 333 String& name = String::Handle();
337 Smi& pos = Smi::Handle(zone); 334 Smi& pos = Smi::Handle();
338 String& previous_name = String::Handle(zone);
339 Smi& previous_pos = Smi::Handle(zone);
340 for (intptr_t i = 0; i < num_named_args; i++) { 335 for (intptr_t i = 0; i < num_named_args; i++) {
341 name ^= optional_arguments_names.At(i); 336 name ^= optional_arguments_names.At(i);
342 pos = Smi::New(num_pos_args + i); 337 pos = Smi::New(num_pos_args + i);
343 intptr_t insert_index = kFirstNamedEntryIndex + (kNamedEntrySize * i); 338 intptr_t insert_index = kFirstNamedEntryIndex + (kNamedEntrySize * i);
344 // Shift already inserted pairs with "larger" names. 339 // Shift already inserted pairs with "larger" names.
340 String& previous_name = String::Handle();
341 Smi& previous_pos = Smi::Handle();
345 while (insert_index > kFirstNamedEntryIndex) { 342 while (insert_index > kFirstNamedEntryIndex) {
346 intptr_t previous_index = insert_index - kNamedEntrySize; 343 intptr_t previous_index = insert_index - kNamedEntrySize;
347 previous_name ^= descriptor.At(previous_index + kNameOffset); 344 previous_name ^= descriptor.At(previous_index + kNameOffset);
348 intptr_t result = name.CompareTo(previous_name); 345 intptr_t result = name.CompareTo(previous_name);
349 ASSERT(result != 0); // Duplicate argument names checked in parser. 346 ASSERT(result != 0); // Duplicate argument names checked in parser.
350 if (result > 0) break; 347 if (result > 0) break;
351 previous_pos ^= descriptor.At(previous_index + kPositionOffset); 348 previous_pos ^= descriptor.At(previous_index + kPositionOffset);
352 descriptor.SetAt(insert_index + kNameOffset, previous_name); 349 descriptor.SetAt(insert_index + kNameOffset, previous_name);
353 descriptor.SetAt(insert_index + kPositionOffset, previous_pos); 350 descriptor.SetAt(insert_index + kPositionOffset, previous_pos);
354 insert_index = previous_index; 351 insert_index = previous_index;
355 } 352 }
356 // Insert pair in descriptor array. 353 // Insert pair in descriptor array.
357 descriptor.SetAt(insert_index + kNameOffset, name); 354 descriptor.SetAt(insert_index + kNameOffset, name);
358 descriptor.SetAt(insert_index + kPositionOffset, pos); 355 descriptor.SetAt(insert_index + kPositionOffset, pos);
359 } 356 }
360 // Set terminating null. 357 // Set terminating null.
361 descriptor.SetAt(descriptor_len - 1, Object::null_object()); 358 descriptor.SetAt(descriptor_len - 1, Object::null_object());
362 359
363 // Share the immutable descriptor when possible by canonicalizing it. 360 // Share the immutable descriptor when possible by canonicalizing it.
364 descriptor.MakeImmutable(); 361 descriptor.MakeImmutable();
365 descriptor ^= descriptor.CheckAndCanonicalize(thread, NULL); 362 descriptor ^= descriptor.CheckAndCanonicalize(NULL);
366 ASSERT(!descriptor.IsNull()); 363 ASSERT(!descriptor.IsNull());
367 return descriptor.raw(); 364 return descriptor.raw();
368 } 365 }
369 366
370 367
371 RawArray* ArgumentsDescriptor::New(intptr_t num_arguments) { 368 RawArray* ArgumentsDescriptor::New(intptr_t num_arguments) {
372 ASSERT(num_arguments >= 0); 369 ASSERT(num_arguments >= 0);
373 if (num_arguments < kCachedDescriptorCount) { 370 if (num_arguments < kCachedDescriptorCount) {
374 return cached_args_descriptors_[num_arguments]; 371 return cached_args_descriptors_[num_arguments];
375 } 372 }
376 return NewNonCached(num_arguments); 373 return NewNonCached(num_arguments);
377 } 374 }
378 375
379 376
380 RawArray* ArgumentsDescriptor::NewNonCached(intptr_t num_arguments, 377 RawArray* ArgumentsDescriptor::NewNonCached(intptr_t num_arguments,
381 bool canonicalize) { 378 bool canonicalize) {
382 // Build the arguments descriptor array, which consists of the total 379 // Build the arguments descriptor array, which consists of the total
383 // argument count; the positional argument count; and 380 // argument count; the positional argument count; and
384 // a terminating null to simplify iterating in generated code. 381 // a terminating null to simplify iterating in generated code.
385 Thread* thread = Thread::Current();
386 Zone* zone = thread->zone();
387 const intptr_t descriptor_len = LengthFor(0); 382 const intptr_t descriptor_len = LengthFor(0);
388 Array& descriptor = Array::Handle( 383 Array& descriptor = Array::Handle(Array::New(descriptor_len, Heap::kOld));
389 zone, Array::New(descriptor_len, Heap::kOld)); 384 const Smi& arg_count = Smi::Handle(Smi::New(num_arguments));
390 const Smi& arg_count = Smi::Handle(zone, Smi::New(num_arguments));
391 385
392 // Set total number of passed arguments. 386 // Set total number of passed arguments.
393 descriptor.SetAt(kCountIndex, arg_count); 387 descriptor.SetAt(kCountIndex, arg_count);
394 388
395 // Set number of positional arguments. 389 // Set number of positional arguments.
396 descriptor.SetAt(kPositionalCountIndex, arg_count); 390 descriptor.SetAt(kPositionalCountIndex, arg_count);
397 391
398 // Set terminating null. 392 // Set terminating null.
399 descriptor.SetAt((descriptor_len - 1), Object::null_object()); 393 descriptor.SetAt((descriptor_len - 1), Object::null_object());
400 394
401 // Share the immutable descriptor when possible by canonicalizing it. 395 // Share the immutable descriptor when possible by canonicalizing it.
402 descriptor.MakeImmutable(); 396 descriptor.MakeImmutable();
403 if (canonicalize) { 397 if (canonicalize) {
404 descriptor ^= descriptor.CheckAndCanonicalize(thread, NULL); 398 descriptor ^= descriptor.CheckAndCanonicalize(NULL);
405 } 399 }
406 ASSERT(!descriptor.IsNull()); 400 ASSERT(!descriptor.IsNull());
407 return descriptor.raw(); 401 return descriptor.raw();
408 } 402 }
409 403
410 404
411 void ArgumentsDescriptor::InitOnce() { 405 void ArgumentsDescriptor::InitOnce() {
412 for (int i = 0; i < kCachedDescriptorCount; i++) { 406 for (int i = 0; i < kCachedDescriptorCount; i++) {
413 cached_args_descriptors_[i] = ArgumentsDescriptor::NewNonCached(i, false); 407 cached_args_descriptors_[i] = ArgumentsDescriptor::NewNonCached(i, false);
414 } 408 }
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 const Array& args = Array::Handle(Array::New(kNumArguments)); 595 const Array& args = Array::Handle(Array::New(kNumArguments));
602 args.SetAt(0, map); 596 args.SetAt(0, map);
603 args.SetAt(1, key); 597 args.SetAt(1, key);
604 args.SetAt(2, value); 598 args.SetAt(2, value);
605 const Object& result = Object::Handle(DartEntry::InvokeFunction(function, 599 const Object& result = Object::Handle(DartEntry::InvokeFunction(function,
606 args)); 600 args));
607 return result.raw(); 601 return result.raw();
608 } 602 }
609 603
610 } // namespace dart 604 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.cc ('k') | runtime/vm/intermediate_language.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698