Bug 1483449 - Simplify nsStaticAtomUtils::Lookup. r=njn

This commit is contained in:
Cameron McCormack 2018-08-16 11:40:02 +10:00
parent 6d732b690f
commit a4d0161e79

View File

@ -13,15 +13,17 @@
#include "mozilla/Maybe.h"
// This class holds basic operations on arrays of static atoms.
class nsStaticAtomUtils {
class nsStaticAtomUtils
{
public:
static mozilla::Maybe<uint32_t> Lookup(nsAtom* aAtom,
const nsStaticAtom* aAtoms,
uint32_t aCount)
{
for (uint32_t i = 0; i < aCount; i++) {
if (aAtom == &aAtoms[i]) {
return mozilla::Some(i);
if (aAtom->IsStatic()) {
ptrdiff_t index = aAtom->AsStatic() - aAtoms;
if (index >= 0 && index < aCount) {
return mozilla::Some(static_cast<uint32_t>(index));
}
}
return mozilla::Nothing();