-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor inline stylesheet cache into a class
https://bugs.webkit.org/show_bug.cgi?id=267996 rdar://problem/121514266 Reviewed by Ryosuke Niwa. Add StyleSheetContentsCache and use it. * Source/WebCore/Sources.txt: * Source/WebCore/WebCore.xcodeproj/project.pbxproj: * Source/WebCore/css/CSSStyleSheet.cpp: (WebCore::CSSStyleSheet::CSSStyleSheet): (WebCore::CSSStyleSheet::replaceSync): * Source/WebCore/css/StyleSheetContents.h: * Source/WebCore/dom/InlineStyleSheetOwner.cpp: (WebCore::makeStyleSheetContentsCacheKey): (WebCore::InlineStyleSheetOwner::createSheet): (WebCore::inlineStyleSheetCache): Deleted. (WebCore::makeInlineStyleSheetCacheKey): Deleted. (WebCore::InlineStyleSheetOwner::clearCache): Deleted. * Source/WebCore/dom/InlineStyleSheetOwner.h: * Source/WebCore/page/MemoryRelease.cpp: (WebCore::releaseNoncriticalMemory): * Source/WebCore/style/StyleSheetContentsCache.cpp: Added. (WebCore::Style::StyleSheetContentsCache::singleton): (WebCore::Style::StyleSheetContentsCache::get): (WebCore::Style::StyleSheetContentsCache::add): (WebCore::Style::StyleSheetContentsCache::clear): * Source/WebCore/style/StyleSheetContentsCache.h: Added. Canonical link: https://commits.webkit.org/273437@main
- Loading branch information
Showing
10 changed files
with
172 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "config.h" | ||
#include "StyleSheetContentsCache.h" | ||
|
||
#include "StyleSheetContents.h" | ||
|
||
namespace WebCore { | ||
namespace Style { | ||
|
||
StyleSheetContentsCache::StyleSheetContentsCache() = default; | ||
|
||
StyleSheetContentsCache& StyleSheetContentsCache::singleton() | ||
{ | ||
static NeverDestroyed<StyleSheetContentsCache> cache; | ||
return cache.get(); | ||
} | ||
|
||
RefPtr<StyleSheetContents> StyleSheetContentsCache::get(const Key& key) | ||
{ | ||
return m_cache.get(key); | ||
} | ||
|
||
void StyleSheetContentsCache::add(Key&& key, Ref<StyleSheetContents> contents) | ||
{ | ||
ASSERT(contents->isCacheable()); | ||
|
||
m_cache.add(WTFMove(key), contents); | ||
contents->addedToMemoryCache(); | ||
|
||
static constexpr auto maximumCacheSize = 256; | ||
if (m_cache.size() > maximumCacheSize) { | ||
auto toRemove = m_cache.random(); | ||
toRemove->value->removedFromMemoryCache(); | ||
m_cache.remove(toRemove); | ||
} | ||
} | ||
|
||
void StyleSheetContentsCache::clear() | ||
{ | ||
m_cache.clear(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) 2024 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "CSSParserContext.h" | ||
#include <wtf/HashMap.h> | ||
#include <wtf/text/WTFString.h> | ||
|
||
namespace WebCore { | ||
|
||
class StyleSheetContents; | ||
|
||
namespace Style { | ||
|
||
class StyleSheetContentsCache { | ||
public: | ||
static StyleSheetContentsCache& singleton(); | ||
|
||
using Key = std::pair<String, CSSParserContext>; | ||
|
||
RefPtr<StyleSheetContents> get(const Key&); | ||
void add(Key&&, Ref<StyleSheetContents>); | ||
|
||
void clear(); | ||
|
||
private: | ||
friend class NeverDestroyed<StyleSheetContentsCache>; | ||
|
||
StyleSheetContentsCache(); | ||
|
||
HashMap<Key, Ref<StyleSheetContents>> m_cache; | ||
}; | ||
|
||
} | ||
} |