Skip to content

Commit aacaad9

Browse files
committed
Statically preallocate Comma TextNode as mostly used
1 parent f38fc63 commit aacaad9

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

Orm/Xtensive.Orm/Sql/Compiler/Internals/Nodes/ContainerNode.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,7 @@ internal override void AcceptVisitor(NodeVisitor visitor)
164164
internal void FlushBuffer()
165165
{
166166
if (stringBuilder.Length > 0) {
167-
var s = stringBuilder.ToString();
168-
if (s.Length < 3) {
169-
s = string.Intern(s);
170-
}
171-
children.Add(new TextNode(s));
167+
children.Add(TextNode.Create(stringBuilder.ToString()));
172168
lastNodeIsText = true;
173169
lastChar = stringBuilder[^1];
174170
_ = stringBuilder.Clear();

Orm/Xtensive.Orm/Sql/Compiler/Internals/Nodes/TextNode.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,30 @@ namespace Xtensive.Sql.Compiler
99
[DebuggerDisplay("Text = {Text}")]
1010
internal class TextNode : Node
1111
{
12+
private const string CommaString = ", ";
13+
private static readonly TextNode CommaNode = new TextNode(CommaString);
14+
1215
public readonly string Text;
1316

14-
internal override void AcceptVisitor(NodeVisitor visitor)
17+
internal override void AcceptVisitor(NodeVisitor visitor) => visitor.Visit(this);
18+
19+
public static TextNode Create(string text)
1520
{
16-
visitor.Visit(this);
21+
if (text.Length < 3) {
22+
text = string.Intern(text);
23+
if (text == CommaString) {
24+
return CommaNode;
25+
}
26+
}
27+
return new TextNode(text);
1728
}
1829

1930
// Constructor
2031

21-
public TextNode(string text)
32+
private TextNode(string text)
2233
: base(true)
2334
{
2435
Text = text;
2536
}
2637
}
27-
}
38+
}

0 commit comments

Comments
 (0)