LCOV - code coverage report
Current view: top level - xpcom/string - nsTSubstringTuple.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 22 23 95.7 %
Date: 2017-07-14 16:53:18 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #include "mozilla/CheckedInt.h"
       8             : 
       9             : /**
      10             :  * computes the aggregate string length
      11             :  */
      12             : 
      13             : nsTSubstringTuple_CharT::size_type
      14        3751 : nsTSubstringTuple_CharT::Length() const
      15             : {
      16        3751 :   mozilla::CheckedInt<size_type> len;
      17        3751 :   if (mHead) {
      18         301 :     len = mHead->Length();
      19             :   } else {
      20        3450 :     len = mFragA->Length();
      21             :   }
      22             : 
      23        3751 :   len += mFragB->Length();
      24        3751 :   MOZ_RELEASE_ASSERT(len.isValid(), "Substring tuple length is invalid");
      25        3751 :   return len.value();
      26             : }
      27             : 
      28             : 
      29             : /**
      30             :  * writes the aggregate string to the given buffer. aBufLen is assumed
      31             :  * to be equal to or greater than the value returned by the Length()
      32             :  * method.  the string written to |aBuf| is not null-terminated.
      33             :  */
      34             : 
      35             : void
      36        3751 : nsTSubstringTuple_CharT::WriteTo(char_type* aBuf, uint32_t aBufLen) const
      37             : {
      38        3751 :   MOZ_RELEASE_ASSERT(aBufLen >= mFragB->Length(), "buffer too small");
      39        3751 :   uint32_t headLen = aBufLen - mFragB->Length();
      40        3751 :   if (mHead) {
      41         301 :     mHead->WriteTo(aBuf, headLen);
      42             :   } else {
      43        3450 :     MOZ_RELEASE_ASSERT(mFragA->Length() == headLen, "buffer incorrectly sized");
      44        3450 :     char_traits::copy(aBuf, mFragA->Data(), mFragA->Length());
      45             :   }
      46             : 
      47        3751 :   char_traits::copy(aBuf + headLen, mFragB->Data(), mFragB->Length());
      48        3751 : }
      49             : 
      50             : 
      51             : /**
      52             :  * returns true if this tuple is dependent on (i.e., overlapping with)
      53             :  * the given char sequence.
      54             :  */
      55             : 
      56             : bool
      57        3751 : nsTSubstringTuple_CharT::IsDependentOn(const char_type* aStart,
      58             :                                        const char_type* aEnd) const
      59             : {
      60             :   // we aStart with the right-most fragment since it is faster to check.
      61             : 
      62        3751 :   if (mFragB->IsDependentOn(aStart, aEnd)) {
      63           0 :     return true;
      64             :   }
      65             : 
      66        3751 :   if (mHead) {
      67         301 :     return mHead->IsDependentOn(aStart, aEnd);
      68             :   }
      69             : 
      70        3450 :   return mFragA->IsDependentOn(aStart, aEnd);
      71             : }

Generated by: LCOV version 1.13