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

Side by Side Diff: src/liveedit.cc

Issue 6577036: [Isolates] Merge from bleeding_edge to isolates, revisions 6100-6300. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 9 years, 10 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/liveedit.h ('k') | src/liveedit-debugger.js » ('j') | 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 for (int i = 0; i < len; i++) { 268 for (int i = 0; i < len; i++) {
269 ASSERT(buf1.has_more() && buf2.has_more()); 269 ASSERT(buf1.has_more() && buf2.has_more());
270 if (buf1.GetNext() != buf2.GetNext()) { 270 if (buf1.GetNext() != buf2.GetNext()) {
271 return false; 271 return false;
272 } 272 }
273 } 273 }
274 return true; 274 return true;
275 } 275 }
276 276
277 277
278 // A helper class that writes chunk numbers into JSArray.
279 // Each chunk is stored as 3 array elements: (pos1_begin, pos1_end, pos2_end).
280 class CompareOutputArrayWriter {
281 public:
282 CompareOutputArrayWriter()
283 : array_(FACTORY->NewJSArray(10)), current_size_(0) {}
284
285 Handle<JSArray> GetResult() {
286 return array_;
287 }
288
289 void WriteChunk(int char_pos1, int char_pos2, int char_len1, int char_len2) {
290 SetElement(array_, current_size_, Handle<Object>(Smi::FromInt(char_pos1)));
291 SetElement(array_, current_size_ + 1,
292 Handle<Object>(Smi::FromInt(char_pos1 + char_len1)));
293 SetElement(array_, current_size_ + 2,
294 Handle<Object>(Smi::FromInt(char_pos2 + char_len2)));
295 current_size_ += 3;
296 }
297
298 private:
299 Handle<JSArray> array_;
300 int current_size_;
301 };
302
303
304 // Represents 2 strings as 2 arrays of tokens.
305 // TODO(LiveEdit): Currently it's actually an array of charactres.
306 // Make array of tokens instead.
307 class TokensCompareInput : public Comparator::Input {
308 public:
309 TokensCompareInput(Handle<String> s1, int offset1, int len1,
310 Handle<String> s2, int offset2, int len2)
311 : s1_(s1), offset1_(offset1), len1_(len1),
312 s2_(s2), offset2_(offset2), len2_(len2) {
313 }
314 virtual int getLength1() {
315 return len1_;
316 }
317 virtual int getLength2() {
318 return len2_;
319 }
320 bool equals(int index1, int index2) {
321 return s1_->Get(offset1_ + index1) == s2_->Get(offset2_ + index2);
322 }
323
324 private:
325 Handle<String> s1_;
326 int offset1_;
327 int len1_;
328 Handle<String> s2_;
329 int offset2_;
330 int len2_;
331 };
332
333
334 // Stores compare result in JSArray. Converts substring positions
335 // to absolute positions.
336 class TokensCompareOutput : public Comparator::Output {
337 public:
338 TokensCompareOutput(CompareOutputArrayWriter* array_writer,
339 int offset1, int offset2)
340 : array_writer_(array_writer), offset1_(offset1), offset2_(offset2) {
341 }
342
343 void AddChunk(int pos1, int pos2, int len1, int len2) {
344 array_writer_->WriteChunk(pos1 + offset1_, pos2 + offset2_, len1, len2);
345 }
346
347 private:
348 CompareOutputArrayWriter* array_writer_;
349 int offset1_;
350 int offset2_;
351 };
352
353
278 // Wraps raw n-elements line_ends array as a list of n+1 lines. The last line 354 // Wraps raw n-elements line_ends array as a list of n+1 lines. The last line
279 // never has terminating new line character. 355 // never has terminating new line character.
280 class LineEndsWrapper { 356 class LineEndsWrapper {
281 public: 357 public:
282 explicit LineEndsWrapper(Handle<String> string) 358 explicit LineEndsWrapper(Handle<String> string)
283 : ends_array_(CalculateLineEnds(string, false)), 359 : ends_array_(CalculateLineEnds(string, false)),
284 string_len_(string->length()) { 360 string_len_(string->length()) {
285 } 361 }
286 int length() { 362 int length() {
287 return ends_array_->length() + 1; 363 return ends_array_->length() + 1;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 422
347 private: 423 private:
348 Isolate* isolate_; 424 Isolate* isolate_;
349 Handle<String> s1_; 425 Handle<String> s1_;
350 Handle<String> s2_; 426 Handle<String> s2_;
351 LineEndsWrapper line_ends1_; 427 LineEndsWrapper line_ends1_;
352 LineEndsWrapper line_ends2_; 428 LineEndsWrapper line_ends2_;
353 }; 429 };
354 430
355 431
356 // Stores compare result in JSArray. Each chunk is stored as 3 array elements: 432 // Stores compare result in JSArray. For each chunk tries to conduct
357 // (pos1_begin, pos1_end, pos2_end). 433 // a fine-grained nested diff token-wise.
358 class LineArrayCompareOutput : public Comparator::Output { 434 class TokenizingLineArrayCompareOutput : public Comparator::Output {
359 public: 435 public:
360 LineArrayCompareOutput(LineEndsWrapper line_ends1, LineEndsWrapper line_ends2) 436 TokenizingLineArrayCompareOutput(LineEndsWrapper line_ends1,
361 : array_(FACTORY->NewJSArray(10)), current_size_(0), 437 LineEndsWrapper line_ends2,
362 line_ends1_(line_ends1), line_ends2_(line_ends2) { 438 Handle<String> s1, Handle<String> s2)
439 : line_ends1_(line_ends1), line_ends2_(line_ends2), s1_(s1), s2_(s2) {
363 } 440 }
364 441
365 void AddChunk(int line_pos1, int line_pos2, int line_len1, int line_len2) { 442 void AddChunk(int line_pos1, int line_pos2, int line_len1, int line_len2) {
366 int char_pos1 = line_ends1_.GetLineStart(line_pos1); 443 int char_pos1 = line_ends1_.GetLineStart(line_pos1);
367 int char_pos2 = line_ends2_.GetLineStart(line_pos2); 444 int char_pos2 = line_ends2_.GetLineStart(line_pos2);
368 int char_len1 = line_ends1_.GetLineStart(line_pos1 + line_len1) - char_pos1; 445 int char_len1 = line_ends1_.GetLineStart(line_pos1 + line_len1) - char_pos1;
369 int char_len2 = line_ends2_.GetLineStart(line_pos2 + line_len2) - char_pos2; 446 int char_len2 = line_ends2_.GetLineStart(line_pos2 + line_len2) - char_pos2;
370 447
371 SetElement(array_, current_size_, Handle<Object>(Smi::FromInt(char_pos1))); 448 if (char_len1 < CHUNK_LEN_LIMIT && char_len2 < CHUNK_LEN_LIMIT) {
372 SetElement(array_, current_size_ + 1, 449 // Chunk is small enough to conduct a nested token-level diff.
373 Handle<Object>(Smi::FromInt(char_pos1 + char_len1))); 450 HandleScope subTaskScope;
374 SetElement(array_, current_size_ + 2, 451
375 Handle<Object>(Smi::FromInt(char_pos2 + char_len2))); 452 TokensCompareInput tokens_input(s1_, char_pos1, char_len1,
376 current_size_ += 3; 453 s2_, char_pos2, char_len2);
454 TokensCompareOutput tokens_output(&array_writer_, char_pos1,
455 char_pos2);
456
457 Comparator::CalculateDifference(&tokens_input, &tokens_output);
458 } else {
459 array_writer_.WriteChunk(char_pos1, char_pos2, char_len1, char_len2);
460 }
377 } 461 }
378 462
379 Handle<JSArray> GetResult() { 463 Handle<JSArray> GetResult() {
380 return array_; 464 return array_writer_.GetResult();
381 } 465 }
382 466
383 private: 467 private:
384 Handle<JSArray> array_; 468 static const int CHUNK_LEN_LIMIT = 800;
385 int current_size_; 469
470 CompareOutputArrayWriter array_writer_;
386 LineEndsWrapper line_ends1_; 471 LineEndsWrapper line_ends1_;
387 LineEndsWrapper line_ends2_; 472 LineEndsWrapper line_ends2_;
473 Handle<String> s1_;
474 Handle<String> s2_;
388 }; 475 };
389 476
390 477
391 Handle<JSArray> LiveEdit::CompareStringsLinewise(Handle<String> s1, 478 Handle<JSArray> LiveEdit::CompareStrings(Handle<String> s1,
392 Handle<String> s2) { 479 Handle<String> s2) {
393 LineEndsWrapper line_ends1(s1); 480 LineEndsWrapper line_ends1(s1);
394 LineEndsWrapper line_ends2(s2); 481 LineEndsWrapper line_ends2(s2);
395 482
396 LineArrayCompareInput 483 LineArrayCompareInput
397 input(Isolate::Current(), s1, s2, line_ends1, line_ends2); 484 input(Isolate::Current(), s1, s2, line_ends1, line_ends2);
398 LineArrayCompareOutput output(line_ends1, line_ends2); 485 TokenizingLineArrayCompareOutput output(line_ends1, line_ends2, s1, s2);
399 486
400 Comparator::CalculateDifference(&input, &output); 487 Comparator::CalculateDifference(&input, &output);
401 488
402 return output.GetResult(); 489 return output.GetResult();
403 } 490 }
404 491
405 492
406 static void CompileScriptForTracker(Isolate* isolate, Handle<Script> script) { 493 static void CompileScriptForTracker(Isolate* isolate, Handle<Script> script) {
407 // TODO(635): support extensions. 494 // TODO(635): support extensions.
408 PostponeInterruptsScope postpone(isolate); 495 PostponeInterruptsScope postpone(isolate);
(...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 1657
1571 bool LiveEditFunctionTracker::IsActive() { 1658 bool LiveEditFunctionTracker::IsActive() {
1572 return false; 1659 return false;
1573 } 1660 }
1574 1661
1575 #endif // ENABLE_DEBUGGER_SUPPORT 1662 #endif // ENABLE_DEBUGGER_SUPPORT
1576 1663
1577 1664
1578 1665
1579 } } // namespace v8::internal 1666 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/liveedit.h ('k') | src/liveedit-debugger.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698