Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/nsStaticAtomUtils.h
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
#ifndef nsStaticAtomUtils_h
8
#define nsStaticAtomUtils_h
9
10
#include <stdint.h>
11
#include "nsAtom.h"
12
#include "mozilla/ArrayUtils.h"
13
#include "mozilla/Maybe.h"
14
15
// This class holds basic operations on arrays of static atoms.
16
class nsStaticAtomUtils
17
{
18
public:
19
  static mozilla::Maybe<uint32_t> Lookup(nsAtom* aAtom,
20
                                         const nsStaticAtom* aAtoms,
21
                                         uint32_t aCount)
22
0
  {
23
0
    if (aAtom->IsStatic()) {
24
0
      ptrdiff_t index = aAtom->AsStatic() - aAtoms;
25
0
      if (index >= 0 && index < static_cast<ptrdiff_t>(aCount)) {
26
0
        return mozilla::Some(static_cast<uint32_t>(index));
27
0
      }
28
0
    }
29
0
    return mozilla::Nothing();
30
0
  }
31
32
  static bool IsMember(nsAtom* aAtom, const nsStaticAtom* aAtoms,
33
                       uint32_t aCount)
34
0
  {
35
0
    return Lookup(aAtom, aAtoms, aCount).isSome();
36
0
  }
37
};
38
39
#endif // nsStaticAtomUtils_h