Commit dd5243fb authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

Move CanvasRenderingContext2D::font_lru_list_ to LinkedHashSet.

ListHashSet is deprecated.

Bug: 614112
Change-Id: I7b726aed29a92e8e61499b7a2455de0855735267
Reviewed-on: https://chromium-review.googlesource.com/c/1392273Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619663}
parent 087c22ed
...@@ -59,9 +59,8 @@ bool CanvasFontCache::GetFontUsingDefaultStyle(const String& font_string, ...@@ -59,9 +59,8 @@ bool CanvasFontCache::GetFontUsingDefaultStyle(const String& font_string,
HashMap<String, Font>::iterator i = HashMap<String, Font>::iterator i =
fonts_resolved_using_default_style_.find(font_string); fonts_resolved_using_default_style_.find(font_string);
if (i != fonts_resolved_using_default_style_.end()) { if (i != fonts_resolved_using_default_style_.end()) {
DCHECK(font_lru_list_.Contains(font_string)); auto add_result = font_lru_list_.PrependOrMoveToFirst(font_string);
font_lru_list_.erase(font_string); DCHECK(!add_result.is_new_entry);
font_lru_list_.insert(font_string);
resolved_font = i->value; resolved_font = i->value;
return true; return true;
} }
...@@ -85,10 +84,9 @@ MutableCSSPropertyValueSet* CanvasFontCache::ParseFont( ...@@ -85,10 +84,9 @@ MutableCSSPropertyValueSet* CanvasFontCache::ParseFont(
MutableCSSPropertyValueSet* parsed_style; MutableCSSPropertyValueSet* parsed_style;
MutableStylePropertyMap::iterator i = fetched_fonts_.find(font_string); MutableStylePropertyMap::iterator i = fetched_fonts_.find(font_string);
if (i != fetched_fonts_.end()) { if (i != fetched_fonts_.end()) {
DCHECK(font_lru_list_.Contains(font_string)); auto add_result = font_lru_list_.PrependOrMoveToFirst(font_string);
DCHECK(!add_result.is_new_entry);
parsed_style = i->value; parsed_style = i->value;
font_lru_list_.erase(font_string);
font_lru_list_.insert(font_string);
} else { } else {
parsed_style = MutableCSSPropertyValueSet::Create(kHTMLStandardMode); parsed_style = MutableCSSPropertyValueSet::Create(kHTMLStandardMode);
CSSParser::ParseValue(parsed_style, CSSPropertyFont, font_string, true, CSSParser::ParseValue(parsed_style, CSSPropertyFont, font_string, true,
...@@ -103,15 +101,15 @@ MutableCSSPropertyValueSet* CanvasFontCache::ParseFont( ...@@ -103,15 +101,15 @@ MutableCSSPropertyValueSet* CanvasFontCache::ParseFont(
if (font_value && font_value->IsCSSWideKeyword()) if (font_value && font_value->IsCSSWideKeyword())
return nullptr; return nullptr;
fetched_fonts_.insert(font_string, parsed_style); fetched_fonts_.insert(font_string, parsed_style);
font_lru_list_.insert(font_string); font_lru_list_.PrependOrMoveToFirst(font_string);
// Hard limit is applied here, on the fly, while the soft limit is // Hard limit is applied here, on the fly, while the soft limit is
// applied at the end of the task. // applied at the end of the task.
if (fetched_fonts_.size() > HardMaxFonts()) { if (fetched_fonts_.size() > HardMaxFonts()) {
DCHECK_EQ(fetched_fonts_.size(), HardMaxFonts() + 1); DCHECK_EQ(fetched_fonts_.size(), HardMaxFonts() + 1);
DCHECK_EQ(font_lru_list_.size(), HardMaxFonts() + 1); DCHECK_EQ(font_lru_list_.size(), HardMaxFonts() + 1);
fetched_fonts_.erase(font_lru_list_.front()); fetched_fonts_.erase(font_lru_list_.back());
fonts_resolved_using_default_style_.erase(font_lru_list_.front()); fonts_resolved_using_default_style_.erase(font_lru_list_.back());
font_lru_list_.RemoveFirst(); font_lru_list_.pop_back();
} }
} }
SchedulePruningIfNeeded(); SchedulePruningIfNeeded();
...@@ -123,9 +121,9 @@ void CanvasFontCache::DidProcessTask(const base::PendingTask& pending_task) { ...@@ -123,9 +121,9 @@ void CanvasFontCache::DidProcessTask(const base::PendingTask& pending_task) {
DCHECK(pruning_scheduled_); DCHECK(pruning_scheduled_);
DCHECK(main_cache_purge_preventer_); DCHECK(main_cache_purge_preventer_);
while (fetched_fonts_.size() > MaxFonts()) { while (fetched_fonts_.size() > MaxFonts()) {
fetched_fonts_.erase(font_lru_list_.front()); fetched_fonts_.erase(font_lru_list_.back());
fonts_resolved_using_default_style_.erase(font_lru_list_.front()); fonts_resolved_using_default_style_.erase(font_lru_list_.back());
font_lru_list_.RemoveFirst(); font_lru_list_.pop_back();
} }
main_cache_purge_preventer_.reset(); main_cache_purge_preventer_.reset();
Thread::Current()->RemoveTaskObserver(this); Thread::Current()->RemoveTaskObserver(this);
......
...@@ -504,9 +504,8 @@ void CanvasRenderingContext2D::setFont(const String& new_font) { ...@@ -504,9 +504,8 @@ void CanvasRenderingContext2D::setFont(const String& new_font) {
HashMap<String, Font>::iterator i = HashMap<String, Font>::iterator i =
fonts_resolved_using_current_style_.find(new_font); fonts_resolved_using_current_style_.find(new_font);
if (i != fonts_resolved_using_current_style_.end()) { if (i != fonts_resolved_using_current_style_.end()) {
DCHECK(font_lru_list_.Contains(new_font)); auto add_result = font_lru_list_.PrependOrMoveToFirst(new_font);
font_lru_list_.erase(new_font); DCHECK(!add_result.is_new_entry);
font_lru_list_.insert(new_font);
ModifiableState().SetFont(i->value, Host()->GetFontSelector()); ModifiableState().SetFont(i->value, Host()->GetFontSelector());
} else { } else {
MutableCSSPropertyValueSet* parsed_style = MutableCSSPropertyValueSet* parsed_style =
...@@ -537,8 +536,8 @@ void CanvasRenderingContext2D::setFont(const String& new_font) { ...@@ -537,8 +536,8 @@ void CanvasRenderingContext2D::setFont(const String& new_font) {
Font final_font(final_description); Font final_font(final_description);
fonts_resolved_using_current_style_.insert(new_font, final_font); fonts_resolved_using_current_style_.insert(new_font, final_font);
DCHECK(!font_lru_list_.Contains(new_font)); auto add_result = font_lru_list_.PrependOrMoveToFirst(new_font);
font_lru_list_.insert(new_font); DCHECK(add_result.is_new_entry);
PruneLocalFontCache(canvas_font_cache->HardMaxFonts()); // hard limit PruneLocalFontCache(canvas_font_cache->HardMaxFonts()); // hard limit
should_prune_local_font_cache_ = true; // apply soft limit should_prune_local_font_cache_ = true; // apply soft limit
ModifiableState().SetFont(final_font, Host()->GetFontSelector()); ModifiableState().SetFont(final_font, Host()->GetFontSelector());
...@@ -582,8 +581,8 @@ void CanvasRenderingContext2D::PruneLocalFontCache(size_t target_size) { ...@@ -582,8 +581,8 @@ void CanvasRenderingContext2D::PruneLocalFontCache(size_t target_size) {
return; return;
} }
while (font_lru_list_.size() > target_size) { while (font_lru_list_.size() > target_size) {
fonts_resolved_using_current_style_.erase(font_lru_list_.front()); fonts_resolved_using_current_style_.erase(font_lru_list_.back());
font_lru_list_.RemoveFirst(); font_lru_list_.pop_back();
} }
} }
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "third_party/blink/renderer/platform/graphics/graphics_types.h" #include "third_party/blink/renderer/platform/graphics/graphics_types.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h" #include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/scheduler/public/thread.h" #include "third_party/blink/renderer/platform/scheduler/public/thread.h"
#include "third_party/blink/renderer/platform/wtf/linked_hash_set.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace cc { namespace cc {
...@@ -267,7 +268,7 @@ class MODULES_EXPORT CanvasRenderingContext2D final ...@@ -267,7 +268,7 @@ class MODULES_EXPORT CanvasRenderingContext2D final
FilterOperations filter_operations_; FilterOperations filter_operations_;
HashMap<String, Font> fonts_resolved_using_current_style_; HashMap<String, Font> fonts_resolved_using_current_style_;
bool should_prune_local_font_cache_; bool should_prune_local_font_cache_;
ListHashSet<String> font_lru_list_; LinkedHashSet<String> font_lru_list_;
}; };
DEFINE_TYPE_CASTS(CanvasRenderingContext2D, DEFINE_TYPE_CASTS(CanvasRenderingContext2D,
......
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