Bug 1447828 part 2 - Remove StyleBackendType uses from nsXULPrototypeCache. r=emilio

MozReview-Commit-ID: 1tYFBTk9BqF

--HG--
extra : rebase_source : 72c783c84ff36fddd6d49e79e7912f42bb0c11a8
extra : source : 4972e279ef76127e4898874478fcbd75c9631d76
This commit is contained in:
Xidorn Quan 2018-03-29 02:31:23 +11:00
Родитель 0401ef821e
Коммит d9cb92544e
5 изменённых файлов: 53 добавлений и 117 удалений

Просмотреть файл

@ -1036,13 +1036,11 @@ nsBindingManager::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
n += mDocumentTable->ShallowSizeOfIncludingThis(aMallocSizeOf);
#ifdef MOZ_XUL
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
StyleBackendType backendType = mDocument->GetStyleBackendType();
#endif
for (auto iter = mDocumentTable->Iter(); !iter.Done(); iter.Next()) {
nsXBLDocumentInfo* docInfo = iter.UserData();
#ifdef MOZ_XUL
nsXBLDocumentInfo* cachedInfo =
cache->GetXBLDocumentInfo(iter.Key(), backendType);
nsXBLDocumentInfo* cachedInfo = cache->GetXBLDocumentInfo(iter.Key());
if (cachedInfo == docInfo) {
// If this binding has been cached, skip it since it can be
// reused by other documents.

Просмотреть файл

@ -969,16 +969,9 @@ nsXBLService::LoadBindingDocumentInfo(nsIContent* aBoundElement,
bool useXULCache = cache && cache->IsEnabled();
if (!info && useXULCache) {
// Assume Gecko style backend for the XBL document without a bound
// document. The only case is loading platformHTMLBindings.xml which
// doesn't have any style sheets or style attributes.
StyleBackendType styleBackend
= aBoundDocument ? aBoundDocument->GetStyleBackendType()
: StyleBackendType::Gecko;
// This cache crosses the entire product, so that any XBL bindings that are
// part of chrome will be reused across all XUL documents.
info = cache->GetXBLDocumentInfo(documentURI, styleBackend);
info = cache->GetXBLDocumentInfo(documentURI);
}
bool useStartupCache = useXULCache && IsChromeOrResourceURI(documentURI);
@ -1042,12 +1035,6 @@ nsXBLService::LoadBindingDocumentInfo(nsIContent* aBoundElement,
bindingManager->PutXBLDocumentInfo(info);
}
MOZ_ASSERT(!aBoundDocument || !info ||
aBoundDocument->GetStyleBackendType() ==
info->GetDocument()->GetStyleBackendType(),
"Style backend type mismatched between the bound document and "
"the XBL document loaded.");
info.forget(aResult);
return NS_OK;

Просмотреть файл

@ -192,22 +192,16 @@ nsXULPrototypeCache::PutPrototype(nsXULPrototypeDocument* aDocument)
}
mozilla::StyleSheet*
nsXULPrototypeCache::GetStyleSheet(nsIURI* aURI,
StyleBackendType aType)
nsXULPrototypeCache::GetStyleSheet(nsIURI* aURI)
{
StyleSheetTable& table = StyleSheetTableFor(aType);
return table.GetWeak(aURI);
return mStyleSheetTable.GetWeak(aURI);
}
nsresult
nsXULPrototypeCache::PutStyleSheet(StyleSheet* aStyleSheet,
StyleBackendType aType)
nsXULPrototypeCache::PutStyleSheet(StyleSheet* aStyleSheet)
{
nsIURI* uri = aStyleSheet->GetSheetURI();
StyleSheetTable& table = StyleSheetTableFor(aType);
table.Put(uri, aStyleSheet);
mStyleSheetTable.Put(uri, aStyleSheet);
return NS_OK;
}
@ -240,24 +234,18 @@ nsXULPrototypeCache::PutScript(nsIURI* aURI,
}
nsXBLDocumentInfo*
nsXULPrototypeCache::GetXBLDocumentInfo(nsIURI* aURL,
StyleBackendType aType)
nsXULPrototypeCache::GetXBLDocumentInfo(nsIURI* aURL)
{
MOZ_ASSERT(aType != StyleBackendType::None,
"Please use either gecko or servo when looking up for the cache!");
return XBLDocTableFor(aType).GetWeak(aURL);
return mXBLDocTable.GetWeak(aURL);
}
nsresult
nsXULPrototypeCache::PutXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo)
{
nsIURI* uri = aDocumentInfo->DocumentURI();
XBLDocTable& table =
XBLDocTableFor(aDocumentInfo->GetDocument()->GetStyleBackendType());
nsXBLDocumentInfo* info = table.GetWeak(uri);
nsXBLDocumentInfo* info = mXBLDocTable.GetWeak(uri);
if (!info) {
table.Put(uri, aDocumentInfo);
mXBLDocTable.Put(uri, aDocumentInfo);
}
return NS_OK;
}
@ -265,36 +253,29 @@ nsXULPrototypeCache::PutXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo)
void
nsXULPrototypeCache::FlushSkinFiles()
{
StyleBackendType tableTypes[] = { StyleBackendType::Gecko,
StyleBackendType::Servo };
for (auto tableType : tableTypes) {
// Flush out skin XBL files from the cache.
XBLDocTable& xblDocTable = XBLDocTableFor(tableType);
for (auto iter = xblDocTable.Iter(); !iter.Done(); iter.Next()) {
nsAutoCString str;
iter.Key()->GetPathQueryRef(str);
if (strncmp(str.get(), "/skin", 5) == 0) {
iter.Remove();
}
// Flush out skin XBL files from the cache.
for (auto iter = mXBLDocTable.Iter(); !iter.Done(); iter.Next()) {
nsAutoCString str;
iter.Key()->GetPathQueryRef(str);
if (strncmp(str.get(), "/skin", 5) == 0) {
iter.Remove();
}
}
// Now flush out our skin stylesheets from the cache.
StyleSheetTable& table = StyleSheetTableFor(tableType);
for (auto iter = table.Iter(); !iter.Done(); iter.Next()) {
nsAutoCString str;
iter.Data()->GetSheetURI()->GetPathQueryRef(str);
if (strncmp(str.get(), "/skin", 5) == 0) {
iter.Remove();
}
// Now flush out our skin stylesheets from the cache.
for (auto iter = mStyleSheetTable.Iter(); !iter.Done(); iter.Next()) {
nsAutoCString str;
iter.Data()->GetSheetURI()->GetPathQueryRef(str);
if (strncmp(str.get(), "/skin", 5) == 0) {
iter.Remove();
}
}
// Iterate over all the remaining XBL and make sure cached
// scoped skin stylesheets are flushed and refetched by the
// prototype bindings.
for (auto iter = xblDocTable.Iter(); !iter.Done(); iter.Next()) {
iter.Data()->FlushSkinStylesheets();
}
// Iterate over all the remaining XBL and make sure cached
// scoped skin stylesheets are flushed and refetched by the
// prototype bindings.
for (auto iter = mXBLDocTable.Iter(); !iter.Done(); iter.Next()) {
iter.Data()->FlushSkinStylesheets();
}
}
@ -309,10 +290,8 @@ nsXULPrototypeCache::Flush()
{
mPrototypeTable.Clear();
mScriptTable.Clear();
mGeckoStyleSheetTable.Clear();
mServoStyleSheetTable.Clear();
mGeckoXBLDocTable.Clear();
mServoXBLDocTable.Clear();
mStyleSheetTable.Clear();
mXBLDocTable.Clear();
}
@ -611,14 +590,8 @@ nsXULPrototypeCache::BeginCaching(nsIURI* aURI)
void
nsXULPrototypeCache::MarkInCCGeneration(uint32_t aGeneration)
{
StyleBackendType tableTypes[] = { StyleBackendType::Gecko,
StyleBackendType::Servo };
for (auto tableType : tableTypes) {
XBLDocTable& xblDocTable = XBLDocTableFor(tableType);
for (auto iter = xblDocTable.Iter(); !iter.Done(); iter.Next()) {
iter.Data()->MarkInCCGeneration(aGeneration);
}
for (auto iter = mXBLDocTable.Iter(); !iter.Done(); iter.Next()) {
iter.Data()->MarkInCCGeneration(aGeneration);
}
for (auto iter = mPrototypeTable.Iter(); !iter.Done(); iter.Next()) {
iter.Data()->MarkInCCGeneration(aGeneration);
@ -679,30 +652,23 @@ nsXULPrototypeCache::CollectMemoryReports(
// TODO Report content in mPrototypeTable?
other += sInstance->
mGeckoStyleSheetTable.ShallowSizeOfExcludingThis(mallocSizeOf);
// TODO Report content inside mGeckoStyleSheetTable?
other += sInstance->
mServoStyleSheetTable.ShallowSizeOfExcludingThis(mallocSizeOf);
// TODO Report content inside mServoStyleSheetTable?
mStyleSheetTable.ShallowSizeOfExcludingThis(mallocSizeOf);
// TODO Report content inside mStyleSheetTable?
other += sInstance->
mScriptTable.ShallowSizeOfExcludingThis(mallocSizeOf);
// TODO Report content inside mScriptTable?
auto reportXBLDocTable =
[&](const nsACString& prefix, const XBLDocTable& table) {
other += table.ShallowSizeOfExcludingThis(mallocSizeOf);
for (auto iter = table.ConstIter(); !iter.Done(); iter.Next()) {
nsAutoCString path(prefix);
path += "-xbl-docs/(";
AppendURIForMemoryReport(iter.Key(), path);
path += ")";
size_t size = iter.UserData()->SizeOfIncludingThis(mallocSizeOf);
REPORT_SIZE(path, size, "Memory used by this XBL document.");
}
};
reportXBLDocTable(NS_LITERAL_CSTRING("gecko"), sInstance->mGeckoXBLDocTable);
reportXBLDocTable(NS_LITERAL_CSTRING("servo"), sInstance->mServoXBLDocTable);
other += sInstance->mXBLDocTable.ShallowSizeOfExcludingThis(mallocSizeOf);
for (auto iter = sInstance->mXBLDocTable.ConstIter();
!iter.Done(); iter.Next()) {
nsAutoCString path;
path += "xbl-docs/(";
AppendURIForMemoryReport(iter.Key(), path);
path += ")";
size_t size = iter.UserData()->SizeOfIncludingThis(mallocSizeOf);
REPORT_SIZE(path, size, "Memory used by this XBL document.");
}
other += sInstance->
mStartupCacheURITable.ShallowSizeOfExcludingThis(mallocSizeOf);

Просмотреть файл

@ -66,8 +66,7 @@ public:
JSScript* GetScript(nsIURI* aURI);
nsresult PutScript(nsIURI* aURI, JS::Handle<JSScript*> aScriptObject);
nsXBLDocumentInfo* GetXBLDocumentInfo(nsIURI* aURL,
mozilla::StyleBackendType aType);
nsXBLDocumentInfo* GetXBLDocumentInfo(nsIURI* aURL);
nsresult PutXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo);
@ -75,15 +74,13 @@ public:
* Get a style sheet by URI. If the style sheet is not in the cache,
* returns nullptr.
*/
mozilla::StyleSheet* GetStyleSheet(nsIURI* aURI,
mozilla::StyleBackendType aType);
mozilla::StyleSheet* GetStyleSheet(nsIURI* aURI);
/**
* Store a style sheet in the cache. The key, style sheet's URI is obtained
* from the style sheet itself.
*/
nsresult PutStyleSheet(mozilla::StyleSheet* aStyleSheet,
mozilla::StyleBackendType aType);
nsresult PutStyleSheet(mozilla::StyleSheet* aStyleSheet);
/**
* Write the XUL prototype document to a cache file. The proto must be
@ -130,22 +127,10 @@ protected:
using StyleSheetTable = nsRefPtrHashtable<nsURIHashKey, mozilla::StyleSheet>;
using XBLDocTable = nsRefPtrHashtable<nsURIHashKey, nsXBLDocumentInfo>;
StyleSheetTable& StyleSheetTableFor(mozilla::StyleBackendType aType) {
return aType == mozilla::StyleBackendType::Gecko ? mGeckoStyleSheetTable
: mServoStyleSheetTable;
}
XBLDocTable& XBLDocTableFor(mozilla::StyleBackendType aType) {
return aType == mozilla::StyleBackendType::Gecko ? mGeckoXBLDocTable
: mServoXBLDocTable;
}
nsRefPtrHashtable<nsURIHashKey,nsXULPrototypeDocument> mPrototypeTable; // owns the prototypes
StyleSheetTable mGeckoStyleSheetTable;
StyleSheetTable mServoStyleSheetTable;
StyleSheetTable mStyleSheetTable;
nsJSThingHashtable<nsURIHashKey, JSScript*> mScriptTable;
XBLDocTable mGeckoXBLDocTable;
XBLDocTable mServoXBLDocTable;
XBLDocTable mXBLDocTable;
// URIs already written to the startup cache, to prevent double-caching.
nsTHashtable<nsURIHashKey> mStartupCacheURITable;

Просмотреть файл

@ -922,7 +922,7 @@ Loader::CreateSheet(nsIURI* aURI,
if (IsChromeURI(aURI)) {
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
if (cache && cache->IsEnabled()) {
sheet = cache->GetStyleSheet(aURI, GetStyleBackendType());
sheet = cache->GetStyleSheet(aURI);
LOG((" From XUL cache: %p", sheet.get()));
}
}
@ -1802,11 +1802,11 @@ Loader::DoSheetComplete(SheetLoadData* aLoadData, LoadDataArray& aDatasToNotify)
if (IsChromeURI(aLoadData->mURI)) {
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
if (cache && cache->IsEnabled()) {
if (!cache->GetStyleSheet(aLoadData->mURI, GetStyleBackendType())) {
if (!cache->GetStyleSheet(aLoadData->mURI)) {
LOG((" Putting sheet in XUL prototype cache"));
NS_ASSERTION(sheet->IsComplete(),
"Should only be caching complete sheets");
cache->PutStyleSheet(sheet, GetStyleBackendType());
cache->PutStyleSheet(sheet);
}
}
}