| OLD | NEW |
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 } | 435 } |
| 436 | 436 |
| 437 // Test whether fast-case should be used. | 437 // Test whether fast-case should be used. |
| 438 int default_index = -1; | 438 int default_index = -1; |
| 439 int min_index = Smi::kMaxValue; | 439 int min_index = Smi::kMaxValue; |
| 440 int max_index = Smi::kMinValue; | 440 int max_index = Smi::kMinValue; |
| 441 for (int i = 0; i < length; i++) { | 441 for (int i = 0; i < length; i++) { |
| 442 CaseClause* clause = cases->at(i); | 442 CaseClause* clause = cases->at(i); |
| 443 if (clause->is_default()) { | 443 if (clause->is_default()) { |
| 444 if (default_index >= 0) { | 444 if (default_index >= 0) { |
| 445 return false; // More than one default label: | 445 // There is more than one default label. Defer to the normal case |
| 446 // Defer to normal case for error. | 446 // for error. |
| 447 } | 447 return false; |
| 448 } |
| 448 default_index = i; | 449 default_index = i; |
| 449 } else { | 450 } else { |
| 450 Expression* label = clause->label(); | 451 Expression* label = clause->label(); |
| 451 Literal* literal = label->AsLiteral(); | 452 Literal* literal = label->AsLiteral(); |
| 452 if (literal == NULL) { | 453 if (literal == NULL) { |
| 453 return false; // fail fast case | 454 return false; // fail fast case |
| 454 } | 455 } |
| 455 Object* value = *(literal->handle()); | 456 Object* value = *(literal->handle()); |
| 456 if (!value->IsSmi()) { | 457 if (!value->IsSmi()) { |
| 457 return false; | 458 return false; |
| 458 } | 459 } |
| 459 int smi = Smi::cast(value)->value(); | 460 int int_value = Smi::cast(value)->value(); |
| 460 if (smi < min_index) { min_index = smi; } | 461 min_index = Min(int_value, min_index); |
| 461 if (smi > max_index) { max_index = smi; } | 462 max_index = Max(int_value, max_index); |
| 462 } | 463 } |
| 463 } | 464 } |
| 464 | 465 |
| 465 // All labels are known to be Smis. | 466 // All labels are known to be Smis. |
| 466 int range = max_index - min_index + 1; // |min..max| inclusive | 467 int range = max_index - min_index + 1; // |min..max| inclusive |
| 467 if (range / FastCaseSwitchMaxOverheadFactor() > length) { | 468 if (range / FastCaseSwitchMaxOverheadFactor() > length) { |
| 468 return false; // range of labels is too sparse | 469 return false; // range of labels is too sparse |
| 469 } | 470 } |
| 470 | 471 |
| 471 // Optimization accepted, generate code. | 472 // Optimization accepted, generate code. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 void ArgumentsAccessStub::Generate(MacroAssembler* masm) { | 508 void ArgumentsAccessStub::Generate(MacroAssembler* masm) { |
| 508 switch (type_) { | 509 switch (type_) { |
| 509 case READ_LENGTH: GenerateReadLength(masm); break; | 510 case READ_LENGTH: GenerateReadLength(masm); break; |
| 510 case READ_ELEMENT: GenerateReadElement(masm); break; | 511 case READ_ELEMENT: GenerateReadElement(masm); break; |
| 511 case NEW_OBJECT: GenerateNewObject(masm); break; | 512 case NEW_OBJECT: GenerateNewObject(masm); break; |
| 512 } | 513 } |
| 513 } | 514 } |
| 514 | 515 |
| 515 | 516 |
| 516 } } // namespace v8::internal | 517 } } // namespace v8::internal |
| OLD | NEW |