Skip to content

Commit 959a112

Browse files
Merge pull request #178 from cosminvlad/fix/string_perf
Improve string manipulation performance
2 parents b2b82e8 + b37748f commit 959a112

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/EntityFramework.DynamicFilters.Shared/DynamicFilterExtensions.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ private static void RemoveFilterDisabledConditionFromQuery(DbCommand command, Db
940940
(paramIdx = command.CommandText.IndexOf(param.ParameterName + " IS NOT NULL", curIdx, StringComparison.OrdinalIgnoreCase)) != -1)
941941
{
942942
int startIdx = command.CommandText.LastIndexOf("or", paramIdx, StringComparison.OrdinalIgnoreCase);
943-
int endIdx = command.CommandText.IndexOf(')', paramIdx);
943+
int endIdx = command.CommandText.IndexOf(")", paramIdx, StringComparison.Ordinal);
944944

945945
if (endIdx == -1)
946946
{
@@ -955,7 +955,7 @@ private static void RemoveFilterDisabledConditionFromQuery(DbCommand command, Db
955955
// (note the extra ()'s which are not present in PostgreSQL).
956956
// So while we found the ending ")", we may or may not want to actually remove it.
957957
// Determine that by checking for the presence of an opening "(" in between the "or" and the parameter name
958-
var openingParenIndex = command.CommandText.IndexOf('(', startIdx);
958+
var openingParenIndex = command.CommandText.IndexOf("(", startIdx, StringComparison.Ordinal);
959959
if ((openingParenIndex < startIdx) || (openingParenIndex > paramIdx))
960960
endIdx--; // Do not have opening paren so do not remove the trailing ")"!
961961
}
@@ -996,7 +996,7 @@ private static void SetParameterList(IEnumerable paramValueCollection, DbParamet
996996
int prevStartIndex = 0;
997997
int paramStartIdx;
998998
bool isNotCondition = false;
999-
while ((paramStartIdx = command.CommandText.IndexOf(param.ParameterName, prevStartIndex)) != -1)
999+
while ((paramStartIdx = command.CommandText.IndexOf(param.ParameterName, prevStartIndex, StringComparison.OrdinalIgnoreCase)) != -1)
10001000
{
10011001
int startIdx = FindLastComparisonOperator(command.CommandText, paramStartIdx, out isNotCondition);
10021002
if (startIdx == -1)
@@ -1058,11 +1058,11 @@ private static int FindLastComparisonOperator(string commandText, int fromIdx, o
10581058
// possible for us to match on a condition that is earlier in the sql statement.
10591059

10601060
// MySql uses "!=" syntax. Not possible to find both.
1061-
int notEqualIdx = commandText.LastIndexOf("!=", fromIdx, 10);
1061+
int notEqualIdx = commandText.LastIndexOf("!=", fromIdx, 10, StringComparison.Ordinal);
10621062
if (notEqualIdx == -1)
1063-
notEqualIdx = commandText.LastIndexOf("<>", fromIdx, 10);
1063+
notEqualIdx = commandText.LastIndexOf("<>", fromIdx, 10, StringComparison.Ordinal);
10641064

1065-
int equalIdx = commandText.LastIndexOf("=", fromIdx, 10);
1065+
int equalIdx = commandText.LastIndexOf("=", fromIdx, 10, StringComparison.Ordinal);
10661066
if (equalIdx == notEqualIdx + 1) // Don't want to match on the "=" in "!="
10671067
equalIdx = -1;
10681068

0 commit comments

Comments
 (0)