Bug 1422524: Avoid calling nsAttrValue::Type twice in the common case. r?xidorn draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sat, 02 Dec 2017 20:36:53 +0100
changeset 706605 ab636dc59b02c16448eec83a84e384e3dcab7f72
parent 706604 23520e5622859a7c5b0d1d28ebe25fe14ad1c658
child 706606 009ebc83fce1e531fb78a90f9e39d52dcf2a64ca
child 706626 45813309d78d677b3cb47e3806f59dcee53d652c
push id91848
push userbmo:emilio@crisal.io
push dateSat, 02 Dec 2017 19:37:45 +0000
reviewersxidorn
bugs1422524
milestone59.0a1
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;
   }