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

Side by Side Diff: src/handles.cc

Issue 5100002: Leverage Lasse's StringSearch object to speed up calculations of script ... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 1 month 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 | « 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 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
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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 502
502 if (*array != Heap::empty_fixed_array()) { 503 if (*array != Heap::empty_fixed_array()) {
503 array->set_map(Heap::fixed_cow_array_map()); 504 array->set_map(Heap::fixed_cow_array_map());
504 } 505 }
505 506
506 script->set_line_ends(*array); 507 script->set_line_ends(*array);
507 ASSERT(script->line_ends()->IsFixedArray()); 508 ASSERT(script->line_ends()->IsFixedArray());
508 } 509 }
509 510
510 511
511 Handle<FixedArray> CalculateLineEnds(Handle<String> src, 512 template <typename SourceChar>
512 bool with_imaginary_last_new_line) { 513 static Handle<FixedArray> CalculateLineEnds(Vector<const SourceChar> src,
513 const int src_len = src->length(); 514 bool with_last_line) {
514 Handle<String> new_line = Factory::NewStringFromAscii(CStrVector("\n")); 515 const int src_len = src.length();
516 StringSearch<char, SourceChar> search(CStrVector("\n"));
515 517
516 // Pass 1: Identify line count. 518 // Pass 1: Identify line count.
517 int line_count = 0; 519 int line_count = 0;
518 int position = 0; 520 int position = 0;
519 while (position != -1 && position < src_len) { 521 while (position != -1 && position < src_len) {
520 position = Runtime::StringMatch(src, new_line, position); 522 position = search.Search(src, position);
521 if (position != -1) { 523 if (position != -1) {
522 position++; 524 position++;
523 }
524 if (position != -1) {
525 line_count++; 525 line_count++;
526 } else if (with_imaginary_last_new_line) { 526 } else if (with_last_line) {
527 // Even if the last line misses a line end, it is counted. 527 // Even if the last line misses a line end, it is counted.
528 line_count++; 528 line_count++;
529 } 529 }
530 } 530 }
531 531
532 // Pass 2: Fill in line ends positions 532 // Pass 2: Fill in line ends positions
533 Handle<FixedArray> array = Factory::NewFixedArray(line_count); 533 Handle<FixedArray> array = Factory::NewFixedArray(line_count);
534 int array_index = 0; 534 int array_index = 0;
535 position = 0; 535 position = 0;
536 while (position != -1 && position < src_len) { 536 while (position != -1 && position < src_len) {
537 position = Runtime::StringMatch(src, new_line, position); 537 position = search.Search(src, position);
538 if (position != -1) { 538 if (position != -1) {
539 array->set(array_index++, Smi::FromInt(position++)); 539 array->set(array_index++, Smi::FromInt(position++));
540 } else if (with_imaginary_last_new_line) { 540 } else if (with_last_line) {
541 // If the script does not end with a line ending add the final end 541 // If the script does not end with a line ending add the final end
542 // position as just past the last line ending. 542 // position as just past the last line ending.
543 array->set(array_index++, Smi::FromInt(src_len)); 543 array->set(array_index++, Smi::FromInt(src_len));
544 } 544 }
545 } 545 }
546 ASSERT(array_index == line_count); 546 ASSERT(array_index == line_count);
547 547
548 return array; 548 return array;
549 } 549 }
550 550
551 Handle<FixedArray> CalculateLineEnds(Handle<String> src,
552 bool with_last_line) {
553 if (!src->IsFlat()) FlattenString(src);
554 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid
555 // Extract flattened substring of cons string before determining asciiness.
556 String* seq_src = *src;
557 if (seq_src->IsConsString()) seq_src = ConsString::cast(seq_src)->first();
558 // Dispatch on type of strings.
559 if (seq_src->IsAsciiRepresentation()) {
560 return CalculateLineEnds(seq_src->ToAsciiVector(), with_last_line);
561 }
562 return CalculateLineEnds(seq_src->ToUC16Vector(), with_last_line);
563 }
564
551 565
552 // Convert code position into line number. 566 // Convert code position into line number.
553 int GetScriptLineNumber(Handle<Script> script, int code_pos) { 567 int GetScriptLineNumber(Handle<Script> script, int code_pos) {
554 InitScriptLineEnds(script); 568 InitScriptLineEnds(script);
555 AssertNoAllocation no_allocation; 569 AssertNoAllocation no_allocation;
556 FixedArray* line_ends_array = FixedArray::cast(script->line_ends()); 570 FixedArray* line_ends_array = FixedArray::cast(script->line_ends());
557 const int line_ends_len = line_ends_array->length(); 571 const int line_ends_len = line_ends_array->length();
558 572
559 if (!line_ends_len) 573 if (!line_ends_len)
560 return -1; 574 return -1;
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 882
869 OptimizedObjectForAddingMultipleProperties:: 883 OptimizedObjectForAddingMultipleProperties::
870 ~OptimizedObjectForAddingMultipleProperties() { 884 ~OptimizedObjectForAddingMultipleProperties() {
871 // Reoptimize the object to allow fast property access. 885 // Reoptimize the object to allow fast property access.
872 if (has_been_transformed_) { 886 if (has_been_transformed_) {
873 TransformToFastProperties(object_, unused_property_fields_); 887 TransformToFastProperties(object_, unused_property_fields_);
874 } 888 }
875 } 889 }
876 890
877 } } // namespace v8::internal 891 } } // 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