Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 18 matching lines...) Expand all Loading... | |
| 29 | 29 |
| 30 #include "accessors.h" | 30 #include "accessors.h" |
| 31 #include "api.h" | 31 #include "api.h" |
| 32 #include "arguments.h" | 32 #include "arguments.h" |
| 33 #include "bootstrapper.h" | 33 #include "bootstrapper.h" |
| 34 #include "compiler.h" | 34 #include "compiler.h" |
| 35 #include "debug.h" | 35 #include "debug.h" |
| 36 #include "execution.h" | 36 #include "execution.h" |
| 37 #include "global-handles.h" | 37 #include "global-handles.h" |
| 38 #include "natives.h" | 38 #include "natives.h" |
| 39 #include "string-search.h" | |
| 39 #include "runtime.h" | 40 #include "runtime.h" |
| 40 #include "stub-cache.h" | 41 #include "stub-cache.h" |
| 41 | 42 |
| 42 namespace v8 { | 43 namespace v8 { |
| 43 namespace internal { | 44 namespace internal { |
| 44 | 45 |
| 45 | 46 |
| 46 v8::ImplementationUtilities::HandleScopeData HandleScope::current_ = | 47 v8::ImplementationUtilities::HandleScopeData HandleScope::current_ = |
| 47 { NULL, NULL, 0 }; | 48 { NULL, NULL, 0 }; |
| 48 | 49 |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 | 498 |
| 498 Handle<String> src(String::cast(script->source())); | 499 Handle<String> src(String::cast(script->source())); |
| 499 | 500 |
| 500 Handle<FixedArray> array = CalculateLineEnds(src, true); | 501 Handle<FixedArray> array = CalculateLineEnds(src, true); |
| 501 | 502 |
| 502 script->set_line_ends(*array); | 503 script->set_line_ends(*array); |
| 503 ASSERT(script->line_ends()->IsFixedArray()); | 504 ASSERT(script->line_ends()->IsFixedArray()); |
| 504 } | 505 } |
| 505 | 506 |
| 506 | 507 |
| 507 Handle<FixedArray> CalculateLineEnds(Handle<String> src, | 508 template <typename SourceChar> |
| 508 bool with_imaginary_last_new_line) { | 509 static Handle<FixedArray> CalculateLineEnds(Vector<const SourceChar> src, |
| 509 const int src_len = src->length(); | 510 bool with_last_line) { |
|
Lasse Reichstein
2010/11/18 08:11:47
I wonder whether this function is performance crit
sandholm
2010/11/18 08:39:10
Me too. Let's see what happens.
| |
| 510 Handle<String> new_line = Factory::NewStringFromAscii(CStrVector("\n")); | 511 const int src_len = src.length(); |
| 512 StringSearch<char, SourceChar> search(CStrVector("\n")); | |
| 511 | 513 |
| 512 // Pass 1: Identify line count. | 514 // Pass 1: Identify line count. |
| 513 int line_count = 0; | 515 int line_count = 0; |
| 514 int position = 0; | 516 int position = 0; |
| 515 while (position != -1 && position < src_len) { | 517 while (position != -1 && position < src_len) { |
| 516 position = Runtime::StringMatch(src, new_line, position); | 518 position = search.Search(src, position); |
|
Lasse Reichstein
2010/11/18 08:11:47
Not calling Runtime::StringMatch is good (it's an
sandholm
2010/11/18 08:39:10
Makes sense. If there is any performance gain from
| |
| 517 if (position != -1) { | 519 if (position != -1) { |
| 518 position++; | 520 position++; |
| 519 } | |
| 520 if (position != -1) { | |
| 521 line_count++; | 521 line_count++; |
| 522 } else if (with_imaginary_last_new_line) { | 522 } else if (with_last_line) { |
| 523 // Even if the last line misses a line end, it is counted. | 523 // Even if the last line misses a line end, it is counted. |
| 524 line_count++; | 524 line_count++; |
| 525 } | 525 } |
| 526 } | 526 } |
| 527 | 527 |
| 528 // Pass 2: Fill in line ends positions | 528 // Pass 2: Fill in line ends positions |
|
Lasse Reichstein
2010/11/18 08:11:47
On the other hand, if the function isn't performan
sandholm
2010/11/18 08:39:10
Agree. That's why I suggested using Fixed ArrayBui
| |
| 529 Handle<FixedArray> array = Factory::NewFixedArray(line_count); | 529 Handle<FixedArray> array = Factory::NewFixedArray(line_count); |
| 530 int array_index = 0; | 530 int array_index = 0; |
| 531 position = 0; | 531 position = 0; |
| 532 while (position != -1 && position < src_len) { | 532 while (position != -1 && position < src_len) { |
| 533 position = Runtime::StringMatch(src, new_line, position); | 533 position = search.Search(src, position); |
| 534 if (position != -1) { | 534 if (position != -1) { |
| 535 array->set(array_index++, Smi::FromInt(position++)); | 535 array->set(array_index++, Smi::FromInt(position++)); |
| 536 } else if (with_imaginary_last_new_line) { | 536 } else if (with_last_line) { |
| 537 // If the script does not end with a line ending add the final end | 537 // If the script does not end with a line ending add the final end |
| 538 // position as just past the last line ending. | 538 // position as just past the last line ending. |
| 539 array->set(array_index++, Smi::FromInt(src_len)); | 539 array->set(array_index++, Smi::FromInt(src_len)); |
| 540 } | 540 } |
| 541 } | 541 } |
| 542 ASSERT(array_index == line_count); | 542 ASSERT(array_index == line_count); |
| 543 | 543 |
| 544 return array; | 544 return array; |
| 545 } | 545 } |
| 546 | 546 |
| 547 Handle<FixedArray> CalculateLineEnds(Handle<String> src, | |
| 548 bool with_last_line) { | |
| 549 if (!src->IsFlat()) FlattenString(src); | |
| 550 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid | |
| 551 // Extract flattened substring of cons string before determining asciiness. | |
| 552 String* seq_src = *src; | |
| 553 if (seq_src->IsConsString()) seq_src = ConsString::cast(seq_src)->first(); | |
| 554 // Dispatch on type of strings. | |
| 555 if (seq_src->IsAsciiRepresentation()) { | |
| 556 return CalculateLineEnds(seq_src->ToAsciiVector(), with_last_line); | |
| 557 } | |
| 558 return CalculateLineEnds(seq_src->ToUC16Vector(), with_last_line); | |
| 559 } | |
| 560 | |
| 547 | 561 |
| 548 // Convert code position into line number. | 562 // Convert code position into line number. |
| 549 int GetScriptLineNumber(Handle<Script> script, int code_pos) { | 563 int GetScriptLineNumber(Handle<Script> script, int code_pos) { |
| 550 InitScriptLineEnds(script); | 564 InitScriptLineEnds(script); |
| 551 AssertNoAllocation no_allocation; | 565 AssertNoAllocation no_allocation; |
| 552 FixedArray* line_ends_array = FixedArray::cast(script->line_ends()); | 566 FixedArray* line_ends_array = FixedArray::cast(script->line_ends()); |
| 553 const int line_ends_len = line_ends_array->length(); | 567 const int line_ends_len = line_ends_array->length(); |
| 554 | 568 |
| 555 if (!line_ends_len) | 569 if (!line_ends_len) |
| 556 return -1; | 570 return -1; |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 864 | 878 |
| 865 OptimizedObjectForAddingMultipleProperties:: | 879 OptimizedObjectForAddingMultipleProperties:: |
| 866 ~OptimizedObjectForAddingMultipleProperties() { | 880 ~OptimizedObjectForAddingMultipleProperties() { |
| 867 // Reoptimize the object to allow fast property access. | 881 // Reoptimize the object to allow fast property access. |
| 868 if (has_been_transformed_) { | 882 if (has_been_transformed_) { |
| 869 TransformToFastProperties(object_, unused_property_fields_); | 883 TransformToFastProperties(object_, unused_property_fields_); |
| 870 } | 884 } |
| 871 } | 885 } |
| 872 | 886 |
| 873 } } // namespace v8::internal | 887 } } // namespace v8::internal |
| OLD | NEW |