-
Notifications
You must be signed in to change notification settings - Fork 934
Various string manipulation optimizations #1543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
3f6942b
e23bf84
14fde54
a6c9fec
6bfe359
83e7c17
85583b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,11 +42,12 @@ private ParameterParser() | |
public static void Parse(string sqlString, IRecognizer recognizer) | ||
{ | ||
// TODO: WTF? "CALL"... it may work for ORACLE but what about others RDBMS ? (by FM) | ||
bool hasMainOutputParameter = sqlString.IndexOf("call") > 0 && | ||
sqlString.IndexOf("?") > 0 && | ||
sqlString.IndexOf("=") > 0 && | ||
sqlString.IndexOf("?") < sqlString.IndexOf("call") && | ||
sqlString.IndexOf("=") < sqlString.IndexOf("call"); | ||
var indexOfCall = sqlString.IndexOf("call", StringComparison.Ordinal); | ||
bool hasMainOutputParameter = indexOfCall > 0 && | ||
sqlString.IndexOf('?') > 0 && | ||
sqlString.IndexOf('=') > 0 && | ||
sqlString.IndexOf('?') < indexOfCall && | ||
sqlString.IndexOf('=') < indexOfCall; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as previous. |
||
bool foundMainOutputParam = false; | ||
|
||
int stringLength = sqlString.Length; | ||
|
@@ -59,7 +60,7 @@ public static void Parse(string sqlString, IRecognizer recognizer) | |
// check comments | ||
if (indx + 1 < stringLength && sqlString.Substring(indx,2) == "/*") | ||
{ | ||
var closeCommentIdx = sqlString.IndexOf("*/", indx+2); | ||
var closeCommentIdx = sqlString.IndexOf("*/", indx + 2, StringComparison.Ordinal); | ||
recognizer.Other(sqlString.Substring(indx, (closeCommentIdx- indx)+2)); | ||
indx = closeCommentIdx + 1; | ||
continue; | ||
|
@@ -112,7 +113,7 @@ public static void Parse(string sqlString, IRecognizer recognizer) | |
if (c == ':') | ||
{ | ||
// named parameter | ||
int right = StringHelper.FirstIndexOfChar(sqlString, ParserHelper.HqlSeparators, indx + 1); | ||
int right = StringHelper.FirstIndexOfChar(sqlString, ParserHelper.HqlSeparatorsAsCharArray, indx + 1); | ||
int chopLocation = right < 0 ? sqlString.Length : right; | ||
string param = sqlString.Substring(indx + 1, chopLocation - (indx + 1)); | ||
recognizer.NamedParameter(param, indx); | ||
|
@@ -124,7 +125,7 @@ public static void Parse(string sqlString, IRecognizer recognizer) | |
if (indx < stringLength - 1 && char.IsDigit(sqlString[indx + 1])) | ||
{ | ||
// a peek ahead showed this as an ejb3-positional parameter | ||
int right = StringHelper.FirstIndexOfChar(sqlString, ParserHelper.HqlSeparators, indx + 1); | ||
int right = StringHelper.FirstIndexOfChar(sqlString, ParserHelper.HqlSeparatorsAsCharArray, indx + 1); | ||
int chopLocation = right < 0 ? sqlString.Length : right; | ||
string param = sqlString.Substring(indx + 1, chopLocation - (indx + 1)); | ||
// make sure this "name" is an integral | ||
|
@@ -160,4 +161,4 @@ public static void Parse(string sqlString, IRecognizer recognizer) | |
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,12 +168,12 @@ public static void ProcessDynamicFilterParameters( | |
|
||
private static bool HasDynamicFilterParam(SqlString sqlFragment) | ||
{ | ||
return sqlFragment.IndexOfCaseInsensitive(ParserHelper.HqlVariablePrefix) < 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually I don't understand this code. Why "has dynamic filter param" is true when HqlVariablePrefix is missing? |
||
return !ParserHelper.HasHqlVariable(sqlFragment); | ||
} | ||
|
||
private static bool HasCollectionFilterParam(SqlString sqlFragment) | ||
{ | ||
return sqlFragment.IndexOfCaseInsensitive("?") < 0; | ||
return sqlFragment.IndexOfOrdinal("?") < 0; | ||
} | ||
|
||
private class JoinSequenceSelector : JoinSequence.ISelector | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -404,6 +404,11 @@ public int IndexOfCaseInsensitive(string text) | |
return IndexOf(text, 0, _length, StringComparison.InvariantCultureIgnoreCase); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears to me this one should be switched to But overall they are more than hundred cases were invariant is used in the code base. It looks to me most of them if not all should be switched to ordinal. Maybe worth a dedicated PR. (By the way if changing this case here, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah. But it's public method. I'm afraid to change its behaviour :)
Agreed (but not as part of this PR) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Fixing a behavior which is a bug is OK. I do not think the invariant behavior discrepancies with ordinal can be anything else than bugs for this case, but well, maybe I am wrong. Something that is equal with invariant but not equal with ordinal looks very likely to me to be considered not equal by the database query parser as well, in which case we would have a bug. Still this can be the subject of another PR, switching all invariant which should be to ordinal. I also think the change of most of them could be considered as also fixing bug possibilities. @hazzik, what is your view on this subject? Do you think it is ok to switch from invariant to ordinal in a minor release, considering it is also a bug fix, or would you rather have such change in a major release? |
||
} | ||
|
||
internal int IndexOfOrdinal(string text) | ||
{ | ||
return IndexOf(text, 0, _length, StringComparison.Ordinal); | ||
} | ||
|
||
/// <summary> | ||
/// Returns the index of the first occurrence of <paramref name="text" />, case-insensitive. | ||
/// </summary> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe even go as far as:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Will do