зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1160703 (Part 2) - Store an ImageURL pointer instead of a URI spec string in ImageCacheKey. r=baku
This commit is contained in:
Родитель
b66721a614
Коммит
05366f060f
|
@ -18,36 +18,36 @@ using namespace dom;
|
|||
namespace image {
|
||||
|
||||
ImageCacheKey::ImageCacheKey(nsIURI* aURI)
|
||||
: mURI(new ImageURL(aURI))
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aURI);
|
||||
MOZ_ASSERT(mURI);
|
||||
|
||||
bool isChrome;
|
||||
mIsChrome = NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome;
|
||||
|
||||
aURI->GetSpec(mSpec);
|
||||
mHash = ComputeHash(mSpec);
|
||||
mHash = ComputeHash(mURI);
|
||||
}
|
||||
|
||||
ImageCacheKey::ImageCacheKey(ImageURL* aURI)
|
||||
: mURI(aURI)
|
||||
{
|
||||
MOZ_ASSERT(aURI);
|
||||
MOZ_ASSERT(mURI);
|
||||
|
||||
bool isChrome;
|
||||
mIsChrome = NS_SUCCEEDED(aURI->SchemeIs("chrome", &isChrome)) && isChrome;
|
||||
|
||||
aURI->GetSpec(mSpec);
|
||||
mHash = ComputeHash(mSpec);
|
||||
mHash = ComputeHash(mURI);
|
||||
}
|
||||
|
||||
ImageCacheKey::ImageCacheKey(const ImageCacheKey& aOther)
|
||||
: mSpec(aOther.mSpec)
|
||||
: mURI(aOther.mURI)
|
||||
, mHash(aOther.mHash)
|
||||
, mIsChrome(aOther.mIsChrome)
|
||||
{ }
|
||||
|
||||
ImageCacheKey::ImageCacheKey(ImageCacheKey&& aOther)
|
||||
: mSpec(Move(aOther.mSpec))
|
||||
: mURI(Move(aOther.mURI))
|
||||
, mHash(aOther.mHash)
|
||||
, mIsChrome(aOther.mIsChrome)
|
||||
{ }
|
||||
|
@ -55,15 +55,23 @@ ImageCacheKey::ImageCacheKey(ImageCacheKey&& aOther)
|
|||
bool
|
||||
ImageCacheKey::operator==(const ImageCacheKey& aOther) const
|
||||
{
|
||||
return mSpec == aOther.mSpec;
|
||||
return *mURI == *aOther.mURI;
|
||||
}
|
||||
|
||||
const char*
|
||||
ImageCacheKey::Spec() const
|
||||
{
|
||||
return mURI->Spec();
|
||||
}
|
||||
|
||||
/* static */ uint32_t
|
||||
ImageCacheKey::ComputeHash(const nsACString& aSpec)
|
||||
ImageCacheKey::ComputeHash(ImageURL* aURI)
|
||||
{
|
||||
// Since we frequently call Hash() several times in a row on the same
|
||||
// ImageCacheKey, as an optimization we compute our hash once and store it.
|
||||
return HashString(aSpec);
|
||||
nsAutoCString spec;
|
||||
aURI->GetSpec(spec);
|
||||
return HashString(spec);
|
||||
}
|
||||
|
||||
} // namespace image
|
||||
|
|
|
@ -36,15 +36,15 @@ public:
|
|||
uint32_t Hash() const { return mHash; }
|
||||
|
||||
/// A weak pointer to the URI spec for this cache entry. For logging only.
|
||||
const char* Spec() const { return mSpec.get(); }
|
||||
const char* Spec() const;
|
||||
|
||||
/// Is this cache entry for a chrome image?
|
||||
bool IsChrome() const { return mIsChrome; }
|
||||
|
||||
private:
|
||||
static uint32_t ComputeHash(const nsACString& aSpec);
|
||||
static uint32_t ComputeHash(ImageURL* aURI);
|
||||
|
||||
nsCString mSpec;
|
||||
nsRefPtr<ImageURL> mURI;
|
||||
uint32_t mHash;
|
||||
bool mIsChrome;
|
||||
};
|
||||
|
|
|
@ -44,6 +44,9 @@ public:
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/// A weak pointer to the URI spec for this ImageURL. For logging only.
|
||||
const char* Spec() const { return mSpec.get(); }
|
||||
|
||||
nsresult GetScheme(nsACString& result)
|
||||
{
|
||||
result = mScheme;
|
||||
|
@ -74,6 +77,13 @@ public:
|
|||
return newURI.forget();
|
||||
}
|
||||
|
||||
bool operator==(const ImageURL& aOther) const
|
||||
{
|
||||
// Note that we don't need to consider mScheme and mRef, because they're
|
||||
// already represented in mSpec.
|
||||
return mSpec == aOther.mSpec;
|
||||
}
|
||||
|
||||
private:
|
||||
// Since this is a basic storage class, no duplication of spec parsing is
|
||||
// included in the functionality. Instead, the class depends upon the
|
||||
|
|
Загрузка…
Ссылка в новой задаче