LCOV - code coverage report
Current view: top level - src - utils-inl.h (source / functions) Hit Total Coverage
Test: app.info Lines: 21 21 100.0 %
Date: 2019-03-21 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright 2016 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             : #ifndef V8_UTILS_INL_H_
       6             : #define V8_UTILS_INL_H_
       7             : 
       8             : #include "src/utils.h"
       9             : 
      10             : #include "include/v8-platform.h"
      11             : #include "src/base/platform/time.h"
      12             : #include "src/char-predicates-inl.h"
      13             : #include "src/v8.h"
      14             : 
      15             : namespace v8 {
      16             : namespace internal {
      17             : 
      18             : class TimedScope {
      19             :  public:
      20             :   explicit TimedScope(double* result)
      21      560734 :       : start_(TimestampMs()), result_(result) {}
      22             : 
      23      561334 :   ~TimedScope() { *result_ = TimestampMs() - start_; }
      24             : 
      25             :  private:
      26     1120786 :   static inline double TimestampMs() {
      27     1120786 :     return V8::GetCurrentPlatform()->MonotonicallyIncreasingTime() *
      28     1119923 :            static_cast<double>(base::Time::kMillisecondsPerSecond);
      29             :   }
      30             : 
      31             :   double start_;
      32             :   double* result_;
      33             : };
      34             : 
      35             : template <typename Char>
      36             : bool TryAddIndexChar(uint32_t* index, Char c) {
      37    89594726 :   if (!IsDecimalDigit(c)) return false;
      38    27733408 :   int d = c - '0';
      39    27733408 :   if (*index > 429496729U - ((d + 3) >> 3)) return false;
      40    27729707 :   *index = (*index) * 10 + d;
      41             :   return true;
      42             : }
      43             : 
      44             : template <typename Stream>
      45      949519 : bool StringToArrayIndex(Stream* stream, uint32_t* index) {
      46      949363 :   uint16_t ch = stream->GetNext();
      47             : 
      48             :   // If the string begins with a '0' character, it must only consist
      49             :   // of it to be a legal array index.
      50      949519 :   if (ch == '0') {
      51      107447 :     *index = 0;
      52      107447 :     return !stream->HasMore();
      53             :   }
      54             : 
      55             :   // Convert string to uint32 array index; character by character.
      56      842072 :   if (!IsDecimalDigit(ch)) return false;
      57        4357 :   int d = ch - '0';
      58        4357 :   uint32_t result = d;
      59       27988 :   while (stream->HasMore()) {
      60       50210 :     if (!TryAddIndexChar(&result, stream->GetNext())) return false;
      61             :   }
      62             : 
      63        2186 :   *index = result;
      64        2186 :   return true;
      65             : }
      66             : 
      67             : }  // namespace internal
      68             : }  // namespace v8
      69             : 
      70             : #endif  // V8_UTILS_INL_H_

Generated by: LCOV version 1.10