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

Side by Side Diff: src/parsing/scanner-character-streams.cc

Issue 2184393002: Implement a character stream for external one byte streams (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 4 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
« no previous file with comments | « src/parsing/scanner-character-streams.h ('k') | test/cctest/test-parsing.cc » ('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 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/parsing/scanner-character-streams.h" 5 #include "src/parsing/scanner-character-streams.h"
6 6
7 #include "include/v8.h" 7 #include "include/v8.h"
8 #include "src/globals.h" 8 #include "src/globals.h"
9 #include "src/handles.h" 9 #include "src/handles.h"
10 #include "src/list-inl.h" // TODO(mstarzinger): Temporary cycle breaker! 10 #include "src/list-inl.h" // TODO(mstarzinger): Temporary cycle breaker!
11 #include "src/objects.h" 11 #include "src/objects-inl.h"
12 #include "src/unicode-inl.h" 12 #include "src/unicode-inl.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 16
17 namespace { 17 namespace {
18 18
19 size_t CopyCharsHelper(uint16_t* dest, size_t length, const uint8_t* src, 19 size_t CopyCharsHelper(uint16_t* dest, size_t length, const uint8_t* src,
20 size_t* src_pos, size_t src_length, 20 size_t* src_pos, size_t src_length,
21 ScriptCompiler::StreamedSource::Encoding encoding) { 21 ScriptCompiler::StreamedSource::Encoding encoding) {
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 } 552 }
553 } 553 }
554 554
555 555
556 // ---------------------------------------------------------------------------- 556 // ----------------------------------------------------------------------------
557 // ExternalTwoByteStringUtf16CharacterStream 557 // ExternalTwoByteStringUtf16CharacterStream
558 558
559 ExternalTwoByteStringUtf16CharacterStream:: 559 ExternalTwoByteStringUtf16CharacterStream::
560 ~ExternalTwoByteStringUtf16CharacterStream() { } 560 ~ExternalTwoByteStringUtf16CharacterStream() { }
561 561
562
563 ExternalTwoByteStringUtf16CharacterStream:: 562 ExternalTwoByteStringUtf16CharacterStream::
564 ExternalTwoByteStringUtf16CharacterStream( 563 ExternalTwoByteStringUtf16CharacterStream(
565 Handle<ExternalTwoByteString> data, int start_position, 564 Handle<ExternalTwoByteString> data, int start_position,
566 int end_position) 565 int end_position)
567 : Utf16CharacterStream(), 566 : raw_data_(data->GetTwoByteData(start_position)), bookmark_(kNoBookmark) {
568 source_(data),
569 raw_data_(data->GetTwoByteData(start_position)),
570 bookmark_(kNoBookmark) {
571 buffer_cursor_ = raw_data_, 567 buffer_cursor_ = raw_data_,
572 buffer_end_ = raw_data_ + (end_position - start_position); 568 buffer_end_ = raw_data_ + (end_position - start_position);
573 pos_ = start_position; 569 pos_ = start_position;
574 } 570 }
575 571
576 572
577 bool ExternalTwoByteStringUtf16CharacterStream::SetBookmark() { 573 bool ExternalTwoByteStringUtf16CharacterStream::SetBookmark() {
578 bookmark_ = pos_; 574 bookmark_ = pos_;
579 return true; 575 return true;
580 } 576 }
581 577
582 578
583 void ExternalTwoByteStringUtf16CharacterStream::ResetToBookmark() { 579 void ExternalTwoByteStringUtf16CharacterStream::ResetToBookmark() {
584 DCHECK(bookmark_ != kNoBookmark); 580 DCHECK(bookmark_ != kNoBookmark);
585 pos_ = bookmark_; 581 pos_ = bookmark_;
586 buffer_cursor_ = raw_data_ + bookmark_; 582 buffer_cursor_ = raw_data_ + bookmark_;
587 } 583 }
584
585 // ----------------------------------------------------------------------------
586 // ExternalOneByteStringUtf16CharacterStream
587
588 ExternalOneByteStringUtf16CharacterStream::
589 ~ExternalOneByteStringUtf16CharacterStream() {}
590
591 ExternalOneByteStringUtf16CharacterStream::
592 ExternalOneByteStringUtf16CharacterStream(
593 Handle<ExternalOneByteString> data, int start_position,
594 int end_position)
595 : raw_data_(data->GetChars()),
596 length_(end_position),
597 bookmark_(kNoBookmark) {
598 DCHECK(end_position >= start_position);
599 pos_ = start_position;
600 }
601
602 bool ExternalOneByteStringUtf16CharacterStream::SetBookmark() {
603 bookmark_ = pos_;
604 return true;
605 }
606
607 void ExternalOneByteStringUtf16CharacterStream::ResetToBookmark() {
608 DCHECK(bookmark_ != kNoBookmark);
609 pos_ = bookmark_;
610 buffer_cursor_ = buffer_;
611 buffer_end_ = buffer_ + FillBuffer(pos_);
612 }
613
614 size_t ExternalOneByteStringUtf16CharacterStream::BufferSeekForward(
615 size_t delta) {
616 size_t old_pos = pos_;
617 pos_ = Min(pos_ + delta, length_);
618 ReadBlock();
619 return pos_ - old_pos;
620 }
621
622 size_t ExternalOneByteStringUtf16CharacterStream::FillBuffer(size_t from_pos) {
623 if (from_pos >= length_) return 0;
624 size_t length = Min(kBufferSize, length_ - from_pos);
625 for (size_t i = 0; i < length; ++i) {
626 buffer_[i] = static_cast<uc16>(raw_data_[from_pos + i]);
627 }
628 return length;
629 }
630
588 } // namespace internal 631 } // namespace internal
589 } // namespace v8 632 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/scanner-character-streams.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698