зеркало из https://github.com/mozilla/gecko-dev.git
Once we've had enough ID lookup misses, make the ID table completely live. Bug
299689, r+sr=jst
This commit is contained in:
Родитель
cf64715ae5
Коммит
811b4e530c
|
@ -2377,6 +2377,18 @@ nsHTMLDocument::GetElementById(const nsAString& aElementId,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!e) {
|
if (!e) {
|
||||||
|
// If IdTableIsLive(), no need to look for the element in the document,
|
||||||
|
// since we're fully maintaining our table's state as the DOM mutates.
|
||||||
|
if (!IdTableIsLive()) {
|
||||||
|
if (IdTableShouldBecomeLive()) {
|
||||||
|
// Just make sure our table is up to date and call this method again
|
||||||
|
// to look up in the hashtable.
|
||||||
|
if (mRootContent) {
|
||||||
|
RegisterNamedItems(mRootContent);
|
||||||
|
}
|
||||||
|
return GetElementById(aElementId, aReturn);
|
||||||
|
}
|
||||||
|
|
||||||
NS_WARN_IF_FALSE(!aElementId.IsEmpty(),
|
NS_WARN_IF_FALSE(!aElementId.IsEmpty(),
|
||||||
"getElementById(\"\") called, fix caller?");
|
"getElementById(\"\") called, fix caller?");
|
||||||
|
|
||||||
|
@ -2384,6 +2396,7 @@ nsHTMLDocument::GetElementById(const nsAString& aElementId,
|
||||||
e = MatchElementId(mRootContent, NS_ConvertUCS2toUTF8(aElementId),
|
e = MatchElementId(mRootContent, NS_ConvertUCS2toUTF8(aElementId),
|
||||||
aElementId);
|
aElementId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!e) {
|
if (!e) {
|
||||||
// There is no element with the given id in the document, cache
|
// There is no element with the given id in the document, cache
|
||||||
|
@ -3015,12 +3028,14 @@ nsHTMLDocument::AddToIdTable(const nsAString& aId, nsIContent *aContent)
|
||||||
nsresult
|
nsresult
|
||||||
nsHTMLDocument::UpdateIdTableEntry(const nsAString& aId, nsIContent *aContent)
|
nsHTMLDocument::UpdateIdTableEntry(const nsAString& aId, nsIContent *aContent)
|
||||||
{
|
{
|
||||||
|
PRBool liveTable = IdTableIsLive();
|
||||||
|
PLDHashOperator op = liveTable ? PL_DHASH_ADD : PL_DHASH_LOOKUP;
|
||||||
IdAndNameMapEntry *entry =
|
IdAndNameMapEntry *entry =
|
||||||
NS_STATIC_CAST(IdAndNameMapEntry *,
|
NS_STATIC_CAST(IdAndNameMapEntry *,
|
||||||
PL_DHashTableOperate(&mIdAndNameHashTable, &aId,
|
PL_DHashTableOperate(&mIdAndNameHashTable, &aId,
|
||||||
PL_DHASH_LOOKUP));
|
op));
|
||||||
|
|
||||||
if (PL_DHASH_ENTRY_IS_BUSY(entry)) {
|
if (entry && (liveTable || PL_DHASH_ENTRY_IS_BUSY(entry))) {
|
||||||
entry->mIdContent = aContent;
|
entry->mIdContent = aContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -310,6 +310,27 @@ protected:
|
||||||
|
|
||||||
PRPackedBool mIsFrameset;
|
PRPackedBool mIsFrameset;
|
||||||
|
|
||||||
|
PRBool IdTableIsLive() const {
|
||||||
|
// live if we've had over 63 misses
|
||||||
|
return (mIdMissCount & 0x40) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool IdTableShouldBecomeLive() {
|
||||||
|
NS_ASSERTION(!IdTableIsLive(),
|
||||||
|
"Shouldn't be called if table is already live!");
|
||||||
|
++mIdMissCount;
|
||||||
|
return IdTableIsLive();
|
||||||
|
}
|
||||||
|
|
||||||
|
PRUint8 mIdMissCount;
|
||||||
|
|
||||||
|
/* mIdAndNameHashTable works as follows for IDs:
|
||||||
|
* 1) Attribute changes affect the table immediately (removing and adding
|
||||||
|
* entries as needed).
|
||||||
|
* 2) Removals from the DOM affect the table immediately
|
||||||
|
* 3) Additions to the DOM always update existing entries, but only add new
|
||||||
|
* ones if IdTableIsLive() is true.
|
||||||
|
*/
|
||||||
PLDHashTable mIdAndNameHashTable;
|
PLDHashTable mIdAndNameHashTable;
|
||||||
|
|
||||||
nsCOMPtr<nsIWyciwygChannel> mWyciwygChannel;
|
nsCOMPtr<nsIWyciwygChannel> mWyciwygChannel;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче