Bug 1483449 - Simplify nsStaticAtomUtils::Lookup. r=njn
authorCameron McCormack <cam@mcc.id.au>
Thu, 16 Aug 2018 11:40:02 +1000
changeset 431870 5928090fcb23935e819e22f392367309428cb648
parent 431869 f578ca2a361ec09d98582dc9428345d9c57096ec
child 431871 a61cdb1a654ca07c48ec5dc1c3d87c2bf12f83ce
push id34451
push userebalazs@mozilla.com
push dateThu, 16 Aug 2018 09:25:15 +0000
treeherdermozilla-central@161817e6d127 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1483449
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1483449 - Simplify nsStaticAtomUtils::Lookup. r=njn
xpcom/ds/nsStaticAtomUtils.h
--- a/xpcom/ds/nsStaticAtomUtils.h
+++ b/xpcom/ds/nsStaticAtomUtils.h
@@ -8,25 +8,27 @@
 #define nsStaticAtomUtils_h
 
 #include <stdint.h>
 #include "nsAtom.h"
 #include "mozilla/ArrayUtils.h"
 #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 < static_cast<ptrdiff_t>(aCount)) {
+        return mozilla::Some(static_cast<uint32_t>(index));
       }
     }
     return mozilla::Nothing();
   }
 
   static bool IsMember(nsAtom* aAtom, const nsStaticAtom* aAtoms,
                        uint32_t aCount)
   {