Skip to content

Commit

Permalink
Merge pull request #178 from cosminvlad/fix/string_perf
Browse files Browse the repository at this point in the history
Improve string manipulation performance
  • Loading branch information
JonathanMagnan authored Dec 8, 2021
2 parents b2b82e8 + b37748f commit 959a112
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ private static void RemoveFilterDisabledConditionFromQuery(DbCommand command, Db
(paramIdx = command.CommandText.IndexOf(param.ParameterName + " IS NOT NULL", curIdx, StringComparison.OrdinalIgnoreCase)) != -1)
{
int startIdx = command.CommandText.LastIndexOf("or", paramIdx, StringComparison.OrdinalIgnoreCase);
int endIdx = command.CommandText.IndexOf(')', paramIdx);
int endIdx = command.CommandText.IndexOf(")", paramIdx, StringComparison.Ordinal);

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

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

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

Expand Down

0 comments on commit 959a112

Please sign in to comment.