LCOV - code coverage report
Current view: top level - src - unicode-decoder.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 36 40 90.0 %
Date: 2019-02-19 Functions: 7 8 87.5 %

          Line data    Source code
       1             : // Copyright 2014 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : 
       6             : #include "src/unicode-inl.h"
       7             : #include "src/unicode-decoder.h"
       8             : #include <stdio.h>
       9             : #include <stdlib.h>
      10             : 
      11             : namespace unibrow {
      12             : 
      13   174058642 : uint16_t Utf8Iterator::operator*() {
      14   174062567 :   if (V8_UNLIKELY(char_ > Utf16::kMaxNonSurrogateCharCode)) {
      15             :     return trailing_ ? Utf16::TrailSurrogate(char_)
      16         176 :                      : Utf16::LeadSurrogate(char_);
      17             :   }
      18             : 
      19             :   DCHECK_EQ(trailing_, false);
      20   174062439 :   return char_;
      21             : }
      22             : 
      23   199483519 : Utf8Iterator& Utf8Iterator::operator++() {
      24   199483519 :   if (V8_UNLIKELY(this->Done())) {
      25         584 :     char_ = Utf8::kBufferEmpty;
      26         584 :     return *this;
      27             :   }
      28             : 
      29   199482935 :   if (V8_UNLIKELY(char_ > Utf16::kMaxNonSurrogateCharCode && !trailing_)) {
      30          74 :     trailing_ = true;
      31          74 :     return *this;
      32             :   }
      33             : 
      34   199482861 :   trailing_ = false;
      35   199482861 :   offset_ = cursor_;
      36             : 
      37             :   char_ =
      38             :       Utf8::ValueOf(reinterpret_cast<const uint8_t*>(stream_.begin()) + cursor_,
      39   398965722 :                     stream_.length() - cursor_, &cursor_);
      40   199482869 :   return *this;
      41             : }
      42             : 
      43           0 : Utf8Iterator Utf8Iterator::operator++(int) {
      44           0 :   Utf8Iterator old(*this);
      45           0 :   ++*this;
      46           0 :   return old;
      47             : }
      48             : 
      49   212426136 : bool Utf8Iterator::Done() {
      50   823829108 :   return offset_ == static_cast<size_t>(stream_.length());
      51             : }
      52             : 
      53         145 : void Utf8DecoderBase::Reset(uint16_t* buffer, size_t buffer_length,
      54             :                             const v8::internal::Vector<const char>& stream) {
      55             :   size_t utf16_length = 0;
      56             : 
      57             :   Utf8Iterator it = Utf8Iterator(stream);
      58             :   // Loop until stream is read, writing to buffer as long as buffer has space.
      59        6763 :   while (utf16_length < buffer_length && !it.Done()) {
      60        6482 :     *buffer++ = *it;
      61        3241 :     ++it;
      62        3241 :     utf16_length++;
      63             :   }
      64         145 :   bytes_read_ = it.Offset();
      65         145 :   trailing_ = it.Trailing();
      66         145 :   chars_written_ = utf16_length;
      67             : 
      68             :   // Now that writing to buffer is done, we just need to calculate utf16_length
      69         974 :   while (!it.Done()) {
      70         684 :     ++it;
      71         684 :     utf16_length++;
      72             :   }
      73         145 :   utf16_length_ = utf16_length;
      74         145 : }
      75             : 
      76           9 : void Utf8DecoderBase::WriteUtf16Slow(
      77             :     uint16_t* data, size_t length,
      78             :     const v8::internal::Vector<const char>& stream, size_t offset,
      79             :     bool trailing) {
      80             :   Utf8Iterator it = Utf8Iterator(stream, offset, trailing);
      81         693 :   while (!it.Done()) {
      82             :     DCHECK_GT(length--, 0);
      83        1368 :     *data++ = *it;
      84         684 :     ++it;
      85             :   }
      86           9 : }
      87             : 
      88      178779 : }  // namespace unibrow

Generated by: LCOV version 1.10