Bug 695843 part 7 - Use the URI string as the key for the various mozJSComponentLoader hashtables. r=mrbkap

This commit is contained in:
Mike Hommey 2011-11-08 18:08:49 +01:00
Родитель f8f93f4de1
Коммит f5f83e1536
2 изменённых файлов: 13 добавлений и 113 удалений

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

@ -485,51 +485,6 @@ mozJSComponentLoader::ReallyInit()
return NS_OK; return NS_OK;
} }
nsresult
mozJSComponentLoader::FileKey(nsILocalFile* aFile, nsAString &aResult)
{
nsresult rv = NS_OK;
nsAutoString canonicalPath;
#if defined(XP_WIN)
nsCOMPtr<nsILocalFileWin> winFile = do_QueryInterface(aFile, &rv);
NS_ENSURE_SUCCESS(rv, rv);
winFile->GetCanonicalPath(canonicalPath);
#else
aFile->GetPath(canonicalPath);
#endif
aResult = NS_LITERAL_STRING("f");
aResult += canonicalPath;
return rv;
}
nsresult
mozJSComponentLoader::JarKey(nsILocalFile* aFile,
const nsACString &aComponentPath,
nsAString &aResult)
{
nsresult rv = NS_OK;
nsAutoString canonicalPath;
#if defined(XP_WIN)
nsCOMPtr<nsILocalFileWin> winFile = do_QueryInterface(aFile, &rv);
NS_ENSURE_SUCCESS(rv, rv);
winFile->GetCanonicalPath(canonicalPath);
#else
aFile->GetPath(canonicalPath);
#endif
aResult = NS_LITERAL_STRING("j");
aResult += canonicalPath;
AppendUTF8toUTF16(aComponentPath, aResult);
return rv;
}
const mozilla::Module* const mozilla::Module*
mozJSComponentLoader::LoadModule(nsILocalFile* aComponentFile) mozJSComponentLoader::LoadModule(nsILocalFile* aComponentFile)
{ {
@ -541,13 +496,8 @@ mozJSComponentLoader::LoadModule(nsILocalFile* aComponentFile)
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return NULL; return NULL;
nsAutoString hashstring;
rv = FileKey(aComponentFile, hashstring);
if (NS_FAILED(rv))
return NULL;
return LoadModuleImpl(aComponentFile, return LoadModuleImpl(aComponentFile,
hashstring, spec,
uri); uri);
} }
@ -569,19 +519,14 @@ mozJSComponentLoader::LoadModuleFromJAR(nsILocalFile *aJarFile,
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return NULL; return NULL;
nsAutoString hashstring;
rv = JarKey(aJarFile, aComponentPath, hashstring);
if (NS_FAILED(rv))
return NULL;
return LoadModuleImpl(aJarFile, return LoadModuleImpl(aJarFile,
hashstring, fullSpec,
uri); uri);
} }
const mozilla::Module* const mozilla::Module*
mozJSComponentLoader::LoadModuleImpl(nsILocalFile* aSourceFile, mozJSComponentLoader::LoadModuleImpl(nsILocalFile* aSourceFile,
nsAString &aKey, nsACString &aKey,
nsIURI* aComponentURI) nsIURI* aComponentURI)
{ {
nsresult rv; nsresult rv;
@ -1041,7 +986,7 @@ mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponentFile,
} }
/* static */ PLDHashOperator /* static */ PLDHashOperator
mozJSComponentLoader::ClearModules(const nsAString& key, ModuleEntry*& entry, void* cx) mozJSComponentLoader::ClearModules(const nsACString& key, ModuleEntry*& entry, void* cx)
{ {
entry->Clear(); entry->Clear();
return PL_DHASH_REMOVE; return PL_DHASH_REMOVE;
@ -1206,7 +1151,6 @@ mozJSComponentLoader::ImportInto(const nsACString & aLocation,
nsCOMPtr<nsIJARURI> jarURI; nsCOMPtr<nsIJARURI> jarURI;
jarURI = do_QueryInterface(resolvedURI, &rv); jarURI = do_QueryInterface(resolvedURI, &rv);
nsCOMPtr<nsIFileURL> baseFileURL; nsCOMPtr<nsIFileURL> baseFileURL;
nsCAutoString jarEntry;
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIURI> baseURI; nsCOMPtr<nsIURI> baseURI;
rv = jarURI->GetJARFile(getter_AddRefs(baseURI)); rv = jarURI->GetJARFile(getter_AddRefs(baseURI));
@ -1214,9 +1158,6 @@ mozJSComponentLoader::ImportInto(const nsACString & aLocation,
baseFileURL = do_QueryInterface(baseURI, &rv); baseFileURL = do_QueryInterface(baseURI, &rv);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
jarURI->GetJAREntry(jarEntry);
NS_ENSURE_SUCCESS(rv, rv);
} else { } else {
baseFileURL = do_QueryInterface(resolvedURI, &rv); baseFileURL = do_QueryInterface(resolvedURI, &rv);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -1230,12 +1171,8 @@ mozJSComponentLoader::ImportInto(const nsACString & aLocation,
sourceLocalFile = do_QueryInterface(sourceFile, &rv); sourceLocalFile = do_QueryInterface(sourceFile, &rv);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsAutoString key; nsCAutoString key;
if (jarEntry.IsEmpty()) { rv = resolvedURI->GetSpec(key);
rv = FileKey(sourceLocalFile, key);
} else {
rv = JarKey(sourceLocalFile, jarEntry, key);
}
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
ModuleEntry* mod; ModuleEntry* mod;
@ -1391,40 +1328,8 @@ mozJSComponentLoader::Unload(const nsACString & aLocation)
rv = scriptChannel->GetURI(getter_AddRefs(resolvedURI)); rv = scriptChannel->GetURI(getter_AddRefs(resolvedURI));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// get the JAR if there is one nsCAutoString key;
nsCOMPtr<nsIJARURI> jarURI; rv = resolvedURI->GetSpec(key);
jarURI = do_QueryInterface(resolvedURI, &rv);
nsCOMPtr<nsIFileURL> baseFileURL;
nsCAutoString jarEntry;
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIURI> baseURI;
rv = jarURI->GetJARFile(getter_AddRefs(baseURI));
NS_ENSURE_SUCCESS(rv, rv);
baseFileURL = do_QueryInterface(baseURI, &rv);
NS_ENSURE_SUCCESS(rv, rv);
jarURI->GetJAREntry(jarEntry);
NS_ENSURE_SUCCESS(rv, rv);
} else {
baseFileURL = do_QueryInterface(resolvedURI, &rv);
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIFile> sourceFile;
rv = baseFileURL->GetFile(getter_AddRefs(sourceFile));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsILocalFile> sourceLocalFile;
sourceLocalFile = do_QueryInterface(sourceFile, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString key;
if (jarEntry.IsEmpty()) {
rv = FileKey(sourceLocalFile, key);
} else {
rv = JarKey(sourceLocalFile, jarEntry, key);
}
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
ModuleEntry* mod; ModuleEntry* mod;

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

@ -89,13 +89,8 @@ class mozJSComponentLoader : public mozilla::ModuleLoader,
nsresult ReallyInit(); nsresult ReallyInit();
void UnloadModules(); void UnloadModules();
nsresult FileKey(nsILocalFile* aFile, nsAString &aResult);
nsresult JarKey(nsILocalFile* aFile,
const nsACString& aComponentPath,
nsAString &aResult);
const mozilla::Module* LoadModuleImpl(nsILocalFile* aSourceFile, const mozilla::Module* LoadModuleImpl(nsILocalFile* aSourceFile,
nsAString &aKey, nsACString &aKey,
nsIURI* aComponentURI); nsIURI* aComponentURI);
nsresult GlobalForLocation(nsILocalFile* aComponentFile, nsresult GlobalForLocation(nsILocalFile* aComponentFile,
@ -162,11 +157,11 @@ class mozJSComponentLoader : public mozilla::ModuleLoader,
friend class ModuleEntry; friend class ModuleEntry;
// Modules are intentionally leaked, but still cleared. // Modules are intentionally leaked, but still cleared.
static PLDHashOperator ClearModules(const nsAString& key, ModuleEntry*& entry, void* cx); static PLDHashOperator ClearModules(const nsACString& key, ModuleEntry*& entry, void* cx);
nsDataHashtable<nsStringHashKey, ModuleEntry*> mModules; nsDataHashtable<nsCStringHashKey, ModuleEntry*> mModules;
nsClassHashtable<nsStringHashKey, ModuleEntry> mImports; nsClassHashtable<nsCStringHashKey, ModuleEntry> mImports;
nsDataHashtable<nsStringHashKey, ModuleEntry*> mInProgressImports; nsDataHashtable<nsCStringHashKey, ModuleEntry*> mInProgressImports;
bool mInitialized; bool mInitialized;
}; };