Optimize performance and GC for string parsing in PDT.
This commit is contained in:
@@ -4,7 +4,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text;
|
||||||
using CMath = System.Math;
|
using CMath = System.Math;
|
||||||
|
|
||||||
namespace Cryville.Common.Pdt {
|
namespace Cryville.Common.Pdt {
|
||||||
@@ -64,6 +64,8 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// The current position in the string being parsed by the interpreter.
|
/// The current position in the string being parsed by the interpreter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Position { get; protected set; }
|
public int Position { get; protected set; }
|
||||||
|
|
||||||
|
readonly StringBuilder _sb = new StringBuilder();
|
||||||
#pragma warning disable IDE1006
|
#pragma warning disable IDE1006
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The character at the current position.
|
/// The character at the current position.
|
||||||
@@ -139,13 +141,15 @@ namespace Cryville.Common.Pdt {
|
|||||||
/// <returns>A string.</returns>
|
/// <returns>A string.</returns>
|
||||||
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
/// <exception cref="IndexOutOfRangeException">The end of the source string is reached.</exception>
|
||||||
protected string GetString() {
|
protected string GetString() {
|
||||||
int sp = Position;
|
_sb.Clear();
|
||||||
do {
|
Position++;
|
||||||
|
while (ct != CharCategory.StringDelimiter) {
|
||||||
if (cc == '\\') Position++;
|
if (cc == '\\') Position++;
|
||||||
|
_sb.Append(cc);
|
||||||
Position++;
|
Position++;
|
||||||
} while (ct != 0x0100);
|
}
|
||||||
Position++;
|
Position++;
|
||||||
return Regex.Replace(Source.Substring(sp + 1, Position - sp - 2), @"\\(.)", "$1");
|
return _sb.ToString();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reads an expression.
|
/// Reads an expression.
|
||||||
|
|||||||
Reference in New Issue
Block a user