From 340c270e8a9fe235c80daa1479ed509e42319544 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Mon, 7 May 2018 14:20:12 -0400 Subject: [PATCH] GlyphContext - Lazy glyph-char-mapping --- src/client/spark/view/Utility/GlyphContext.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client/spark/view/Utility/GlyphContext.cs b/src/client/spark/view/Utility/GlyphContext.cs index e5e0b617b..e89a49a36 100644 --- a/src/client/spark/view/Utility/GlyphContext.cs +++ b/src/client/spark/view/Utility/GlyphContext.cs @@ -1,4 +1,5 @@ -using System.Collections.Concurrent; +using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; @@ -12,8 +13,8 @@ namespace mbts.ui.utility.text { /// class GlyphContext { static readonly GlyphTypeface _default_glyph_typeface; - static readonly ConcurrentDictionary> _glyph_char_maps = - new ConcurrentDictionary>(); + static readonly ConcurrentDictionary>> _glyph_char_maps = + new ConcurrentDictionary>>(); readonly GlyphTypeface _glyph_typeface; readonly IDictionary _char_map; @@ -59,13 +60,12 @@ namespace mbts.ui.utility.text { #pragma warning restore CS0618 // Type or member is obsolete } - static ReadOnlyDictionary _get_glyph_char_map(GlyphTypeface glyph_typeface) { - return _glyph_char_maps.GetOrAdd(glyph_typeface, gt => { + static ReadOnlyDictionary _get_glyph_char_map(GlyphTypeface glyph_typeface) => + _glyph_char_maps.GetOrAdd(glyph_typeface, gt => new Lazy>(() => { var widths = glyph_typeface.AdvanceWidths; return new ReadOnlyDictionary( glyph_typeface.CharacterToGlyphMap.ToDictionary(kv => kv.Key, kv => (kv.Value, widths[kv.Value]))); - }); - } + })).Value; static Point _calculate_glyph_run_origin( double font_size, double available_width, double available_height, double glyph_width,