Skip to content

Commit c54f509

Browse files
author
Алексей
committed
changing string concatenation with stringbuilder.append in Helper.ReplaceAll
With the previous implementation, large queries took a very long time to compile.
1 parent b27115b commit c54f509

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

QueryBuilder/Helper.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using System.Text;
56
using System.Text.RegularExpressions;
67

78
namespace SqlKata
@@ -10,7 +11,7 @@ public static class Helper
1011
{
1112
public static bool IsArray(object value)
1213
{
13-
if(value is string)
14+
if (value is string)
1415
{
1516
return false;
1617
}
@@ -88,8 +89,9 @@ public static string ReplaceAll(string subject, string match, Func<int, string>
8889
);
8990

9091
return splitted.Skip(1)
91-
.Select((item, index) => callback(index) + item)
92-
.Aggregate(splitted.First(), (left, right) => left + right);
92+
.Select((item, index) => callback(index) + item)
93+
.Aggregate(new StringBuilder(splitted.First()), (prev, right) => prev.Append(right))
94+
.ToString();
9395
}
9496

9597
public static string JoinArray(string glue, IEnumerable array)
@@ -158,13 +160,13 @@ public static IEnumerable<string> Repeat(this string str, int count)
158160
{
159161
return Enumerable.Repeat(str, count);
160162
}
161-
163+
162164
public static string ReplaceIdentifierUnlessEscaped(this string input, string escapeCharacter, string identifier, string newIdentifier)
163165
{
164166
//Replace standard, non-escaped identifiers first
165167
var nonEscapedRegex = new Regex($@"(?<!{Regex.Escape(escapeCharacter)}){Regex.Escape(identifier)}");
166168
var nonEscapedReplace = nonEscapedRegex.Replace(input, newIdentifier);
167-
169+
168170
//Then replace escaped identifiers, by just removing the escape character
169171
var escapedRegex = new Regex($@"{Regex.Escape(escapeCharacter)}{Regex.Escape(identifier)}");
170172
return escapedRegex.Replace(nonEscapedReplace, identifier);

0 commit comments

Comments
 (0)