Commit 7c27fd53 authored by hyatt's avatar hyatt
Browse files

Back out my previous patch to the WebCore memory cache.

        * loader/Cache.cpp:
        (WebCore::Cache::flush):
        (WebCore::Cache::setSize):
        (WebCore::Cache::getLRUListFor):
        (WebCore::Cache::removeFromLRUList):
        (WebCore::Cache::insertInLRUList):
        * loader/Cache.h:
        * loader/CachedCSSStyleSheet.cpp:
        (WebCore::CachedCSSStyleSheet::deref):
        * loader/CachedCSSStyleSheet.h:
        * loader/CachedImage.cpp:
        (WebCore::CachedImage::deref):
        * loader/CachedImage.h:
        * loader/CachedResource.cpp:
        (WebCore::CachedResource::setRequest):
        (WebCore::CachedResource::deref):
        * loader/CachedResource.h:
        (WebCore::CachedResource::allowInLRUList):
        * loader/CachedScript.cpp:
        (WebCore::CachedScript::deref):
        * loader/CachedScript.h:
        * loader/CachedXBLDocument.cpp:
        (WebCore::CachedXBLDocument::deref):
        * loader/CachedXBLDocument.h:
        * loader/CachedXSLStyleSheet.cpp:
        (WebCore::CachedXSLStyleSheet::deref):
        * loader/CachedXSLStyleSheet.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@17097 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 5790cc31
2006-10-17 David Hyatt <hyatt@apple.com>
Back out my previous patch to the WebCore memory cache.
* loader/Cache.cpp:
(WebCore::Cache::flush):
(WebCore::Cache::setSize):
(WebCore::Cache::getLRUListFor):
(WebCore::Cache::removeFromLRUList):
(WebCore::Cache::insertInLRUList):
* loader/Cache.h:
* loader/CachedCSSStyleSheet.cpp:
(WebCore::CachedCSSStyleSheet::deref):
* loader/CachedCSSStyleSheet.h:
* loader/CachedImage.cpp:
(WebCore::CachedImage::deref):
* loader/CachedImage.h:
* loader/CachedResource.cpp:
(WebCore::CachedResource::setRequest):
(WebCore::CachedResource::deref):
* loader/CachedResource.h:
(WebCore::CachedResource::allowInLRUList):
* loader/CachedScript.cpp:
(WebCore::CachedScript::deref):
* loader/CachedScript.h:
* loader/CachedXBLDocument.cpp:
(WebCore::CachedXBLDocument::deref):
* loader/CachedXBLDocument.h:
* loader/CachedXSLStyleSheet.cpp:
(WebCore::CachedXSLStyleSheet::deref):
* loader/CachedXSLStyleSheet.h:
2006-10-17 Oliver Hunt <oliver@apple.com>
 
