Skip to content

Commit

Permalink
Additional code gen improvements
Browse files Browse the repository at this point in the history
- In Go, Improve code generation from several constructs to reduce code size and increase bounds reduction in the non-backtracking compiler
- In FindFirstChars, use IndexOf instead of Boyer-Moore if the found prefix is only one character in length.
- Hide some debug-only functions from code coverage
  • Loading branch information
stephentoub committed Jan 9, 2020
1 parent 25a2900 commit 22469b3
Show file tree
Hide file tree
Showing 12 changed files with 458 additions and 292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//

using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

namespace System.Text.RegularExpressions
Expand Down Expand Up @@ -331,6 +332,7 @@ internal void Tidy(int textpos)
}

#if DEBUG
[ExcludeFromCodeCoverage]
internal bool Debug => _regex != null && _regex.Debug;

internal virtual void Dump()
Expand Down Expand Up @@ -372,6 +374,7 @@ internal MatchSparse(Regex regex, Hashtable caps, int capcount, string text, int
public override GroupCollection Groups => _groupcoll ??= new GroupCollection(this, _caps);

#if DEBUG
[ExcludeFromCodeCoverage]
internal override void Dump()
{
if (_caps != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ protected void InitializeReferences()
/// <summary>
/// True if the regex has debugging enabled
/// </summary>
[ExcludeFromCodeCoverage]
internal bool Debug => (roptions & RegexOptions.Debug) != 0;
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// need to be examined.

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

namespace System.Text.RegularExpressions
Expand Down Expand Up @@ -338,8 +339,10 @@ public int Scan(string text, int index, int beglimit, int endlimit)
/// <summary>
/// Used when dumping for debugging.
/// </summary>
[ExcludeFromCodeCoverage]
public override string ToString() => Pattern;

[ExcludeFromCodeCoverage]
public string Dump(string indent)
{
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Threading;

Expand Down Expand Up @@ -1374,6 +1375,7 @@ private static ReadOnlySpan<char> SetFromProperty(string capname, bool invert, s
/// <summary>
/// Produces a human-readable description for a set string.
/// </summary>
[ExcludeFromCodeCoverage]
public static string SetDescription(string set)
{
int setLength = set[SetLengthIndex];
Expand Down Expand Up @@ -1472,6 +1474,7 @@ public static string SetDescription(string set)
/// <summary>
/// Produces a human-readable description for a single character.
/// </summary>
[ExcludeFromCodeCoverage]
public static string CharDescription(char ch)
{
if (ch == '\\')
Expand Down Expand Up @@ -1507,6 +1510,7 @@ public static string CharDescription(char ch)
return sb.ToString();
}

[ExcludeFromCodeCoverage]
private static string CategoryDescription(char ch)
{
if (ch == SpaceConst)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// Strings and sets are indices into a string table.

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace System.Text.RegularExpressions
{
Expand Down Expand Up @@ -241,6 +241,7 @@ public static int OpcodeSize(int opcode)
"Oneloopatomic", "Notoneloopatomic", "Setloopatomic"
};

[ExcludeFromCodeCoverage]
private static string OperatorDescription(int Opcode)
{
bool isCi = ((Opcode & Ci) != 0);
Expand All @@ -256,6 +257,7 @@ private static string OperatorDescription(int Opcode)
(isBack2 ? "-Back2" : "");
}

[ExcludeFromCodeCoverage]
public string OpcodeDescription(int offset)
{
StringBuilder sb = new StringBuilder();
Expand Down Expand Up @@ -367,6 +369,7 @@ public string OpcodeDescription(int offset)
return sb.ToString();
}

[ExcludeFromCodeCoverage]
public void Dump()
{
int i;
Expand Down
Loading

0 comments on commit 22469b3

Please sign in to comment.