Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/string/nsTSubstringTuple.cpp
Line
Count
Source (jump to first uncovered line)
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
template <typename T>
14
typename nsTSubstringTuple<T>::size_type
15
nsTSubstringTuple<T>::Length() const
16
42.7k
{
17
42.7k
  mozilla::CheckedInt<size_type> len;
18
42.7k
  if (mHead) {
19
5.58k
    len = mHead->Length();
20
37.1k
  } else {
21
37.1k
    len = mFragA->Length();
22
37.1k
  }
23
42.7k
24
42.7k
  len += mFragB->Length();
25
42.7k
  MOZ_RELEASE_ASSERT(len.isValid(), "Substring tuple length is invalid");
26
42.7k
  return len.value();
27
42.7k
}
nsTSubstringTuple<char>::Length() const
Line
Count
Source
16
42.7k
{
17
42.7k
  mozilla::CheckedInt<size_type> len;
18
42.7k
  if (mHead) {
19
5.58k
    len = mHead->Length();
20
37.1k
  } else {
21
37.1k
    len = mFragA->Length();
22
37.1k
  }
23
42.7k
24
42.7k
  len += mFragB->Length();
25
42.7k
  MOZ_RELEASE_ASSERT(len.isValid(), "Substring tuple length is invalid");
26
42.7k
  return len.value();
27
42.7k
}
nsTSubstringTuple<char16_t>::Length() const
Line
Count
Source
16
15
{
17
15
  mozilla::CheckedInt<size_type> len;
18
15
  if (mHead) {
19
0
    len = mHead->Length();
20
15
  } else {
21
15
    len = mFragA->Length();
22
15
  }
23
15
24
15
  len += mFragB->Length();
25
15
  MOZ_RELEASE_ASSERT(len.isValid(), "Substring tuple length is invalid");
26
15
  return len.value();
27
15
}
28
29
30
/**
31
 * writes the aggregate string to the given buffer. aBufLen is assumed
32
 * to be equal to or greater than the value returned by the Length()
33
 * method.  the string written to |aBuf| is not null-terminated.
34
 */
35
36
template <typename T>
37
void
38
nsTSubstringTuple<T>::WriteTo(char_type* aBuf, uint32_t aBufLen) const
39
42.7k
{
40
42.7k
  MOZ_RELEASE_ASSERT(aBufLen >= mFragB->Length(), "buffer too small");
41
42.7k
  uint32_t headLen = aBufLen - mFragB->Length();
42
42.7k
  if (mHead) {
43
5.58k
    mHead->WriteTo(aBuf, headLen);
44
37.1k
  } else {
45
37.1k
    MOZ_RELEASE_ASSERT(mFragA->Length() == headLen, "buffer incorrectly sized");
46
37.1k
    char_traits::copy(aBuf, mFragA->Data(), mFragA->Length());
47
37.1k
  }
48
42.7k
49
42.7k
  char_traits::copy(aBuf + headLen, mFragB->Data(), mFragB->Length());
50
42.7k
}
nsTSubstringTuple<char>::WriteTo(char*, unsigned int) const
Line
Count
Source
39
42.7k
{
40
42.7k
  MOZ_RELEASE_ASSERT(aBufLen >= mFragB->Length(), "buffer too small");
41
42.7k
  uint32_t headLen = aBufLen - mFragB->Length();
42
42.7k
  if (mHead) {
43
5.58k
    mHead->WriteTo(aBuf, headLen);
44
37.1k
  } else {
45
37.1k
    MOZ_RELEASE_ASSERT(mFragA->Length() == headLen, "buffer incorrectly sized");
46
37.1k
    char_traits::copy(aBuf, mFragA->Data(), mFragA->Length());
47
37.1k
  }
48
42.7k
49
42.7k
  char_traits::copy(aBuf + headLen, mFragB->Data(), mFragB->Length());
50
42.7k
}
nsTSubstringTuple<char16_t>::WriteTo(char16_t*, unsigned int) const
Line
Count
Source
39
15
{
40
15
  MOZ_RELEASE_ASSERT(aBufLen >= mFragB->Length(), "buffer too small");
41
15
  uint32_t headLen = aBufLen - mFragB->Length();
42
15
  if (mHead) {
43
0
    mHead->WriteTo(aBuf, headLen);
44
15
  } else {
45
15
    MOZ_RELEASE_ASSERT(mFragA->Length() == headLen, "buffer incorrectly sized");
46
15
    char_traits::copy(aBuf, mFragA->Data(), mFragA->Length());
47
15
  }
48
15
49
15
  char_traits::copy(aBuf + headLen, mFragB->Data(), mFragB->Length());
50
15
}
51
52
53
/**
54
 * returns true if this tuple is dependent on (i.e., overlapping with)
55
 * the given char sequence.
56
 */
57
58
template <typename T>
59
bool
60
nsTSubstringTuple<T>::IsDependentOn(const char_type* aStart,
61
                                    const char_type* aEnd) const
62
42.7k
{
63
42.7k
  // we aStart with the right-most fragment since it is faster to check.
64
42.7k
65
42.7k
  if (mFragB->IsDependentOn(aStart, aEnd)) {
66
0
    return true;
67
0
  }
68
42.7k
69
42.7k
  if (mHead) {
70
5.58k
    return mHead->IsDependentOn(aStart, aEnd);
71
5.58k
  }
72
37.1k
73
37.1k
  return mFragA->IsDependentOn(aStart, aEnd);
74
37.1k
}
nsTSubstringTuple<char>::IsDependentOn(char const*, char const*) const
Line
Count
Source
62
42.7k
{
63
42.7k
  // we aStart with the right-most fragment since it is faster to check.
64
42.7k
65
42.7k
  if (mFragB->IsDependentOn(aStart, aEnd)) {
66
0
    return true;
67
0
  }
68
42.7k
69
42.7k
  if (mHead) {
70
5.58k
    return mHead->IsDependentOn(aStart, aEnd);
71
5.58k
  }
72
37.1k
73
37.1k
  return mFragA->IsDependentOn(aStart, aEnd);
74
37.1k
}
nsTSubstringTuple<char16_t>::IsDependentOn(char16_t const*, char16_t const*) const
Line
Count
Source
62
15
{
63
15
  // we aStart with the right-most fragment since it is faster to check.
64
15
65
15
  if (mFragB->IsDependentOn(aStart, aEnd)) {
66
0
    return true;
67
0
  }
68
15
69
15
  if (mHead) {
70
0
    return mHead->IsDependentOn(aStart, aEnd);
71
0
  }
72
15
73
15
  return mFragA->IsDependentOn(aStart, aEnd);
74
15
}