Bug 1422524: Avoid calling nsAttrValue::Type twice in the common case. r=xidorn
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 02 Dec 2017 20:36:53 +0100
changeset 394735 f77500d7262c5cc07bbe7a17a4e365d547b4be4d
parent 394734 7a19568290c61d7a510b54455419b086e66cc6db
child 394736 f5921af9f1a6a35adfe68977c6437f91fc866d18
push id56425
push userecoal95@gmail.com
push dateSat, 02 Dec 2017 23:17:10 +0000
treeherderautoland@f5921af9f1a6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1422524
milestone59.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 1422524: Avoid calling nsAttrValue::Type twice in the common case. r=xidorn MozReview-Commit-ID: JCnUrlYCWv3
layout/style/ServoBindings.cpp
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -1096,31 +1096,32 @@ ClassOrClassList(Implementor* aElement, 
 {
   const nsAttrValue* attr = aElement->GetClasses();
   if (!attr) {
     return 0;
   }
 
   // For class values with only whitespace, Gecko just stores a string. For the
   // purposes of the style system, there is no class in this case.
-  if (attr->Type() == nsAttrValue::eString) {
+  nsAttrValue::ValueType type = attr->Type();
+  if (MOZ_UNLIKELY(type == nsAttrValue::eString)) {
     MOZ_ASSERT(nsContentUtils::TrimWhitespace<nsContentUtils::IsHTMLWhitespace>(
                  attr->GetStringValue()).IsEmpty());
     return 0;
   }
 
   // Single tokens are generally stored as an atom. Check that case.
-  if (attr->Type() == nsAttrValue::eAtom) {
+  if (type == nsAttrValue::eAtom) {
     *aClass = attr->GetAtomValue();
     return 1;
   }
 
   // At this point we should have an atom array. It is likely, but not
   // guaranteed, that we have two or more elements in the array.
-  MOZ_ASSERT(attr->Type() == nsAttrValue::eAtomArray);
+  MOZ_ASSERT(type == nsAttrValue::eAtomArray);
   nsTArray<RefPtr<nsAtom>>* atomArray = attr->GetAtomArrayValue();
   uint32_t length = atomArray->Length();
 
   // Special case: zero elements.
   if (length == 0) {
     return 0;
   }