| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/scanner-character-streams.h" | 7 #include "src/scanner-character-streams.h" |
| 8 | 8 |
| 9 #include "include/v8.h" | 9 #include "include/v8.h" |
| 10 #include "src/handles.h" | 10 #include "src/handles.h" |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 // Did we use all the data in the data chunk? | 381 // Did we use all the data in the data chunk? |
| 382 if (current_data_offset_ == current_data_length_) { | 382 if (current_data_offset_ == current_data_length_) { |
| 383 FlushCurrent(); | 383 FlushCurrent(); |
| 384 } | 384 } |
| 385 } | 385 } |
| 386 return data_in_buffer; | 386 return data_in_buffer; |
| 387 } | 387 } |
| 388 | 388 |
| 389 | 389 |
| 390 bool ExternalStreamingStream::SetBookmark() { | 390 bool ExternalStreamingStream::SetBookmark() { |
| 391 DCHECK(utf8_split_char_buffer_length_ == 0); // We can't be within a char. | |
| 392 | |
| 393 // Bookmarking for this stream is a bit more complex than expected, since | 391 // Bookmarking for this stream is a bit more complex than expected, since |
| 394 // the stream state is distributed over several places: | 392 // the stream state is distributed over several places: |
| 395 // - pos_ (inherited from Utf16CharacterStream) | 393 // - pos_ (inherited from Utf16CharacterStream) |
| 396 // - buffer_cursor_ and buffer_end_ (also from Utf16CharacterStream) | 394 // - buffer_cursor_ and buffer_end_ (also from Utf16CharacterStream) |
| 397 // - buffer_ (from BufferedUtf16CharacterStream) | 395 // - buffer_ (from BufferedUtf16CharacterStream) |
| 398 // - current_data_ (+ .._offset_ and .._length) (this class) | 396 // - current_data_ (+ .._offset_ and .._length) (this class) |
| 397 // - utf8_split_char_buffer_* (a partial utf8 symbol at the block boundary) |
| 399 // | 398 // |
| 400 // The underlying source_stream_ instance likely could re-construct this | 399 // The underlying source_stream_ instance likely could re-construct this |
| 401 // local data for us, but with the given interfaces we have no way of | 400 // local data for us, but with the given interfaces we have no way of |
| 402 // accomplishing this. Thus, we'll have to save all data locally. | 401 // accomplishing this. Thus, we'll have to save all data locally. |
| 403 // | 402 // |
| 404 // What gets saved where: | 403 // What gets saved where: |
| 405 // - pos_ => bookmark_ | 404 // - pos_ => bookmark_ |
| 406 // - buffer_[buffer_cursor_ .. buffer_end_] => bookmark_buffer_ | 405 // - buffer_[buffer_cursor_ .. buffer_end_] => bookmark_buffer_ |
| 407 // - current_data_[.._offset_ .. .._length_] => bookmark_data_ | 406 // - current_data_[.._offset_ .. .._length_] => bookmark_data_ |
| 407 // - utf8_split_char_buffer_* => bookmark_utf8_split... |
| 408 | 408 |
| 409 bookmark_ = pos_; | 409 bookmark_ = pos_; |
| 410 | 410 |
| 411 size_t buffer_length = buffer_end_ - buffer_cursor_; | 411 size_t buffer_length = buffer_end_ - buffer_cursor_; |
| 412 bookmark_buffer_.Dispose(); | 412 bookmark_buffer_.Dispose(); |
| 413 bookmark_buffer_ = Vector<uint16_t>::New(static_cast<int>(buffer_length)); | 413 bookmark_buffer_ = Vector<uint16_t>::New(static_cast<int>(buffer_length)); |
| 414 CopyCharsUnsigned(bookmark_buffer_.start(), buffer_cursor_, buffer_length); | 414 CopyCharsUnsigned(bookmark_buffer_.start(), buffer_cursor_, buffer_length); |
| 415 | 415 |
| 416 size_t data_length = current_data_length_ - current_data_offset_; | 416 size_t data_length = current_data_length_ - current_data_offset_; |
| 417 bookmark_data_.Dispose(); | 417 bookmark_data_.Dispose(); |
| 418 bookmark_data_ = Vector<uint8_t>::New(static_cast<int>(data_length)); | 418 bookmark_data_ = Vector<uint8_t>::New(static_cast<int>(data_length)); |
| 419 CopyBytes(bookmark_data_.start(), current_data_ + current_data_offset_, | 419 CopyBytes(bookmark_data_.start(), current_data_ + current_data_offset_, |
| 420 data_length); | 420 data_length); |
| 421 | 421 |
| 422 bookmark_utf8_split_char_buffer_length_ = utf8_split_char_buffer_length_; |
| 423 for (size_t i = 0; i < utf8_split_char_buffer_length_; i++) { |
| 424 bookmark_utf8_split_char_buffer_[i] = utf8_split_char_buffer_[i]; |
| 425 } |
| 426 |
| 422 return source_stream_->SetBookmark(); | 427 return source_stream_->SetBookmark(); |
| 423 } | 428 } |
| 424 | 429 |
| 425 | 430 |
| 426 void ExternalStreamingStream::ResetToBookmark() { | 431 void ExternalStreamingStream::ResetToBookmark() { |
| 427 source_stream_->ResetToBookmark(); | 432 source_stream_->ResetToBookmark(); |
| 428 FlushCurrent(); | 433 FlushCurrent(); |
| 429 | 434 |
| 430 pos_ = bookmark_; | 435 pos_ = bookmark_; |
| 431 | 436 |
| 432 // current_data_ can point to bookmark_data_'s buffer. | 437 // current_data_ can point to bookmark_data_'s buffer. |
| 433 current_data_ = bookmark_data_.start(); | 438 current_data_ = bookmark_data_.start(); |
| 434 current_data_offset_ = 0; | 439 current_data_offset_ = 0; |
| 435 current_data_length_ = bookmark_data_.length(); | 440 current_data_length_ = bookmark_data_.length(); |
| 436 | 441 |
| 437 // bookmark_buffer_ needs to be copied to buffer_. | 442 // bookmark_buffer_ needs to be copied to buffer_. |
| 438 CopyCharsUnsigned(buffer_, bookmark_buffer_.begin(), | 443 CopyCharsUnsigned(buffer_, bookmark_buffer_.begin(), |
| 439 bookmark_buffer_.length()); | 444 bookmark_buffer_.length()); |
| 440 buffer_cursor_ = buffer_; | 445 buffer_cursor_ = buffer_; |
| 441 buffer_end_ = buffer_ + bookmark_buffer_.length(); | 446 buffer_end_ = buffer_ + bookmark_buffer_.length(); |
| 447 |
| 448 // utf8 split char buffer |
| 449 utf8_split_char_buffer_length_ = bookmark_utf8_split_char_buffer_length_; |
| 450 for (size_t i = 0; i < bookmark_utf8_split_char_buffer_length_; i++) { |
| 451 utf8_split_char_buffer_[i] = bookmark_utf8_split_char_buffer_[i]; |
| 452 } |
| 442 } | 453 } |
| 443 | 454 |
| 444 | 455 |
| 445 void ExternalStreamingStream::FlushCurrent() { | 456 void ExternalStreamingStream::FlushCurrent() { |
| 446 delete[] current_data_; | 457 delete[] current_data_; |
| 447 current_data_ = NULL; | 458 current_data_ = NULL; |
| 448 current_data_length_ = 0; | 459 current_data_length_ = 0; |
| 449 current_data_offset_ = 0; | 460 current_data_offset_ = 0; |
| 450 } | 461 } |
| 451 | 462 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 return true; | 549 return true; |
| 539 } | 550 } |
| 540 | 551 |
| 541 | 552 |
| 542 void ExternalTwoByteStringUtf16CharacterStream::ResetToBookmark() { | 553 void ExternalTwoByteStringUtf16CharacterStream::ResetToBookmark() { |
| 543 DCHECK(bookmark_ != kNoBookmark); | 554 DCHECK(bookmark_ != kNoBookmark); |
| 544 pos_ = bookmark_; | 555 pos_ = bookmark_; |
| 545 buffer_cursor_ = raw_data_ + bookmark_; | 556 buffer_cursor_ = raw_data_ + bookmark_; |
| 546 } | 557 } |
| 547 } } // namespace v8::internal | 558 } } // namespace v8::internal |
| OLD | NEW |