Skip to content

Commit

Permalink
Merge pull request #71 from davidnemeti/FixIndexOfPerformanceProblem
Browse files Browse the repository at this point in the history
Using string.IndexOf overload with StringComparison.Ordinal parameter
  • Loading branch information
rivantsov authored Aug 30, 2024
2 parents e0167e1 + 19d006c commit 48f4344
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Irony/Parsing/Terminals/CommentTerminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private Token CompleteMatch(ParsingContext context, ISourceStream source) {
while (!source.EOF()) {
int firstCharPos;
if (EndSymbols.Count == 1)
firstCharPos = source.Text.IndexOf(EndSymbols[0], source.PreviewPosition);
firstCharPos = source.Text.IndexOf(EndSymbols[0], source.PreviewPosition, StringComparison.Ordinal);
else
firstCharPos = source.Text.IndexOfAny(_endSymbolsFirsts, source.PreviewPosition);
if (firstCharPos < 0) {
Expand Down
2 changes: 1 addition & 1 deletion Irony/Parsing/Terminals/FreeTextLiteral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private bool TryMatchPrefixes(ParsingContext context, ISourceStream source) {
private Token TryMatchContentSimple(ParsingContext context, ISourceStream source) {
var startPos = source.PreviewPosition;
var termLen = _singleTerminator.Length;
var stringComp = Grammar.CaseSensitive ? StringComparison.InvariantCulture : StringComparison.InvariantCultureIgnoreCase;
var stringComp = Grammar.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
int termPos = source.Text.IndexOf(_singleTerminator, startPos, stringComp);
if (termPos < 0 && IsSet(FreeTextOptions.AllowEof))
termPos = source.Text.Length;
Expand Down
2 changes: 1 addition & 1 deletion Irony/Parsing/Terminals/QuotedValueLiteral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override IList<string> GetFirsts() {
protected override string ReadBody(ParsingContext context, ISourceStream source) {
if (!source.MatchSymbol(StartSymbol)) return null; //this will result in null returned from TryMatch, no token
var start = source.Location.Position + StartSymbol.Length;
var end = source.Text.IndexOf(EndSymbol, start);
var end = source.Text.IndexOf(EndSymbol, start, StringComparison.Ordinal);
if (end < 0) return null;
var body = source.Text.Substring(start, end - start);
source.PreviewPosition = end + EndSymbol.Length; //move beyond the end of EndSymbol
Expand Down
4 changes: 2 additions & 2 deletions Irony/Parsing/Terminals/StringLiteral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private bool CompleteReadBody(ISourceStream source, CompoundTokenDetails details
int nlPos = lineBreakAllowed ? -1 : source.Text.IndexOf('\n', source.PreviewPosition);
//fix by ashmind for EOF right after opening symbol
while (true) {
int endPos = source.Text.IndexOf(endQuoteSymbol, source.PreviewPosition);
int endPos = source.Text.IndexOf(endQuoteSymbol, source.PreviewPosition, StringComparison.Ordinal);
//Check for partial token in line-scanning mode
if (endPos < 0 && details.PartialOk && lineBreakAllowed) {
ProcessPartialBody(source, details);
Expand Down Expand Up @@ -324,7 +324,7 @@ protected override bool ConvertValue(CompoundTokenDetails details) {

//Check for doubled end symbol
string endSymbol = details.EndSymbol;
if (details.IsSet((short)StringOptions.AllowsDoubledQuote) && value.IndexOf(endSymbol) >= 0)
if (details.IsSet((short)StringOptions.AllowsDoubledQuote) && value.IndexOf(endSymbol, StringComparison.Ordinal) >= 0)
value = value.Replace(endSymbol + endSymbol, endSymbol);

if (details.IsSet((short)StringOptions.IsChar)) {
Expand Down
2 changes: 1 addition & 1 deletion Irony/Parsing/Terminals/WikiTerminals/WikiBlockTerminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public WikiBlockTerminal(string name, WikiBlockType blockType, string openTag, s
public override Token TryMatch(ParsingContext context, ISourceStream source) {
if (!source.MatchSymbol(OpenTag)) return null;
source.PreviewPosition += OpenTag.Length;
var endPos = source.Text.IndexOf(CloseTag, source.PreviewPosition);
var endPos = source.Text.IndexOf(CloseTag, source.PreviewPosition, StringComparison.Ordinal);
string content;
if(endPos > 0) {
content = source.Text.Substring(source.PreviewPosition, endPos - source.PreviewPosition);
Expand Down

0 comments on commit 48f4344

Please sign in to comment.