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

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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 Handle<FixedArray> CalculateLineEnds(Vector<const SourceChar> src,
mnaganov (inactive) 2010/11/17 15:32:00 Please mark this private function 'static'.
sandholm 2010/11/17 15:45:23 Done.
509 const int src_len = src->length(); 510 bool with_last_line) {
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);
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
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 // const int src_len = src->length();
550 if (!src->IsFlat()) FlattenString(src);
551 AssertNoAllocation no_heap_allocation; // ensure vectors stay valid
552 // Extract flattened substrings of cons strings before determining asciiness.
553 String* seq_src = *src;
554 if (seq_src->IsConsString()) seq_src = ConsString::cast(seq_src)->first();
mnaganov (inactive) 2010/11/17 15:32:00 Should you assert anything about the second part o
sandholm 2010/11/17 15:45:23 Yes. src is flat so if it is a cons string then th
555 // dispatch on type of strings
556 if (seq_src->IsAsciiRepresentation()) {
557 return CalculateLineEnds(seq_src->ToAsciiVector(), with_last_line);
558 }
559 return CalculateLineEnds(seq_src->ToUC16Vector(), with_last_line);
560 }
561
547 562
548 // Convert code position into line number. 563 // Convert code position into line number.
549 int GetScriptLineNumber(Handle<Script> script, int code_pos) { 564 int GetScriptLineNumber(Handle<Script> script, int code_pos) {
550 InitScriptLineEnds(script); 565 InitScriptLineEnds(script);
551 AssertNoAllocation no_allocation; 566 AssertNoAllocation no_allocation;
552 FixedArray* line_ends_array = FixedArray::cast(script->line_ends()); 567 FixedArray* line_ends_array = FixedArray::cast(script->line_ends());
553 const int line_ends_len = line_ends_array->length(); 568 const int line_ends_len = line_ends_array->length();
554 569
555 if (!line_ends_len) 570 if (!line_ends_len)
556 return -1; 571 return -1;
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 879
865 OptimizedObjectForAddingMultipleProperties:: 880 OptimizedObjectForAddingMultipleProperties::
866 ~OptimizedObjectForAddingMultipleProperties() { 881 ~OptimizedObjectForAddingMultipleProperties() {
867 // Reoptimize the object to allow fast property access. 882 // Reoptimize the object to allow fast property access.
868 if (has_been_transformed_) { 883 if (has_been_transformed_) {
869 TransformToFastProperties(object_, unused_property_fields_); 884 TransformToFastProperties(object_, unused_property_fields_);
870 } 885 }
871 } 886 }
872 887
873 } } // namespace v8::internal 888 } } // 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