Bug 1372061 - Change StyleChildrenIterator FFI functions to use placement new/delete. r=bholley

MozReview-Commit-ID: BEWvJcaJxA

--HG--
extra : rebase_source : 48b4982001a305b95a88578cb278c3c6e4beac70
This commit is contained in:
Cameron McCormack 2017-06-27 23:56:13 -07:00
parent 4cfbfe320e
commit a0ce63693c
5 changed files with 26 additions and 20 deletions

View File

@ -264,8 +264,11 @@ private:
*
* Note: it assumes that no mutation of the DOM or frame tree takes place during
* iteration, and will break horribly if that is not true.
*
* We require this to be memmovable since Rust code can create and move
* StyleChildrenIterators.
*/
class StyleChildrenIterator : private AllChildrenIterator
class MOZ_NEEDS_MEMMOVABLE_MEMBERS StyleChildrenIterator : private AllChildrenIterator
{
public:
explicit StyleChildrenIterator(const nsIContent* aContent)

View File

@ -68,6 +68,7 @@ typedef mozilla::ComputedTiming RawGeckoComputedTiming;
typedef nsTArray<const RawServoStyleRule*> RawGeckoServoStyleRuleList;
typedef nsTArray<nsCSSPropertyID> RawGeckoCSSPropertyIDList;
typedef mozilla::gfx::Float RawGeckoGfxMatrix4x4[16];
typedef mozilla::dom::StyleChildrenIterator RawGeckoStyleChildrenIterator;
// We have these helper types so that we can directly generate
// things like &T or Borrowed<T> on the Rust side in the function, providing
@ -156,6 +157,7 @@ DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoServoStyleRuleList)
DECL_BORROWED_MUT_REF_TYPE_FOR(nsCSSPropertyIDSet)
DECL_BORROWED_REF_TYPE_FOR(RawGeckoCSSPropertyIDList)
DECL_BORROWED_REF_TYPE_FOR(nsXBLBinding)
DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoStyleChildrenIterator)
#undef DECL_ARC_REF_TYPE_FOR
#undef DECL_OWNED_REF_TYPE_FOR

View File

@ -204,23 +204,23 @@ Gecko_DestroyAnonymousContentList(nsTArray<nsIContent*>* aAnonContent)
delete aAnonContent;
}
StyleChildrenIteratorOwnedOrNull
Gecko_MaybeCreateStyleChildrenIterator(RawGeckoNodeBorrowed aNode)
void
Gecko_ConstructStyleChildrenIterator(
RawGeckoElementBorrowed aElement,
RawGeckoStyleChildrenIteratorBorrowedMut aIterator)
{
if (!aNode->IsElement()) {
return nullptr;
}
const Element* el = aNode->AsElement();
return StyleChildrenIterator::IsNeeded(el) ? new StyleChildrenIterator(el)
: nullptr;
MOZ_ASSERT(aElement);
MOZ_ASSERT(aIterator);
new (aIterator) StyleChildrenIterator(aElement);
}
void
Gecko_DropStyleChildrenIterator(StyleChildrenIteratorOwned aIterator)
Gecko_DestroyStyleChildrenIterator(
RawGeckoStyleChildrenIteratorBorrowedMut aIterator)
{
MOZ_ASSERT(aIterator);
delete aIterator;
aIterator->~StyleChildrenIterator();
}
nsIContent*
@ -235,7 +235,7 @@ Gecko_ElementBindingAnonymousContent(RawGeckoElementBorrowed aElement)
}
RawGeckoNodeBorrowed
Gecko_GetNextStyleChild(StyleChildrenIteratorBorrowedMut aIterator)
Gecko_GetNextStyleChild(RawGeckoStyleChildrenIteratorBorrowedMut aIterator)
{
MOZ_ASSERT(aIterator);
return aIterator->GetNextChild();

View File

@ -137,12 +137,11 @@ void Gecko_DestroyAnonymousContentList(nsTArray<nsIContent*>* anon_content);
// By default, Servo walks the DOM by traversing the siblings of the DOM-view
// first child. This generally works, but misses anonymous children, which we
// want to traverse during styling. To support these cases, we create an
// optional heap-allocated iterator for nodes that need it. If the creation
// method returns null, Servo falls back to the aforementioned simpler (and
// faster) sibling traversal.
StyleChildrenIteratorOwnedOrNull Gecko_MaybeCreateStyleChildrenIterator(RawGeckoNodeBorrowed node);
void Gecko_DropStyleChildrenIterator(StyleChildrenIteratorOwned it);
RawGeckoNodeBorrowedOrNull Gecko_GetNextStyleChild(StyleChildrenIteratorBorrowedMut it);
// optional stack-allocated iterator in aIterator for nodes that need it.
void Gecko_ConstructStyleChildrenIterator(RawGeckoElementBorrowed aElement,
RawGeckoStyleChildrenIteratorBorrowedMut aIterator);
void Gecko_DestroyStyleChildrenIterator(RawGeckoStyleChildrenIteratorBorrowedMut aIterator);
RawGeckoNodeBorrowedOrNull Gecko_GetNextStyleChild(RawGeckoStyleChildrenIteratorBorrowedMut it);
void Gecko_LoadStyleSheet(mozilla::css::Loader* loader,
mozilla::ServoStyleSheet* parent,

View File

@ -57,6 +57,7 @@ headers = [
"mozilla/ServoElementSnapshot.h",
"mozilla/ServoElementSnapshotTable.h",
"mozilla/dom/Element.h",
"mozilla/dom/ChildIterator.h",
"mozilla/dom/NameSpaceConstants.h",
"mozilla/LookAndFeel.h",
"mozilla/ServoBindings.h",
@ -123,6 +124,7 @@ whitelist-types = [
"mozilla::css::SheetParsingMode",
"mozilla::css::URLMatchingFunction",
"mozilla::dom::IterationCompositeOperation",
"mozilla::dom::StyleChildrenIterator",
"mozilla::HalfCorner",
"mozilla::PropertyStyleAnimationValuePair",
"mozilla::TraversalRestyleBehavior",
@ -348,6 +350,7 @@ structs-types = [
"RawGeckoPresContext",
"RawGeckoPresContextOwned",
"RawGeckoStyleAnimationList",
"RawGeckoStyleChildrenIteratorBorrowedMut",
"RawGeckoServoStyleRuleList",
"RawGeckoURLExtraData",
"RawGeckoXBLBinding",
@ -453,7 +456,6 @@ array-types = [
]
servo-owned-types = [
{ name = "RawServoStyleSet", opaque = true },
{ name = "StyleChildrenIterator", opaque = true },
{ name = "ServoElementSnapshot", opaque = false },
{ name = "RawServoAnimationValueMap", opaque = true },
]