diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightColor.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightColor.cs index 00abdf68a1..9901a8b0e2 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightColor.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightColor.cs @@ -19,12 +19,6 @@ namespace ICSharpCode.TextEditor.Document /// public class HighlightColor { - bool systemColor = false; - string systemColorName = null; - - bool systemBgColor = false; - string systemBgColorName = null; - Color color; Color backgroundcolor = System.Drawing.Color.WhiteSmoke; @@ -69,10 +63,7 @@ namespace ICSharpCode.TextEditor.Document /// public Color BackgroundColor { get { - if (!systemBgColor) { - return backgroundcolor; - } - return ParseColorString(systemBgColorName); + return backgroundcolor; } } @@ -81,10 +72,7 @@ namespace ICSharpCode.TextEditor.Document /// public Color Color { get { - if (!systemColor) { - return color; - } - return ParseColorString(systemColorName); + return color; } } @@ -135,8 +123,7 @@ namespace ICSharpCode.TextEditor.Document if (c[0] == '#') { color = ParseColor(c); } else if (c.StartsWith("SystemColors.")) { - systemColor = true; - systemColorName = c.Substring("SystemColors.".Length); + color = ParseColorString(c.Substring("SystemColors.".Length)); } else { color = (Color)(Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]); } @@ -150,8 +137,7 @@ namespace ICSharpCode.TextEditor.Document if (c[0] == '#') { backgroundcolor = ParseColor(c); } else if (c.StartsWith("SystemColors.")) { - systemBgColor = true; - systemBgColorName = c.Substring("SystemColors.".Length); + backgroundcolor = ParseColorString(c.Substring("SystemColors.".Length)); } else { backgroundcolor = (Color)(Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]); } @@ -182,8 +168,7 @@ namespace ICSharpCode.TextEditor.Document if (c[0] == '#') { color = ParseColor(c); } else if (c.StartsWith("SystemColors.")) { - systemColor = true; - systemColorName = c.Substring("SystemColors.".Length); + color = ParseColorString(c.Substring("SystemColors.".Length)); } else { color = (Color)(Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]); } @@ -197,8 +182,7 @@ namespace ICSharpCode.TextEditor.Document if (c[0] == '#') { backgroundcolor = ParseColor(c); } else if (c.StartsWith("SystemColors.")) { - systemBgColor = true; - systemBgColorName = c.Substring("SystemColors.".Length); + backgroundcolor = ParseColorString(c.Substring("SystemColors.".Length)); } else { backgroundcolor = (Color)(Color.GetType()).InvokeMember(c, BindingFlags.GetProperty, null, Color, new object[0]); } @@ -241,11 +225,8 @@ namespace ICSharpCode.TextEditor.Document hasForeground = true; hasBackground = true; - this.systemColor = true; - systemColorName = systemColor; - - systemBgColor = true; - systemBgColorName = systemBackgroundColor; + this.color = ParseColorString(systemColor); + this.backgroundcolor = ParseColorString(systemBackgroundColor); this.bold = bold; this.italic = italic; @@ -258,8 +239,7 @@ namespace ICSharpCode.TextEditor.Document { hasForeground = true; - this.systemColor = true; - systemColorName = systemColor; + this.color = ParseColorString(systemColor); this.bold = bold; this.italic = italic; diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Util/LookupTable.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Util/LookupTable.cs index 6bab9d3d18..dbe7dea497 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Util/LookupTable.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Util/LookupTable.cs @@ -44,7 +44,7 @@ namespace ICSharpCode.TextEditor.Util if (casesensitive) { for (int i = 0; i < length; ++i) { int index = ((int)document.GetCharAt(wordOffset + i)) % 256; - next = next.leaf[index]; + next = next[index]; if (next == null) { return null; @@ -58,7 +58,7 @@ namespace ICSharpCode.TextEditor.Util for (int i = 0; i < length; ++i) { int index = ((int)Char.ToUpper(document.GetCharAt(wordOffset + i))) % 256; - next = next.leaf[index]; + next = next[index]; if (next == null) { return null; @@ -90,15 +90,15 @@ namespace ICSharpCode.TextEditor.Util int index = ((int)keyword[i]) % 256; // index of curchar bool d = keyword[i] == '\\'; - next = next.leaf[index]; // get node to this index + next = next[index]; // get node to this index if (next == null) { // no node created -> insert word here - node.leaf[index] = new Node(value, keyword); + node[index] = new Node(value, keyword); break; } if (next.word != null && next.word.Length != i) { // node there, take node content and insert them again - string tmpword = next.word; // this word will be inserted 1 level deeper (better, don't need too much + string tmpword = next.word; // this word will be inserted 1 level deeper (better, don't need too much object tmpcolor = next.color; // string comparisons for finding.) next.color = next.word = null; this[tmpword] = tmpcolor; @@ -134,7 +134,23 @@ namespace ICSharpCode.TextEditor.Util public string word; public object color; - public Node[] leaf = new Node[256]; + // Lazily initialize children array. Saves 200 KB of memory for the C# highlighting + // because we don't have to store the array for leaf nodes. + public Node this[int index] { + get { + if (children != null) + return children[index]; + else + return null; + } + set { + if (children == null) + children = new Node[256]; + children[index] = value; + } + } + + private Node[] children; } } }