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

Side by Side Diff: src/liveedit.cc

Issue 6899011: LiveEdit: optimize substring comparison (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 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 | Annotate | Revision Log
« no previous file with comments | « src/isolate.h ('k') | 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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 261
262 void Comparator::CalculateDifference(Comparator::Input* input, 262 void Comparator::CalculateDifference(Comparator::Input* input,
263 Comparator::Output* result_writer) { 263 Comparator::Output* result_writer) {
264 Differencer differencer(input); 264 Differencer differencer(input);
265 differencer.Initialize(); 265 differencer.Initialize();
266 differencer.FillTable(); 266 differencer.FillTable();
267 differencer.SaveResult(result_writer); 267 differencer.SaveResult(result_writer);
268 } 268 }
269 269
270 270
271 static bool CompareSubstrings(Isolate* isolate, Handle<String> s1, int pos1, 271 static bool CompareSubstrings(Handle<String> s1, int pos1,
272 Handle<String> s2, int pos2, int len) { 272 Handle<String> s2, int pos2, int len) {
273 StringInputBuffer& buf1 = *isolate->liveedit_compare_substrings_buf1();
274 StringInputBuffer& buf2 = *isolate->liveedit_compare_substrings_buf2();
275 buf1.Reset(*s1);
276 buf1.Seek(pos1);
277 buf2.Reset(*s2);
278 buf2.Seek(pos2);
279 for (int i = 0; i < len; i++) { 273 for (int i = 0; i < len; i++) {
280 ASSERT(buf1.has_more() && buf2.has_more()); 274 if (s1->Get(i + pos1) != s2->Get(i + pos2)) {
281 if (buf1.GetNext() != buf2.GetNext()) {
282 return false; 275 return false;
283 } 276 }
284 } 277 }
285 return true; 278 return true;
286 } 279 }
287 280
288 281
289 // A helper class that writes chunk numbers into JSArray. 282 // A helper class that writes chunk numbers into JSArray.
290 // Each chunk is stored as 3 array elements: (pos1_begin, pos1_end, pos2_end). 283 // Each chunk is stored as 3 array elements: (pos1_begin, pos1_end, pos2_end).
291 class CompareOutputArrayWriter { 284 class CompareOutputArrayWriter {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 396
404 int GetPosAfterNewLine(int index) { 397 int GetPosAfterNewLine(int index) {
405 return Smi::cast(ends_array_->get(index))->value() + 1; 398 return Smi::cast(ends_array_->get(index))->value() + 1;
406 } 399 }
407 }; 400 };
408 401
409 402
410 // Represents 2 strings as 2 arrays of lines. 403 // Represents 2 strings as 2 arrays of lines.
411 class LineArrayCompareInput : public Comparator::Input { 404 class LineArrayCompareInput : public Comparator::Input {
412 public: 405 public:
413 LineArrayCompareInput(Isolate* isolate, Handle<String> s1, Handle<String> s2, 406 LineArrayCompareInput(Handle<String> s1, Handle<String> s2,
414 LineEndsWrapper line_ends1, LineEndsWrapper line_ends2) 407 LineEndsWrapper line_ends1, LineEndsWrapper line_ends2)
415 : isolate_(isolate), s1_(s1), s2_(s2), line_ends1_(line_ends1), 408 : s1_(s1), s2_(s2), line_ends1_(line_ends1),
416 line_ends2_(line_ends2) { 409 line_ends2_(line_ends2) {
417 } 410 }
418 int getLength1() { 411 int getLength1() {
419 return line_ends1_.length(); 412 return line_ends1_.length();
420 } 413 }
421 int getLength2() { 414 int getLength2() {
422 return line_ends2_.length(); 415 return line_ends2_.length();
423 } 416 }
424 bool equals(int index1, int index2) { 417 bool equals(int index1, int index2) {
425 int line_start1 = line_ends1_.GetLineStart(index1); 418 int line_start1 = line_ends1_.GetLineStart(index1);
426 int line_start2 = line_ends2_.GetLineStart(index2); 419 int line_start2 = line_ends2_.GetLineStart(index2);
427 int line_end1 = line_ends1_.GetLineEnd(index1); 420 int line_end1 = line_ends1_.GetLineEnd(index1);
428 int line_end2 = line_ends2_.GetLineEnd(index2); 421 int line_end2 = line_ends2_.GetLineEnd(index2);
429 int len1 = line_end1 - line_start1; 422 int len1 = line_end1 - line_start1;
430 int len2 = line_end2 - line_start2; 423 int len2 = line_end2 - line_start2;
431 if (len1 != len2) { 424 if (len1 != len2) {
432 return false; 425 return false;
433 } 426 }
434 return CompareSubstrings(isolate_, s1_, line_start1, s2_, line_start2, 427 return CompareSubstrings(s1_, line_start1, s2_, line_start2,
435 len1); 428 len1);
436 } 429 }
437 430
438 private: 431 private:
439 Isolate* isolate_;
440 Handle<String> s1_; 432 Handle<String> s1_;
441 Handle<String> s2_; 433 Handle<String> s2_;
442 LineEndsWrapper line_ends1_; 434 LineEndsWrapper line_ends1_;
443 LineEndsWrapper line_ends2_; 435 LineEndsWrapper line_ends2_;
444 }; 436 };
445 437
446 438
447 // Stores compare result in JSArray. For each chunk tries to conduct 439 // Stores compare result in JSArray. For each chunk tries to conduct
448 // a fine-grained nested diff token-wise. 440 // a fine-grained nested diff token-wise.
449 class TokenizingLineArrayCompareOutput : public Comparator::Output { 441 class TokenizingLineArrayCompareOutput : public Comparator::Output {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 CompareOutputArrayWriter array_writer_; 477 CompareOutputArrayWriter array_writer_;
486 LineEndsWrapper line_ends1_; 478 LineEndsWrapper line_ends1_;
487 LineEndsWrapper line_ends2_; 479 LineEndsWrapper line_ends2_;
488 Handle<String> s1_; 480 Handle<String> s1_;
489 Handle<String> s2_; 481 Handle<String> s2_;
490 }; 482 };
491 483
492 484
493 Handle<JSArray> LiveEdit::CompareStrings(Handle<String> s1, 485 Handle<JSArray> LiveEdit::CompareStrings(Handle<String> s1,
494 Handle<String> s2) { 486 Handle<String> s2) {
487 s1 = FlattenGetString(s1);
488 s2 = FlattenGetString(s2);
489
495 LineEndsWrapper line_ends1(s1); 490 LineEndsWrapper line_ends1(s1);
496 LineEndsWrapper line_ends2(s2); 491 LineEndsWrapper line_ends2(s2);
497 492
498 LineArrayCompareInput 493 LineArrayCompareInput input(s1, s2, line_ends1, line_ends2);
499 input(Isolate::Current(), s1, s2, line_ends1, line_ends2);
500 TokenizingLineArrayCompareOutput output(line_ends1, line_ends2, s1, s2); 494 TokenizingLineArrayCompareOutput output(line_ends1, line_ends2, s1, s2);
501 495
502 Comparator::CalculateDifference(&input, &output); 496 Comparator::CalculateDifference(&input, &output);
503 497
504 return output.GetResult(); 498 return output.GetResult();
505 } 499 }
506 500
507 501
508 static void CompileScriptForTracker(Isolate* isolate, Handle<Script> script) { 502 static void CompileScriptForTracker(Isolate* isolate, Handle<Script> script) {
509 // TODO(635): support extensions. 503 // TODO(635): support extensions.
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1684 1678
1685 bool LiveEditFunctionTracker::IsActive() { 1679 bool LiveEditFunctionTracker::IsActive() {
1686 return false; 1680 return false;
1687 } 1681 }
1688 1682
1689 #endif // ENABLE_DEBUGGER_SUPPORT 1683 #endif // ENABLE_DEBUGGER_SUPPORT
1690 1684
1691 1685
1692 1686
1693 } } // namespace v8::internal 1687 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/isolate.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698