From 98667ed402d0875e7ed8ce85f399e750b49a34e5 Mon Sep 17 00:00:00 2001 From: Robert Pickering Date: Tue, 2 Aug 2022 13:52:49 +0200 Subject: [PATCH] Replace resx with a statically generated cs file (#3025) * Replace resx with a statically generated cs file * upgrade regex to remove need for System.Buffers * Really remove need for System.Buffers * don't modify the throughput tests and fix build constants * import vendored improvements * Re-apply Anna's fix * remove annoying json file and add .gitignore to avoid these errors in the future * actually add the .gitignore mentioned earlier * don't null out array before it's used --- .../UpdateVendors/VendoredDependency.cs | 21 +- tracer/build/crank/.gitignore | 1 + .../Datadog.Dependabot.Vendors.csproj | 4 +- tracer/src/Datadog.Trace/Datadog.Trace.csproj | 4 +- ...eSystem.Text.RegularExpressions.csproj.txt | 31 +- .../SR.Designer.cs | 568 ------------------ .../SR.g.cs | 89 +++ .../SR.resx | 288 --------- .../Text/RegularExpressions/RegexCharClass.cs | 2 +- .../RegexGeneratorAttribute.cs | 57 -- .../Text/RegularExpressions/RegexOptions.cs | 7 +- .../RegularExpressions/RegexParseError.cs | 7 +- .../RegularExpressions/RegexParseException.cs | 7 +- .../Text/RegularExpressions/RegexWriter.cs | 2 +- .../System/Text/SegmentStringBuilder.cs | 10 +- .../System/Threading/StackHelper.cs | 13 +- .../_last_downloaded_source_url.txt | 2 +- .../additional/HashCode.cs | 5 - .../common/ValueListBuilder.cs | 17 +- .../common/ValueStringBuilder.cs | 20 + ...sHaveNotChanged.netcoreapp3.1.verified.txt | 3 - 21 files changed, 167 insertions(+), 991 deletions(-) create mode 100644 tracer/build/crank/.gitignore delete mode 100644 tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/SR.Designer.cs create mode 100644 tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/SR.g.cs delete mode 100644 tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/SR.resx delete mode 100644 tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexGeneratorAttribute.cs delete mode 100644 tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/additional/HashCode.cs diff --git a/tracer/build/_build/UpdateVendors/VendoredDependency.cs b/tracer/build/_build/UpdateVendors/VendoredDependency.cs index ab66049b2764..aa508a712151 100644 --- a/tracer/build/_build/UpdateVendors/VendoredDependency.cs +++ b/tracer/build/_build/UpdateVendors/VendoredDependency.cs @@ -75,13 +75,13 @@ static VendoredDependency() Add( libraryName: "IndieSystem.Text.RegularExpressions", - version: "0.1", - downloadUrl: "https://github.com/robertpi/IndieRegex/archive/refs/tags/v0.3.zip", - pathToSrc: new[] { "IndieRegex-0.3", "src" }, + version: "0.6", + downloadUrl: "https://github.com/robertpi/IndieRegex/archive/refs/tags/v0.6.zip", + pathToSrc: new[] { "IndieRegex-0.6", "src" }, // Perform standard CS file transform with additional '#nullable enable' directive at the beginning of the files, since the vendored project was built with enable transform: filePath => RewriteCsFileWithStandardTransform(filePath, originalNamespace: "IndieSystem.Text.RegularExpressions", - AddIfNetcoreapp31OrGreater, AddNullableDirectiveTransform, AddIgnoreNullabilityWarningDisablePragma, FixupResources), - relativePathsToExclude: new[] { "additional/HashCode.cs" }); + AddIfNetcoreapp31OrGreater, AddNullableDirectiveTransform, AddIgnoreNullabilityWarningDisablePragma), + relativePathsToExclude: new[] { "additional/HashCode.cs", "SR.resx" }); } public static List All { get; set; } = new List(); @@ -265,17 +265,6 @@ static string AddIgnoreNullabilityWarningDisablePragma(string filePath, string c "CS8774" + // Member 'x' must have a non-null value when exiting. Environment.NewLine + content; - static string FixupResources(string filePath, string content) - { - if (content.Contains("new global::System.Resources.ResourceManager(\"IndieSystem.Text.RegularExpressions.SR\"")) - { - return content.Replace("new global::System.Resources.ResourceManager(\"IndieSystem.Text.RegularExpressions.SR\"", - "new global::System.Resources.ResourceManager(\"Datadog.Trace.Vendors.IndieSystem.Text.RegularExpressions.SR\""); - } - - return content; - } - private static void RewriteFileWithTransform(string filePath, Func transform) { var fileContent = File.ReadAllText(filePath); diff --git a/tracer/build/crank/.gitignore b/tracer/build/crank/.gitignore new file mode 100644 index 000000000000..94a2dd146a22 --- /dev/null +++ b/tracer/build/crank/.gitignore @@ -0,0 +1 @@ +*.json \ No newline at end of file diff --git a/tracer/dependabot/Datadog.Dependabot.Vendors.csproj b/tracer/dependabot/Datadog.Dependabot.Vendors.csproj index 0f91142fb504..baaeca74e745 100644 --- a/tracer/dependabot/Datadog.Dependabot.Vendors.csproj +++ b/tracer/dependabot/Datadog.Dependabot.Vendors.csproj @@ -27,8 +27,8 @@ - - + + diff --git a/tracer/src/Datadog.Trace/Datadog.Trace.csproj b/tracer/src/Datadog.Trace/Datadog.Trace.csproj index 22dea4d06bd1..517b62e27a6d 100644 --- a/tracer/src/Datadog.Trace/Datadog.Trace.csproj +++ b/tracer/src/Datadog.Trace/Datadog.Trace.csproj @@ -91,8 +91,8 @@ $(DefineConstants);ASYNCLOCAL;HASHTABLE;FEATURE_DEFAULT_INTERFACE;FEATURE_SPAN - - $(DefineConstants);REGEXGENERATOR + + $(DefineConstants);NO_ARRAY_POOL diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/IndieSystem.Text.RegularExpressions.csproj.txt b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/IndieSystem.Text.RegularExpressions.csproj.txt index 0933796eaa97..7ffd17f27ac7 100644 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/IndieSystem.Text.RegularExpressions.csproj.txt +++ b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/IndieSystem.Text.RegularExpressions.csproj.txt @@ -6,7 +6,15 @@ enable true false + + + MIT + regex;regular-expression;non-backtracking + Robert Pickering + Robert Pickering, .NET Foundation and Contributors + IndieRegex or IndieSystem.Text.RegularExpressions is a drop-in replacement for .NET's Regex class. It is built using the source of Regex from .NET 7.0, modified and patched to run on .NET Framework 4.6.1, .NET Standard 2.0, .NET Core 3.1, .NET 5.0 and .NET 6.0. + @@ -35,7 +43,6 @@ - @@ -99,9 +106,8 @@ - - + @@ -119,18 +125,13 @@ - - - True - True - SR.resx - - - - ResXFileCodeGenerator - SR.Designer.cs - + - \ No newline at end of file + + + $(DefineConstants);NO_ARRAY_POOL + + + \ No newline at end of file diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/SR.Designer.cs b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/SR.Designer.cs deleted file mode 100644 index d0696285fab2..000000000000 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/SR.Designer.cs +++ /dev/null @@ -1,568 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This file was automatically generated by the UpdateVendors tool. -//------------------------------------------------------------------------------ -#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032 -#pragma warning disable CS8600, CS8601, CS8602, CS8603, CS8604, CS8618, CS8620, CS8714, CS8762, CS8765, CS8766, CS8767, CS8768, CS8769, CS8612, CS8629, CS8774 -#nullable enable -#if NETCOREAPP3_1_OR_GREATER -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace Datadog.Trace.Vendors.IndieSystem.Text.RegularExpressions{ - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal partial class SR { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal SR() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Datadog.Trace.Vendors.IndieSystem.Text.RegularExpressions.SR", typeof(SR).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to Alternation conditions cannot be comments.. - /// - internal static string AlternationHasComment { - get { - return ResourceManager.GetString("AlternationHasComment", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Illegal conditional (?(...)) expression.. - /// - internal static string AlternationHasMalformedCondition { - get { - return ResourceManager.GetString("AlternationHasMalformedCondition", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Conditional alternation is missing a closing parenthesis after the group number {0}.. - /// - internal static string AlternationHasMalformedReference { - get { - return ResourceManager.GetString("AlternationHasMalformedReference", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Alternation conditions do not capture and cannot be named.. - /// - internal static string AlternationHasNamedCapture { - get { - return ResourceManager.GetString("AlternationHasNamedCapture", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Too many | in (?()|).. - /// - internal static string AlternationHasTooManyConditions { - get { - return ResourceManager.GetString("AlternationHasTooManyConditions", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Conditional alternation refers to an undefined group number {0}.. - /// - internal static string AlternationHasUndefinedReference { - get { - return ResourceManager.GetString("AlternationHasUndefinedReference", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Destination array is not long enough to copy all the items in the collection. Check array index and length.. - /// - internal static string Arg_ArrayPlusOffTooSmall { - get { - return ResourceManager.GetString("Arg_ArrayPlusOffTooSmall", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Start index cannot be less than 0 or greater than input length.. - /// - internal static string BeginIndexNotNegative { - get { - return ResourceManager.GetString("BeginIndexNotNegative", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Invalid group name: Group names must begin with a word character.. - /// - internal static string CaptureGroupNameInvalid { - get { - return ResourceManager.GetString("CaptureGroupNameInvalid", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Capture number cannot be zero.. - /// - internal static string CaptureGroupOfZero { - get { - return ResourceManager.GetString("CaptureGroupOfZero", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Count cannot be less than -1.. - /// - internal static string CountTooSmall { - get { - return ResourceManager.GetString("CountTooSmall", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Enumeration has either not started or has already finished.. - /// - internal static string EnumNotStarted { - get { - return ResourceManager.GetString("EnumNotStarted", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to A subtraction must be the last element in a character class.. - /// - internal static string ExclusionGroupNotLast { - get { - return ResourceManager.GetString("ExclusionGroupNotLast", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to atomic subexpressions (?> pattern). - /// - internal static string ExpressionDescription_AtomicSubexpressions { - get { - return ResourceManager.GetString("ExpressionDescription_AtomicSubexpressions", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to backreference (\\ number). - /// - internal static string ExpressionDescription_Backreference { - get { - return ResourceManager.GetString("ExpressionDescription_Backreference", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to balancing group (?<name1-name2>subexpression) or (?'name1-name2' subexpression). - /// - internal static string ExpressionDescription_BalancingGroup { - get { - return ResourceManager.GetString("ExpressionDescription_BalancingGroup", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to captured group conditional (?( name ) yes-pattern | no-pattern ) or (?( number ) yes-pattern| no-pattern ). - /// - internal static string ExpressionDescription_Conditional { - get { - return ResourceManager.GetString("ExpressionDescription_Conditional", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to contiguous matches (\\G). - /// - internal static string ExpressionDescription_ContiguousMatches { - get { - return ResourceManager.GetString("ExpressionDescription_ContiguousMatches", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to test conditional (?( test-pattern ) yes-pattern | no-pattern ). - /// - internal static string ExpressionDescription_IfThenElse { - get { - return ResourceManager.GetString("ExpressionDescription_IfThenElse", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to negative lookahead (?! pattern) or negative lookbehind (?<! pattern). - /// - internal static string ExpressionDescription_NegativeLookaround { - get { - return ResourceManager.GetString("ExpressionDescription_NegativeLookaround", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to positive lookahead (?= pattern) or positive lookbehind (?<= pattern). - /// - internal static string ExpressionDescription_PositiveLookaround { - get { - return ResourceManager.GetString("ExpressionDescription_PositiveLookaround", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Regular expression parser error '{0}' at offset {1}.. - /// - internal static string Generic { - get { - return ResourceManager.GetString("Generic", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to AppDomain data '{0}' contains the invalid value or object '{1}' for specifying a default matching timeout for System.Text.RegularExpressions.Regex.. - /// - internal static string IllegalDefaultRegexMatchTimeoutInAppDomain { - get { - return ResourceManager.GetString("IllegalDefaultRegexMatchTimeoutInAppDomain", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Not enough )'s.. - /// - internal static string InsufficientClosingParentheses { - get { - return ResourceManager.GetString("InsufficientClosingParentheses", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Too many )'s.. - /// - internal static string InsufficientOpeningParentheses { - get { - return ResourceManager.GetString("InsufficientOpeningParentheses", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Insufficient hexadecimal digits.. - /// - internal static string InsufficientOrInvalidHexDigits { - get { - return ResourceManager.GetString("InsufficientOrInvalidHexDigits", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unrecognized grouping construct.. - /// - internal static string InvalidGroupingConstruct { - get { - return ResourceManager.GetString("InvalidGroupingConstruct", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Incomplete \\p{X} character escape.. - /// - internal static string InvalidUnicodePropertyEscape { - get { - return ResourceManager.GetString("InvalidUnicodePropertyEscape", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Length cannot be less than 0 or exceed input length.. - /// - internal static string LengthNotNegative { - get { - return ResourceManager.GetString("LengthNotNegative", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Invalid pattern '{0}' at offset {1}. {2}. - /// - internal static string MakeException { - get { - return ResourceManager.GetString("MakeException", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Malformed \\k<...> named back reference.. - /// - internal static string MalformedNamedReference { - get { - return ResourceManager.GetString("MalformedNamedReference", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Malformed \\p{X} character escape.. - /// - internal static string MalformedUnicodePropertyEscape { - get { - return ResourceManager.GetString("MalformedUnicodePropertyEscape", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Missing control character.. - /// - internal static string MissingControlCharacter { - get { - return ResourceManager.GetString("MissingControlCharacter", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Nested quantifier '{0}'.. - /// - internal static string NestedQuantifiersNotParenthesized { - get { - return ResourceManager.GetString("NestedQuantifiersNotParenthesized", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Result cannot be called on a failed Match.. - /// - internal static string NoResultOnFailed { - get { - return ResourceManager.GetString("NoResultOnFailed", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Regex replacements with substitutions of groups are not supported with RegexOptions.NonBacktracking.. - /// - internal static string NotSupported_NonBacktrackingAndReplacementsWithSubstitutionsOfGroups { - get { - return ResourceManager.GetString("NotSupported_NonBacktrackingAndReplacementsWithSubstitutionsOfGroups", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to RegexOptions.NonBacktracking is not supported in conjunction with expressions containing: '{0}'.. - /// - internal static string NotSupported_NonBacktrackingConflictingExpression { - get { - return ResourceManager.GetString("NotSupported_NonBacktrackingConflictingExpression", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The specified pattern with RegexOptions.NonBacktracking could result in an automata as large as '{0}' nodes, which is larger than the configured limit of '{1}'.. - /// - internal static string NotSupported_NonBacktrackingUnsafeSize { - get { - return ResourceManager.GetString("NotSupported_NonBacktrackingUnsafeSize", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Collection is read-only.. - /// - internal static string NotSupported_ReadOnlyCollection { - get { - return ResourceManager.GetString("NotSupported_ReadOnlyCollection", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to This platform does not support writing compiled regular expressions to an assembly. Use RegexGeneratorAttribute with the regular expression source generator instead.. - /// - internal static string PlatformNotSupported_CompileToAssembly { - get { - return ResourceManager.GetString("PlatformNotSupported_CompileToAssembly", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Quantifier '{0}' following nothing.. - /// - internal static string QuantifierAfterNothing { - get { - return ResourceManager.GetString("QuantifierAfterNothing", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Quantifier and capture group numbers must be less than or equal to Int32.MaxValue.. - /// - internal static string QuantifierOrCaptureGroupOutOfRange { - get { - return ResourceManager.GetString("QuantifierOrCaptureGroupOutOfRange", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The Regex engine has timed out while trying to match a pattern to an input string. This can occur for many reasons, including very large inputs or excessive backtracking caused by nested quantifiers, back-references and other factors.. - /// - internal static string RegexMatchTimeoutException_Occurred { - get { - return ResourceManager.GetString("RegexMatchTimeoutException_Occurred", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to [x-y] range in reverse order.. - /// - internal static string ReversedCharacterRange { - get { - return ResourceManager.GetString("ReversedCharacterRange", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Illegal {x,y} with x > y.. - /// - internal static string ReversedQuantifierRange { - get { - return ResourceManager.GetString("ReversedQuantifierRange", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Cannot include class \\{0} in character range.. - /// - internal static string ShorthandClassInCharacterRange { - get { - return ResourceManager.GetString("ShorthandClassInCharacterRange", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Reference to undefined group name '{0}'.. - /// - internal static string UndefinedNamedReference { - get { - return ResourceManager.GetString("UndefinedNamedReference", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Reference to undefined group number {0}.. - /// - internal static string UndefinedNumberedReference { - get { - return ResourceManager.GetString("UndefinedNumberedReference", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Illegal \\ at end of pattern.. - /// - internal static string UnescapedEndingBackslash { - get { - return ResourceManager.GetString("UnescapedEndingBackslash", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unrecognized control character.. - /// - internal static string UnrecognizedControlCharacter { - get { - return ResourceManager.GetString("UnrecognizedControlCharacter", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unrecognized escape sequence \\{0}.. - /// - internal static string UnrecognizedEscape { - get { - return ResourceManager.GetString("UnrecognizedEscape", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unknown property '{0}'.. - /// - internal static string UnrecognizedUnicodeProperty { - get { - return ResourceManager.GetString("UnrecognizedUnicodeProperty", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unterminated [] set.. - /// - internal static string UnterminatedBracket { - get { - return ResourceManager.GetString("UnterminatedBracket", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Unterminated (?#...) comment.. - /// - internal static string UnterminatedComment { - get { - return ResourceManager.GetString("UnterminatedComment", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Searching an input span using a pre-compiled Regex assembly is not supported. Please use the string overloads or use a newer Regex implementation.. - /// - internal static string UsingSpanAPIsWithCompiledToAssembly { - get { - return ResourceManager.GetString("UsingSpanAPIsWithCompiledToAssembly", resourceCulture); - } - } - } -} - -#endif \ No newline at end of file diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/SR.g.cs b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/SR.g.cs new file mode 100644 index 000000000000..241569538be0 --- /dev/null +++ b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/SR.g.cs @@ -0,0 +1,89 @@ +//------------------------------------------------------------------------------ +// +// This file was automatically generated by the UpdateVendors tool. +//------------------------------------------------------------------------------ +#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032 +#pragma warning disable CS8600, CS8601, CS8602, CS8603, CS8604, CS8618, CS8620, CS8714, CS8762, CS8765, CS8766, CS8767, CS8768, CS8769, CS8612, CS8629, CS8774 +#nullable enable +#if NETCOREAPP3_1_OR_GREATER +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Datadog.Trace.Vendors.IndieSystem.Text.RegularExpressions; + +using System; + + +/// +/// A strongly-typed class, for hardcode messages +/// +internal partial class SR +{ + + public const string Generic = @"Regular expression parser error '{0}' at offset {1}."; + public const string AlternationHasNamedCapture = @"Alternation conditions do not capture and cannot be named."; + public const string AlternationHasComment = @"Alternation conditions cannot be comments."; + public const string Arg_ArrayPlusOffTooSmall = @"Destination array is not long enough to copy all the items in the collection. Check array index and length."; + public const string ShorthandClassInCharacterRange = @"Cannot include class \\{0} in character range."; + public const string BeginIndexNotNegative = @"Start index cannot be less than 0 or greater than input length."; + public const string QuantifierOrCaptureGroupOutOfRange = @"Quantifier and capture group numbers must be less than or equal to Int32.MaxValue."; + public const string CaptureGroupOfZero = @"Capture number cannot be zero."; + public const string CountTooSmall = @"Count cannot be less than -1."; + public const string EnumNotStarted = @"Enumeration has either not started or has already finished."; + public const string AlternationHasMalformedCondition = @"Illegal conditional (?(...)) expression."; + public const string IllegalDefaultRegexMatchTimeoutInAppDomain = @"AppDomain data '{0}' contains the invalid value or object '{1}' for specifying a default matching timeout for System.Text.RegularExpressions.Regex."; + public const string UnescapedEndingBackslash = @"Illegal \\ at end of pattern."; + public const string ReversedQuantifierRange = @"Illegal {x,y} with x > y."; + public const string InvalidUnicodePropertyEscape = @"Incomplete \\p{X} character escape."; + public const string CaptureGroupNameInvalid = @"Invalid group name: Group names must begin with a word character."; + public const string LengthNotNegative = @"Length cannot be less than 0 or exceed input length."; + public const string MalformedNamedReference = @"Malformed \\k<...> named back reference."; + public const string AlternationHasMalformedReference = @"Conditional alternation is missing a closing parenthesis after the group number {0}."; + public const string MalformedUnicodePropertyEscape = @"Malformed \\p{X} character escape."; + public const string MakeException = @"Invalid pattern '{0}' at offset {1}. {2}"; + public const string MissingControlCharacter = @"Missing control character."; + public const string NestedQuantifiersNotParenthesized = @"Nested quantifier '{0}'."; + public const string NoResultOnFailed = @"Result cannot be called on a failed Match."; + public const string InsufficientClosingParentheses = @"Not enough )'s."; + public const string NotSupported_ReadOnlyCollection = @"Collection is read-only."; + public const string PlatformNotSupported_CompileToAssembly = @"This platform does not support writing compiled regular expressions to an assembly. Use RegexGeneratorAttribute with the regular expression source generator instead."; + public const string QuantifierAfterNothing = @"Quantifier '{0}' following nothing."; + public const string RegexMatchTimeoutException_Occurred = @"The Regex engine has timed out while trying to match a pattern to an input string. This can occur for many reasons, including very large inputs or excessive backtracking caused by nested quantifiers, back-references and other factors."; + public const string ReversedCharacterRange = @"[x-y] range in reverse order."; + public const string ExclusionGroupNotLast = @"A subtraction must be the last element in a character class."; + public const string InsufficientOrInvalidHexDigits = @"Insufficient hexadecimal digits."; + public const string AlternationHasTooManyConditions = @"Too many | in (?()|)."; + public const string InsufficientOpeningParentheses = @"Too many )'s."; + public const string UndefinedNumberedReference = @"Reference to undefined group number {0}."; + public const string UndefinedNamedReference = @"Reference to undefined group name '{0}'."; + public const string AlternationHasUndefinedReference = @"Conditional alternation refers to an undefined group number {0}."; + public const string UnrecognizedUnicodeProperty = @"Unknown property '{0}'."; + public const string UnrecognizedControlCharacter = @"Unrecognized control character."; + public const string UnrecognizedEscape = @"Unrecognized escape sequence \\{0}."; + public const string InvalidGroupingConstruct = @"Unrecognized grouping construct."; + public const string UnterminatedBracket = @"Unterminated [] set."; + public const string UnterminatedComment = @"Unterminated (?#...) comment."; + public const string NotSupported_NonBacktrackingAndReplacementsWithSubstitutionsOfGroups = @"Regex replacements with substitutions of groups are not supported with RegexOptions.NonBacktracking."; + public const string NotSupported_NonBacktrackingConflictingExpression = @"RegexOptions.NonBacktracking is not supported in conjunction with expressions containing: '{0}'."; + public const string NotSupported_NonBacktrackingUnsafeSize = @"The specified pattern with RegexOptions.NonBacktracking could result in an automata as large as '{0}' nodes, which is larger than the configured limit of '{1}'."; + public const string ExpressionDescription_Backreference = @"backreference (\\ number)"; + public const string ExpressionDescription_Conditional = @"captured group conditional (?( name ) yes-pattern | no-pattern ) or (?( number ) yes-pattern| no-pattern )"; + public const string ExpressionDescription_PositiveLookaround = @"positive lookahead (?= pattern) or positive lookbehind (?<= pattern)"; + public const string ExpressionDescription_NegativeLookaround = @"negative lookahead (?! pattern) or negative lookbehind (? pattern)"; + public const string ExpressionDescription_IfThenElse = @"test conditional (?( test-pattern ) yes-pattern | no-pattern )"; + public const string ExpressionDescription_BalancingGroup = @"balancing group (?subexpression) or (?'name1-name2' subexpression)"; + public const string UsingSpanAPIsWithCompiledToAssembly = @"Searching an input span using a pre-compiled Regex assembly is not supported. Please use the string overloads or use a newer Regex implementation."; + +} + + +#endif \ No newline at end of file diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/SR.resx b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/SR.resx deleted file mode 100644 index b3f09d64acdc..000000000000 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/SR.resx +++ /dev/null @@ -1,288 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Regular expression parser error '{0}' at offset {1}. - - - Alternation conditions do not capture and cannot be named. - - - Alternation conditions cannot be comments. - - - Destination array is not long enough to copy all the items in the collection. Check array index and length. - - - Cannot include class \\{0} in character range. - - - Start index cannot be less than 0 or greater than input length. - - - Quantifier and capture group numbers must be less than or equal to Int32.MaxValue. - - - Capture number cannot be zero. - - - Count cannot be less than -1. - - - Enumeration has either not started or has already finished. - - - Illegal conditional (?(...)) expression. - - - AppDomain data '{0}' contains the invalid value or object '{1}' for specifying a default matching timeout for System.Text.RegularExpressions.Regex. - - - Illegal \\ at end of pattern. - - - Illegal {x,y} with x > y. - - - Incomplete \\p{X} character escape. - - - Invalid group name: Group names must begin with a word character. - - - Length cannot be less than 0 or exceed input length. - - - Malformed \\k<...> named back reference. - - - Conditional alternation is missing a closing parenthesis after the group number {0}. - - - Malformed \\p{X} character escape. - - - Invalid pattern '{0}' at offset {1}. {2} - - - Missing control character. - - - Nested quantifier '{0}'. - - - Result cannot be called on a failed Match. - - - Not enough )'s. - - - Collection is read-only. - - - This platform does not support writing compiled regular expressions to an assembly. Use RegexGeneratorAttribute with the regular expression source generator instead. - - - Quantifier '{0}' following nothing. - - - The Regex engine has timed out while trying to match a pattern to an input string. This can occur for many reasons, including very large inputs or excessive backtracking caused by nested quantifiers, back-references and other factors. - - - [x-y] range in reverse order. - - - A subtraction must be the last element in a character class. - - - Insufficient hexadecimal digits. - - - Too many | in (?()|). - - - Too many )'s. - - - Reference to undefined group number {0}. - - - Reference to undefined group name '{0}'. - - - Conditional alternation refers to an undefined group number {0}. - - - Unknown property '{0}'. - - - Unrecognized control character. - - - Unrecognized escape sequence \\{0}. - - - Unrecognized grouping construct. - - - Unterminated [] set. - - - Unterminated (?#...) comment. - - - Regex replacements with substitutions of groups are not supported with RegexOptions.NonBacktracking. - {Locked="RegexOptions.NonBacktracking"} - - - RegexOptions.NonBacktracking is not supported in conjunction with expressions containing: '{0}'. - {Locked="RegexOptions.NonBacktracking"} - - - The specified pattern with RegexOptions.NonBacktracking could result in an automata as large as '{0}' nodes, which is larger than the configured limit of '{1}'. - {Locked="RegexOptions.NonBacktracking"} - - - backreference (\\ number) - - - captured group conditional (?( name ) yes-pattern | no-pattern ) or (?( number ) yes-pattern| no-pattern ) - - - positive lookahead (?= pattern) or positive lookbehind (?<= pattern) - - - negative lookahead (?! pattern) or negative lookbehind (?<! pattern) - - - contiguous matches (\\G) - - - atomic subexpressions (?> pattern) - - - test conditional (?( test-pattern ) yes-pattern | no-pattern ) - - - balancing group (?<name1-name2>subexpression) or (?'name1-name2' subexpression) - - - Searching an input span using a pre-compiled Regex assembly is not supported. Please use the string overloads or use a newer Regex implementation. - - \ No newline at end of file diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexCharClass.cs b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexCharClass.cs index 8b99548ae595..1c106de2a6b0 100644 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexCharClass.cs +++ b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexCharClass.cs @@ -1239,7 +1239,7 @@ static bool InitializeValue(char ch, string set, ref uint[]? asciiLazyCache) } uint[]? cache = asciiLazyCache ?? Interlocked.CompareExchange(ref asciiLazyCache, new uint[CacheArrayLength], null) ?? asciiLazyCache; -#if REGEXGENERATOR || !NET5_0_OR_GREATER +#if !NET5_0_OR_GREATER InterlockedExtensions.Or(ref cache[ch >> 4], bitsToSet); #else Interlocked.Or(ref cache[ch >> 4], bitsToSet); diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexGeneratorAttribute.cs b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexGeneratorAttribute.cs deleted file mode 100644 index 5876f2d7aba6..000000000000 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexGeneratorAttribute.cs +++ /dev/null @@ -1,57 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This file was automatically generated by the UpdateVendors tool. -//------------------------------------------------------------------------------ -#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032 -#pragma warning disable CS8600, CS8601, CS8602, CS8603, CS8604, CS8618, CS8620, CS8714, CS8762, CS8765, CS8766, CS8767, CS8768, CS8769, CS8612, CS8629, CS8774 -#nullable enable -#if NETCOREAPP3_1_OR_GREATER -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Diagnostics.CodeAnalysis; -using System.Threading; - -namespace Datadog.Trace.Vendors.IndieSystem.Text.RegularExpressions; - -/// Instructs the System.Text.RegularExpressions source generator to generate an implementation of the specified regular expression. -/// The generator associated with this attribute only supports C#. It only supplies an implementation when applied to static, partial, parameterless, non-generic methods that are typed to return . -[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] -internal sealed class RegexGeneratorAttribute : Attribute -{ - /// Initializes a new instance of the with the specified pattern. - /// The regular expression pattern to match. - public RegexGeneratorAttribute([StringSyntax(StringSyntaxAttribute.Regex)] string pattern) : this (pattern, RegexOptions.None) - { - } - - /// Initializes a new instance of the with the specified pattern and options. - /// The regular expression pattern to match. - /// A bitwise combination of the enumeration values that modify the regular expression. - public RegexGeneratorAttribute([StringSyntax(StringSyntaxAttribute.Regex, "options")] string pattern, RegexOptions options) : this (pattern, options, Timeout.Infinite) - { - } - - /// Initializes a new instance of the with the specified pattern, options, and timeout. - /// The regular expression pattern to match. - /// A bitwise combination of the enumeration values that modify the regular expression. - /// A time-out interval (milliseconds), or to indicate that the method should not time out. - public RegexGeneratorAttribute([StringSyntax(StringSyntaxAttribute.Regex, "options")] string pattern, RegexOptions options, int matchTimeoutMilliseconds) - { - Pattern = pattern; - Options = options; - MatchTimeoutMilliseconds = matchTimeoutMilliseconds; - } - - /// Gets the regular expression pattern to match. - public string Pattern { get; } - - /// Gets a bitwise combination of the enumeration values that modify the regular expression. - public RegexOptions Options { get; } - - /// Gets a time-out interval (milliseconds), or to indicate that the method should not time out. - public int MatchTimeoutMilliseconds { get; } -} - -#endif \ No newline at end of file diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexOptions.cs b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexOptions.cs index aae61fd155c3..a053a5e3a127 100644 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexOptions.cs +++ b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexOptions.cs @@ -14,12 +14,7 @@ namespace Datadog.Trace.Vendors.IndieSystem.Text.RegularExpressions { [Flags] -#if REGEXGENERATOR - internal -#else - public -#endif - enum RegexOptions + internal enum RegexOptions { /// Use default behavior. None = 0x0000, diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexParseError.cs b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexParseError.cs index d10ff41d9a12..ed0ec7972c02 100644 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexParseError.cs +++ b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexParseError.cs @@ -18,12 +18,7 @@ namespace Datadog.Trace.Vendors.IndieSystem.Text.RegularExpressions /// /// This information is made available through . /// -#if REGEXGENERATOR - internal -#else - public -#endif - enum RegexParseError + internal enum RegexParseError { /// /// An unknown regular expression parse error. diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexParseException.cs b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexParseException.cs index d77d253439be..8b1c476a75bb 100644 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexParseException.cs +++ b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexParseException.cs @@ -19,12 +19,7 @@ namespace Datadog.Trace.Vendors.IndieSystem.Text.RegularExpressions /// detailed information in the and properties. /// [Serializable] -#if REGEXGENERATOR - internal -#else - public -#endif - sealed class RegexParseException : ArgumentException + internal sealed class RegexParseException : ArgumentException { /// Gets the error that happened during parsing. public RegexParseError Error { get; } diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexWriter.cs b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexWriter.cs index c6c1732a3cc2..8ecd42cf0f83 100644 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexWriter.cs +++ b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/RegularExpressions/RegexWriter.cs @@ -187,7 +187,7 @@ private void Emit(RegexOpcode op, int opd1, int opd2) /// private int StringCode(string str) { -#if REGEXGENERATOR || !NET6_0_OR_GREATER +#if !NET6_0_OR_GREATER if (!_stringTable.TryGetValue(str, out int i)) { i = _stringTable.Count; diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/SegmentStringBuilder.cs b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/SegmentStringBuilder.cs index 012342722126..51ca9bb8c8d4 100644 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/SegmentStringBuilder.cs +++ b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Text/SegmentStringBuilder.cs @@ -60,10 +60,15 @@ private void GrowAndAdd(ReadOnlyMemory segment) const int DefaultArraySize = 256; int newSize = array.Length == 0 ? DefaultArraySize : array.Length * 2; +#if NO_ARRAY_POOL + _array = new ReadOnlyMemory[newSize]; + Array.Copy(array, _array, _count); +#else ReadOnlyMemory[] newArray = _array = ArrayPool>.Shared.Rent(newSize); Array.Copy(array, newArray, _count); ArrayPool>.Shared.Return(array, clearArray: true); - newArray[_count++] = segment; +#endif + _array[_count++] = segment; } /// Gets a span of all segments in the builder. @@ -101,7 +106,10 @@ public override string ToString() span.Clear(); this = default; + +#if !NO_ARRAY_POOL ArrayPool>.Shared.Return(array); +#endif return result; } diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Threading/StackHelper.cs b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Threading/StackHelper.cs index f78444b4ff57..1571f2697154 100644 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Threading/StackHelper.cs +++ b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/System/Threading/StackHelper.cs @@ -20,22 +20,11 @@ internal static class StackHelper /// Tries to ensure there is sufficient stack to execute the average .NET function. public static bool TryEnsureSufficientExecutionStack() { -#if REGEXGENERATOR - try - { - RuntimeHelpers.EnsureSufficientExecutionStack(); - return true; - } - catch - { - return false; - } -#else + #if NETFRAMEWORK || NETSTANDARD return true; #else return RuntimeHelpers.TryEnsureSufficientExecutionStack(); -#endif #endif } diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/_last_downloaded_source_url.txt b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/_last_downloaded_source_url.txt index 9df2cb1af257..8ba5911dc7ef 100644 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/_last_downloaded_source_url.txt +++ b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/_last_downloaded_source_url.txt @@ -1 +1 @@ -https://github.com/robertpi/IndieRegex/archive/refs/tags/v0.3.zip \ No newline at end of file +https://github.com/robertpi/IndieRegex/archive/refs/tags/v0.6.zip \ No newline at end of file diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/additional/HashCode.cs b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/additional/HashCode.cs deleted file mode 100644 index de7d50fa6557..000000000000 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/additional/HashCode.cs +++ /dev/null @@ -1,5 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This file was automatically generated by the UpdateVendors tool. -//------------------------------------------------------------------------------ -#pragma warning disable CS0618, CS0649, CS1574, CS1580, CS1581, CS1584, CS1591, CS1573, CS8018, SYSLIB0011, SYSLIB0032 diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/common/ValueListBuilder.cs b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/common/ValueListBuilder.cs index 0a58b71539ae..2b4e5775ecd5 100644 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/common/ValueListBuilder.cs +++ b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/common/ValueListBuilder.cs @@ -18,13 +18,17 @@ namespace System.Collections.Generic internal ref partial struct ValueListBuilder { private Span _span; +#if !NO_ARRAY_POOL private T[]? _arrayFromPool; +#endif private int _pos; public ValueListBuilder(Span initialSpan) { _span = initialSpan; +#if !NO_ARRAY_POOL _arrayFromPool = null; +#endif _pos = 0; } @@ -82,12 +86,14 @@ public ReadOnlySpan AsSpan() [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Dispose() { +#if !NO_ARRAY_POOL T[]? toReturn = _arrayFromPool; if (toReturn != null) { _arrayFromPool = null; ArrayPool.Shared.Return(toReturn); } +#endif } private void Grow() @@ -109,7 +115,15 @@ private void Grow() nextCapacity = Math.Max(Math.Max(_span.Length + 1, ArrayMaxLength), _span.Length); } +#if NO_ARRAY_POOL + T[] array = new T[nextCapacity]; + + _span.CopyTo(array); + + _span = array; +#else T[] array = ArrayPool.Shared.Rent(nextCapacity); + _span.CopyTo(array); T[]? toReturn = _arrayFromPool; @@ -118,8 +132,9 @@ private void Grow() { ArrayPool.Shared.Return(toReturn); } +#endif } } } -#endif \ No newline at end of file +#endif diff --git a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/common/ValueStringBuilder.cs b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/common/ValueStringBuilder.cs index c3489354b63d..dd7201c0339d 100644 --- a/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/common/ValueStringBuilder.cs +++ b/tracer/src/Datadog.Trace/Vendors/IndieSystem.Text.RegularExpressions/common/ValueStringBuilder.cs @@ -18,21 +18,29 @@ namespace System.Text { internal ref partial struct ValueStringBuilder { +#if !NO_ARRAY_POOL private char[]? _arrayToReturnToPool; +#endif private Span _chars; private int _pos; public ValueStringBuilder(Span initialBuffer) { +#if !NO_ARRAY_POOL _arrayToReturnToPool = null; +#endif _chars = initialBuffer; _pos = 0; } public ValueStringBuilder(int initialCapacity) { +#if NO_ARRAY_POOL + _chars = new char[initialCapacity]; +#else _arrayToReturnToPool = ArrayPool.Shared.Rent(initialCapacity); _chars = _arrayToReturnToPool; +#endif _pos = 0; } @@ -312,6 +320,13 @@ private void Grow(int additionalCapacityBeyondPos) // Make sure to let Rent throw an exception if the caller has a bug and the desired capacity is negative. // This could also go negative if the actual required length wraps around. +#if NO_ARRAY_POOL + char[] array = new char[newCapacity]; + + _chars.Slice(0, _pos).CopyTo(array); + + _chars = array; +#else char[] poolArray = ArrayPool.Shared.Rent(newCapacity); _chars.Slice(0, _pos).CopyTo(poolArray); @@ -322,17 +337,22 @@ private void Grow(int additionalCapacityBeyondPos) { ArrayPool.Shared.Return(toReturn); } + #endif } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Dispose() { +#if NO_ARRAY_POOL + this = default; +#else char[]? toReturn = _arrayToReturnToPool; this = default; // for safety, to avoid using pooled array if this instance is erroneously appended to again if (toReturn != null) { ArrayPool.Shared.Return(toReturn); } +#endif } } } diff --git a/tracer/test/Datadog.Trace.Tests/Snapshots/PublicApiTests.Datadog.Trace.AssemblyReferencesHaveNotChanged.netcoreapp3.1.verified.txt b/tracer/test/Datadog.Trace.Tests/Snapshots/PublicApiTests.Datadog.Trace.AssemblyReferencesHaveNotChanged.netcoreapp3.1.verified.txt index 2313b2512ea7..10fb0ce95671 100644 --- a/tracer/test/Datadog.Trace.Tests/Snapshots/PublicApiTests.Datadog.Trace.AssemblyReferencesHaveNotChanged.netcoreapp3.1.verified.txt +++ b/tracer/test/Datadog.Trace.Tests/Snapshots/PublicApiTests.Datadog.Trace.AssemblyReferencesHaveNotChanged.netcoreapp3.1.verified.txt @@ -4,7 +4,6 @@ Microsoft.AspNetCore.Mvc.Abstractions, Version=2.0.0.0, Culture=neutral, PublicK Microsoft.AspNetCore.Routing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 Microsoft.AspNetCore.Routing.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 Microsoft.Extensions.Primitives, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60 -System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 System.Collections, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.Concurrent, Version=4.0.15.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Collections.NonGeneric, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a @@ -17,7 +16,6 @@ System.Diagnostics.Debug, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5 System.Diagnostics.DiagnosticSource, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51 System.Diagnostics.Process, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Diagnostics.StackTrace, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a -System.Diagnostics.Tools, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Diagnostics.TraceSource, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Diagnostics.Tracing, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.IO.Compression, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 @@ -38,7 +36,6 @@ System.Reflection.Emit, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7 System.Reflection.Emit.ILGeneration, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Reflection.Emit.Lightweight, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Reflection.Primitives, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a -System.Resources.ResourceManager, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a System.Runtime.Extensions, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a