From 64a2edac01f24e6b6a1b038bbdfd1ec38651800f Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 25 May 2015 20:38:04 +0200 Subject: [PATCH] Cache Selector.ToString() Was actually adding up to a noticeable amount of time in large layouts. --- Perspex.Styling/Selector.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Perspex.Styling/Selector.cs b/Perspex.Styling/Selector.cs index 2daccc63ae..e141f9dabb 100644 --- a/Perspex.Styling/Selector.cs +++ b/Perspex.Styling/Selector.cs @@ -17,6 +17,8 @@ namespace Perspex.Styling private bool stopTraversal; + private string description; + public Selector() { this.evaluate = _ => new SelectorMatch(true); @@ -94,14 +96,19 @@ namespace Perspex.Styling public override string ToString() { - string result = string.Empty; - - if (this.Previous != null) + if (this.description == null) { - result = this.Previous.ToString(); + string result = string.Empty; + + if (this.Previous != null) + { + result = this.Previous.ToString(); + } + + this.description = result + this.SelectorString; } - return result + this.SelectorString; + return this.description; } } }