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/. */
7 #ifndef nsStaticAtomUtils_h
8 #define nsStaticAtomUtils_h
12 #include "mozilla/ArrayUtils.h"
13 #include "mozilla/Maybe.h"
15 // This class holds basic operations on arrays of static atoms.
16 class nsStaticAtomUtils
{
18 static mozilla::Maybe
<uint32_t> Lookup(nsAtom
* aAtom
,
19 const nsStaticAtom
* aAtoms
,
21 if (aAtom
->IsStatic()) {
22 ptrdiff_t index
= aAtom
->AsStatic() - aAtoms
;
23 if (index
>= 0 && index
< static_cast<ptrdiff_t>(aCount
)) {
24 return mozilla::Some(static_cast<uint32_t>(index
));
27 return mozilla::Nothing();
30 static bool IsMember(nsAtom
* aAtom
, const nsStaticAtom
* aAtoms
,
32 return Lookup(aAtom
, aAtoms
, aCount
).isSome();
36 #endif // nsStaticAtomUtils_h