Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/ds/nsGkAtoms.cpp
Line
Count
Source
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 "nsGkAtoms.h"
8
9
// Register an array of static atoms with the atom table.
10
void
11
NS_RegisterStaticAtoms(const nsStaticAtom* aAtoms, size_t aAtomsLen);
12
13
namespace mozilla {
14
namespace detail {
15
16
extern constexpr GkAtoms gGkAtoms = {
17
  // The initialization of each atom's string.
18
  #define GK_ATOM(name_, value_, hash_, type_, atom_type_) \
19
    u"" value_,
20
  #include "nsGkAtomList.h"
21
  #undef GK_ATOM
22
  {
23
    // The initialization of the atoms themselves.
24
    //
25
    // Note that |value_| is an 8-bit string, and so |sizeof(value_)| is equal
26
    // to the number of chars (including the terminating '\0'). The |u""| prefix
27
    // converts |value_| to a 16-bit string.
28
    #define GK_ATOM(name_, value_, hash_, type_, atom_type_)              \
29
      nsStaticAtom(u"" value_,                                            \
30
          sizeof(value_) - 1,                                             \
31
          hash_,                                                          \
32
          offsetof(GkAtoms,                                               \
33
                   mAtoms[static_cast<size_t>(GkAtoms::Atoms::name_)]) -  \
34
          offsetof(GkAtoms, name_##_string)),
35
    #include "nsGkAtomList.h"
36
    #undef GK_ATOM
37
  }
38
};
39
40
} // namespace detail
41
} // namespace mozilla
42
43
const nsStaticAtom* const nsGkAtoms::sAtoms = mozilla::detail::gGkAtoms.mAtoms;
44
45
// Definition of the pointer to the static atom.
46
#define GK_ATOM(name_, value_, hash_, type_, atom_type_)                   \
47
  type_* nsGkAtoms::name_ = const_cast<type_*>(static_cast<const type_*>(  \
48
    &mozilla::detail::gGkAtoms.mAtoms[                                     \
49
      static_cast<size_t>(mozilla::detail::GkAtoms::Atoms::name_)]));
50
#include "nsGkAtomList.h"
51
#undef GK_ATOM
52
53
void nsGkAtoms::RegisterStaticAtoms()
54
3
{
55
3
  NS_RegisterStaticAtoms(sAtoms, sAtomsLen);
56
3
}
57