From c54f509b0e802b2c79b4f63a82b80e465910023e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Wed, 29 Jan 2020 15:06:57 +0300 Subject: [PATCH] changing string concatenation with stringbuilder.append in Helper.ReplaceAll With the previous implementation, large queries took a very long time to compile. --- QueryBuilder/Helper.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/QueryBuilder/Helper.cs b/QueryBuilder/Helper.cs index 23b77eb6..8e6b2384 100644 --- a/QueryBuilder/Helper.cs +++ b/QueryBuilder/Helper.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Text; using System.Text.RegularExpressions; namespace SqlKata @@ -10,7 +11,7 @@ public static class Helper { public static bool IsArray(object value) { - if(value is string) + if (value is string) { return false; } @@ -88,8 +89,9 @@ public static string ReplaceAll(string subject, string match, Func ); return splitted.Skip(1) - .Select((item, index) => callback(index) + item) - .Aggregate(splitted.First(), (left, right) => left + right); + .Select((item, index) => callback(index) + item) + .Aggregate(new StringBuilder(splitted.First()), (prev, right) => prev.Append(right)) + .ToString(); } public static string JoinArray(string glue, IEnumerable array) @@ -158,13 +160,13 @@ public static IEnumerable Repeat(this string str, int count) { return Enumerable.Repeat(str, count); } - + public static string ReplaceIdentifierUnlessEscaped(this string input, string escapeCharacter, string identifier, string newIdentifier) { //Replace standard, non-escaped identifiers first var nonEscapedRegex = new Regex($@"(?