From 8d12260f422f5fd1d9097bc28c2a4d5132f686c4 Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Mon, 6 May 2013 11:05:44 -0400 Subject: [PATCH] Bug 868557. Explicitly unalias list in nsStyleContext::AddChild() r=dbaron Clang and GCC probably MSVC are not able to unalias list because they don't realize that mEmptyChild and mChild can't alias mNextSibling and mPrevSibling. If we explicitly dereference list we get better code, saving 3 instructions with clang. --- layout/style/nsStyleContext.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/layout/style/nsStyleContext.cpp b/layout/style/nsStyleContext.cpp index fdf6b764620..8b510ebd167 100644 --- a/layout/style/nsStyleContext.cpp +++ b/layout/style/nsStyleContext.cpp @@ -110,17 +110,20 @@ void nsStyleContext::AddChild(nsStyleContext* aChild) aChild->mNextSibling == aChild, "child already in a child list"); - nsStyleContext **list = aChild->mRuleNode->IsRoot() ? &mEmptyChild : &mChild; + nsStyleContext **listPtr = aChild->mRuleNode->IsRoot() ? &mEmptyChild : &mChild; + // Explicitly dereference listPtr so that compiler doesn't have to know that mNextSibling + // etc. don't alias with what ever listPtr points at. + nsStyleContext *list = *listPtr; // Insert at the beginning of the list. See also FindChildWithRules. - if (*list) { + if (list) { // Link into existing elements, if there are any. - aChild->mNextSibling = (*list); - aChild->mPrevSibling = (*list)->mPrevSibling; - (*list)->mPrevSibling->mNextSibling = aChild; - (*list)->mPrevSibling = aChild; + aChild->mNextSibling = list; + aChild->mPrevSibling = list->mPrevSibling; + list->mPrevSibling->mNextSibling = aChild; + list->mPrevSibling = aChild; } - (*list) = aChild; + (*listPtr) = aChild; } void nsStyleContext::RemoveChild(nsStyleContext* aChild)