зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1380621 - Use node pointer for HTMLMediaElement::mSourcePointer. r=cpearce
Using a pointer instead of an index helps us avoid some costly operations such as IndexOf and GetChildAt with the upcoming changes from bug 651120.
This commit is contained in:
Родитель
f1506a2ce3
Коммит
42e06700b2
|
@ -1446,6 +1446,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLMediaElement, nsGenericHTM
|
|||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSrcMediaSource)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSrcStream)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSrcAttrStream)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourcePointer)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mLoadBlockedDoc)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceLoadCandidate)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAudioChannelWrapper)
|
||||
|
@ -1473,6 +1474,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLMediaElement, nsGenericHTMLE
|
|||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSrcAttrStream)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMediaSource)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSrcMediaSource)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourcePointer)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mLoadBlockedDoc)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourceLoadCandidate)
|
||||
if (tmp->mAudioChannelWrapper) {
|
||||
|
@ -1505,33 +1507,16 @@ NS_IMPL_BOOL_ATTR(HTMLMediaElement, Loop, loop)
|
|||
NS_IMPL_BOOL_ATTR(HTMLMediaElement, DefaultMuted, muted)
|
||||
NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(HTMLMediaElement, Preload, preload, nullptr)
|
||||
|
||||
void
|
||||
HTMLMediaElement::ContentInserted(nsIDocument* aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
int32_t aIndexInContainer)
|
||||
{
|
||||
if (aContainer != this ||
|
||||
aIndexInContainer >= int32_t(mSourcePointer) ||
|
||||
aIndexInContainer < 0) {
|
||||
return;
|
||||
}
|
||||
++mSourcePointer;
|
||||
}
|
||||
|
||||
void
|
||||
HTMLMediaElement::ContentRemoved(nsIDocument* aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
int32_t aIndexInContainer,
|
||||
int32_t /* aIndexInContainer */,
|
||||
nsIContent* aPreviousSibling)
|
||||
{
|
||||
if (aContainer != this ||
|
||||
aIndexInContainer >= int32_t(mSourcePointer) ||
|
||||
aIndexInContainer < 0) {
|
||||
return;
|
||||
if (aChild == mSourcePointer) {
|
||||
mSourcePointer = aPreviousSibling;
|
||||
}
|
||||
--mSourcePointer;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(bool)
|
||||
|
@ -1812,7 +1797,7 @@ void HTMLMediaElement::AbortExistingLoads()
|
|||
mIsEncrypted = false;
|
||||
mPendingEncryptedInitData.Reset();
|
||||
mWaitingForKey = NOT_WAITING_FOR_KEY;
|
||||
mSourcePointer = 0;
|
||||
mSourcePointer = nullptr;
|
||||
|
||||
mTags = nullptr;
|
||||
|
||||
|
@ -3832,7 +3817,7 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed<mozilla::dom::NodeInfo>& aNo
|
|||
mSrcStreamPausedCurrentTime(-1),
|
||||
mShutdownObserver(new ShutdownObserver),
|
||||
mCurrentLoadID(0),
|
||||
mSourcePointer(0),
|
||||
mSourcePointer(nullptr),
|
||||
mNetworkState(nsIDOMHTMLMediaElement::NETWORK_EMPTY),
|
||||
mReadyState(nsIDOMHTMLMediaElement::HAVE_NOTHING, "HTMLMediaElement::mReadyState"),
|
||||
mLoadWaitStatus(NOT_WAITING),
|
||||
|
@ -6459,13 +6444,16 @@ nsIContent* HTMLMediaElement::GetNextSource()
|
|||
mSourceLoadCandidate = nullptr;
|
||||
|
||||
while (true) {
|
||||
if (mSourcePointer >= GetChildCount())
|
||||
return nullptr; // No more children.
|
||||
if (mSourcePointer == nsINode::GetLastChild()) {
|
||||
return nullptr; // no more children
|
||||
}
|
||||
|
||||
nsIContent* child = GetChildAt(mSourcePointer);
|
||||
|
||||
// Advance to the next child.
|
||||
++mSourcePointer;
|
||||
if (!mSourcePointer) {
|
||||
mSourcePointer = nsINode::GetFirstChild();
|
||||
} else {
|
||||
mSourcePointer = mSourcePointer->GetNextSibling();
|
||||
}
|
||||
nsIContent* child = mSourcePointer;
|
||||
|
||||
// If child is a <source> element, it is the next candidate.
|
||||
if (child && child->IsHTMLElement(nsGkAtoms::source)) {
|
||||
|
|
|
@ -116,7 +116,6 @@ public:
|
|||
typedef mozilla::MetadataTags MetadataTags;
|
||||
|
||||
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(HTMLMediaElement)
|
||||
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
||||
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
||||
|
||||
CORSMode GetCORSMode() {
|
||||
|
@ -1411,10 +1410,14 @@ protected:
|
|||
uint32_t mCurrentLoadID;
|
||||
|
||||
// Points to the child source elements, used to iterate through the children
|
||||
// when selecting a resource to load. This is the index of the child element
|
||||
// that is the current 'candidate' in:
|
||||
// when selecting a resource to load. This is the previous sibling of the
|
||||
// child considered the current 'candidate' in:
|
||||
// https://html.spec.whatwg.org/multipage/media.html#concept-media-load-algorithm
|
||||
uint32_t mSourcePointer;
|
||||
//
|
||||
// mSourcePointer == nullptr, we will next try to load |GetFirstChild()|.
|
||||
// mSourcePointer == GetLastChild(), we've exhausted all sources, waiting
|
||||
// for new elements to be appended.
|
||||
nsCOMPtr<nsIContent> mSourcePointer;
|
||||
|
||||
// Points to the document whose load we're blocking. This is the document
|
||||
// we're bound to when loading starts.
|
||||
|
|
Загрузка…
Ссылка в новой задаче