Browse Source

Memory usage optimization for the Text Editor as suggested in forum-8629.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3672 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
dbaed14afa
  1. 38
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightColor.cs
  2. 26
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Util/LookupTable.cs

38
src/Libraries/ICSharpCode.TextEditor/Project/Src/Document/HighlightingStrategy/HighlightColor.cs

@ -19,12 +19,6 @@ namespace ICSharpCode.TextEditor.Document @@ -19,12 +19,6 @@ namespace ICSharpCode.TextEditor.Document
/// </summary>
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 @@ -69,10 +63,7 @@ namespace ICSharpCode.TextEditor.Document
/// </value>
public Color BackgroundColor {
get {
if (!systemBgColor) {
return backgroundcolor;
}
return ParseColorString(systemBgColorName);
return backgroundcolor;
}
}
@ -81,10 +72,7 @@ namespace ICSharpCode.TextEditor.Document @@ -81,10 +72,7 @@ namespace ICSharpCode.TextEditor.Document
/// </value>
public Color Color {
get {
if (!systemColor) {
return color;
}
return ParseColorString(systemColorName);
return color;
}
}
@ -135,8 +123,7 @@ namespace ICSharpCode.TextEditor.Document @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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;

26
src/Libraries/ICSharpCode.TextEditor/Project/Src/Util/LookupTable.cs

@ -44,7 +44,7 @@ namespace ICSharpCode.TextEditor.Util @@ -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 @@ -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,10 +90,10 @@ namespace ICSharpCode.TextEditor.Util @@ -90,10 +90,10 @@ 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;
}
@ -134,7 +134,23 @@ namespace ICSharpCode.TextEditor.Util @@ -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;
}
}
}

Loading…
Cancel
Save