Reviewed by Anders.
......@@ -71,7 +71,9 @@ int Cache::flushCount = 0;
Image *Cache::nullImage = 0;
Image *Cache::brokenImage = 0;
CachedResource *Cache::m_headOfUncacheableList = 0;
int Cache::m_totalSizeOfLRULists = 0;
int Cache::m_countOfLRUAndUncacheableLists;
LRUList *Cache::m_LRULists = 0;
void Cache::init()
......@@ -381,10 +383,18 @@ CachedXBLDocument* Cache::requestXBLDocument(DocLoader* dl, const String& url, b
}
#endif
void Cache::flush()
void Cache::flush(bool force)
{
if (m_totalSizeOfLRULists <= maxSize)
return;
if (force)
flushCount = 0;
// Don't flush for every image.
if (m_countOfLRUAndUncacheableLists < flushCount)
return;
init();
while (m_headOfUncacheableList)
remove(m_headOfUncacheableList);
for (int i = maxLRULists-1; i>=0; i--) {
if (m_totalSizeOfLRULists <= maxSize)
......@@ -393,6 +403,8 @@ void Cache::flush()
while (m_totalSizeOfLRULists > maxSize && m_LRULists[i].m_tail)
remove(m_LRULists[i].m_tail);
}
flushCount = m_countOfLRUAndUncacheableLists+10; // Flush again when the cache has grown.
}
......@@ -401,8 +413,9 @@ void Cache::setSize(int bytes)
maxSize = bytes;
maxCacheable = max(maxSize / 128, minMaxCacheableObjectSize);
// Flush in case the new size is smaller.
flush();
// may be we need to clear parts of the cache
flushCount = 0;
flush(true);
}
void Cache::remove(CachedResource *object)
......@@ -455,38 +468,40 @@ LRUList* Cache::getLRUListFor(CachedResource* o)
queueIndex = maxLRULists-1;
}
if (!m_LRULists)
m_LRULists = new LRUList[maxLRULists];
m_LRULists = new LRUList [maxLRULists];
return &m_LRULists[queueIndex];
}
void Cache::removeFromLRUList(CachedResource *object)
{
if (object->status() == CachedResource::Uncacheable ||
object->status() == CachedResource::Persistent)
return;
CachedResource *next = object->m_nextInLRUList;
CachedResource *prev = object->m_prevInLRUList;
LRUList* list = getLRUListFor(object);
if (next == 0 && prev == 0 && list->m_head != object)
bool uncacheable = object->status() == CachedResource::Uncacheable;
LRUList* list = uncacheable ? 0 : getLRUListFor(object);
CachedResource *&head = uncacheable ? m_headOfUncacheableList : list->m_head;
if (next == 0 && prev == 0 && head != object) {
return;
}
object->m_nextInLRUList = 0;
object->m_prevInLRUList = 0;
if (next)
next->m_prevInLRUList = prev;
else if (list->m_tail == object)
else if (!uncacheable && list->m_tail == object)
list->m_tail = prev;
if (prev)
prev->m_nextInLRUList = next;
else if (list->m_head == object)
list->m_head = next;
else if (head == object)
head = next;
--m_countOfLRUAndUncacheableLists;
m_totalSizeOfLRULists -= object->size();
if (!uncacheable)
m_totalSizeOfLRULists -= object->size();
}
void Cache::moveToHeadOfLRUList(CachedResource *object)
......@@ -502,15 +517,22 @@ void Cache::insertInLRUList(CachedResource *object)
return;
LRUList* list = getLRUListFor(object);
object->m_nextInLRUList = list->m_head;
if (list->m_head)
list->m_head->m_prevInLRUList = object;
list->m_head = object;
if (object->m_nextInLRUList == 0)
bool uncacheable = object->status() == CachedResource::Uncacheable;
CachedResource *&head = uncacheable ? m_headOfUncacheableList : list->m_head;
object->m_nextInLRUList = head;
if (head)
head->m_prevInLRUList = object;
head = object;
if (object->m_nextInLRUList == 0 && !uncacheable)
list->m_tail = object;
m_totalSizeOfLRULists += object->size();
++m_countOfLRUAndUncacheableLists;
if (!uncacheable)
m_totalSizeOfLRULists += object->size();
}
bool Cache::adjustSize(CachedResource *object, int delta)
......
......@@ -95,7 +95,7 @@ namespace WebCore {
/**
* clean up cache
*/
static void flush();
static void flush(bool force = false);
/**
* clears the cache
......@@ -155,6 +155,10 @@ namespace WebCore {
static LRUList* m_LRULists;
static int m_totalSizeOfLRULists;
static CachedResource* m_headOfUncacheableList;
static int m_countOfLRUAndUncacheableLists;
};
}
......
......@@ -63,6 +63,14 @@ void CachedCSSStyleSheet::ref(CachedResourceClient *c)
c->setCSSStyleSheet(m_url, m_decoder->encoding().name(), m_sheet);
}
void CachedCSSStyleSheet::deref(CachedResourceClient *c)
{
Cache::flush();
CachedResource::deref(c);
if (canDelete() && m_free)
delete this;
}
void CachedCSSStyleSheet::setCharset(const String& chs)
{
m_decoder->setEncoding(chs, Decoder::EncodingFromHTTPHeader);
......
......@@ -45,6 +45,7 @@ namespace WebCore {
const String& sheet() const { return m_sheet; }
virtual void ref(CachedResourceClient*);
virtual void deref(CachedResourceClient*);
virtual void setCharset(const String&);
virtual void data(Vector<char>&, bool allDataReceived);
......
......@@ -68,6 +68,14 @@ void CachedImage::ref(CachedResourceClient* c)
c->notifyFinished(this);
}
void CachedImage::deref(CachedResourceClient *c)
{
Cache::flush();
CachedResource::deref(c);
if (canDelete() && m_free)
delete this;
}
Image* CachedImage::image() const
{
if (m_errorOccurred)
......
......@@ -52,6 +52,7 @@ public:
IntRect imageRect() const; // The size of the image.
virtual void ref(CachedResourceClient*);
virtual void deref(CachedResourceClient*);
virtual Vector<char>& bufferData(const char* bytes, int addedSize, Request*);
virtual void data(Vector<char>&, bool allDataReceived);
......
......@@ -94,9 +94,7 @@ void CachedResource::setRequest(Request *_request)
if ( _request && !m_request )
m_status = Pending;
m_request = _request;
if (canDelete() && status() == Uncacheable)
Cache::remove(this);
else if (canDelete() && m_free)
if (canDelete() && m_free)
delete this;
else if (allowInLRUList())
Cache::insertInLRUList(this);
......@@ -114,12 +112,6 @@ void CachedResource::deref(CachedResourceClient *c)
m_clients.remove(c);
if (allowInLRUList())
Cache::insertInLRUList(this);
if (canDelete()) {
if (status() == Uncacheable)
Cache::remove(this);
else if (m_free)
delete this;
}
}
void CachedResource::setSize(int size)
......
......@@ -180,7 +180,7 @@ namespace WebCore {
bool m_expireDateChanged : 1;
private:
bool allowInLRUList() const { return canDelete() && status() != Persistent && status() != Uncacheable; }
bool allowInLRUList() const { return canDelete() && status() != Persistent; }
CachedResource* m_nextInLRUList;
CachedResource* m_prevInLRUList;
......
......@@ -73,6 +73,14 @@ void CachedScript::ref(CachedResourceClient* c)
c->notifyFinished(this);
}
void CachedScript::deref(CachedResourceClient* c)
{
Cache::flush();
CachedResource::deref(c);
if (canDelete() && m_free)
delete this;
}
void CachedScript::setCharset(const String& chs)
{
TextEncoding encoding(chs);
......
......@@ -44,6 +44,7 @@ namespace WebCore {
const String& script() const { return m_script; }
virtual void ref(CachedResourceClient*);
virtual void deref(CachedResourceClient*);
virtual void setCharset(const String&);
virtual void data(Vector<char>&, bool allDataReceived);
......
......@@ -65,6 +65,14 @@ void CachedXBLDocument::ref(CachedResourceClient *c)
c->setXBLDocument(m_url, m_document);
}
void CachedXBLDocument::deref(CachedResourceClient *c)
{
Cache::flush();
CachedResource::deref(c);
if (canDelete() && m_free)
delete this;
}
void CachedXBLDocument::setCharset(const String& chs)
{
m_decoder->setEncoding(chs, Decoder::EncodingFromHTTPHeader);
......
......@@ -47,6 +47,7 @@ namespace WebCore {
XBL::XBLDocument* document() const { return m_document; }
virtual void ref(CachedResourceClient*);
virtual void deref(CachedResourceClient*);
virtual void setCharset(const String&);
virtual void data(Vector<char>&, bool allDataReceived);
......
......@@ -61,6 +61,14 @@ void CachedXSLStyleSheet::ref(CachedResourceClient *c)
c->setXSLStyleSheet(m_url, m_sheet);
}
void CachedXSLStyleSheet::deref(CachedResourceClient *c)
{
Cache::flush();
CachedResource::deref(c);
if (canDelete() && m_free)
delete this;
}
void CachedXSLStyleSheet::setCharset(const String& chs)
{
m_decoder->setEncoding(chs, Decoder::EncodingFromHTTPHeader);
......
......@@ -44,6 +44,7 @@ namespace WebCore {
const String& sheet() const { return m_sheet; }
virtual void ref(CachedResourceClient*);
virtual void deref(CachedResourceClient*);
virtual void setCharset(const String&);
virtual void data(Vector<char>&, bool allDataReceived);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment