-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Avoid Regex in DscClassCache.CreateKeywordFromCimClass #26306
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 all commits
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 | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -525,9 +525,6 @@ public DscClassCacheEntry(DSCResourceRunAsCredential aDSCResourceRunAsCredential | |||||||||||||||||||||||||||||||||||||
| public static class DscClassCache | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| private const string InboxDscResourceModulePath = "WindowsPowershell\\v1.0\\Modules\\PsDesiredStateConfiguration"; | ||||||||||||||||||||||||||||||||||||||
| private const string reservedDynamicKeywords = "^(Synchronization|Certificate|IIS|SQL)$"; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private const string reservedProperties = "^(Require|Trigger|Notify|Before|After|Subscribe)$"; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private static readonly PSTraceSource s_tracer = PSTraceSource.GetTracer("DSC", "DSC Class Cache"); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
@@ -1264,13 +1261,6 @@ public static void ValidateInstanceText(string instanceText) | |||||||||||||||||||||||||||||||||||||
| parser.ValidateInstanceText(instanceText); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private static bool IsMagicProperty(string propertyName) | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| return System.Text.RegularExpressions.Regex.Match(propertyName, | ||||||||||||||||||||||||||||||||||||||
| "^(ResourceId|SourceInfo|ModuleName|ModuleVersion|ConfigurationName)$", | ||||||||||||||||||||||||||||||||||||||
| System.Text.RegularExpressions.RegexOptions.IgnoreCase).Success; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private static string GetFriendlyName(CimClass cimClass) | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| try | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -1367,7 +1357,8 @@ private static DynamicKeyword CreateKeywordFromCimClass(string moduleName, Versi | |||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||
| // Skip all of the base, meta, registration and other classes that are not intended to be used directly by a script author | ||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||
| if (System.Text.RegularExpressions.Regex.Match(keywordString, "^OMI_Base|^OMI_.*Registration", System.Text.RegularExpressions.RegexOptions.IgnoreCase).Success) | ||||||||||||||||||||||||||||||||||||||
| if (keywordString.StartsWith("OMI_Base", StringComparison.OrdinalIgnoreCase) || | ||||||||||||||||||||||||||||||||||||||
| (keywordString.StartsWith("OMI_", StringComparison.OrdinalIgnoreCase) && keywordString.IndexOf("Registration", 4, StringComparison.OrdinalIgnoreCase) >= 0)) | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -1383,7 +1374,7 @@ private static DynamicKeyword CreateKeywordFromCimClass(string moduleName, Versi | |||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // If it's one of reserved dynamic keyword, mark it | ||||||||||||||||||||||||||||||||||||||
| if (System.Text.RegularExpressions.Regex.Match(keywordString, reservedDynamicKeywords, System.Text.RegularExpressions.RegexOptions.IgnoreCase).Success) | ||||||||||||||||||||||||||||||||||||||
| if (IsReservedDynamicKeyword(keywordString)) | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| keyword.IsReservedKeyword = true; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -1441,7 +1432,7 @@ private static DynamicKeyword CreateKeywordFromCimClass(string moduleName, Versi | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| // If it's one of our reserved properties, save it for error reporting | ||||||||||||||||||||||||||||||||||||||
| if (System.Text.RegularExpressions.Regex.Match(prop.Name, reservedProperties, System.Text.RegularExpressions.RegexOptions.IgnoreCase).Success) | ||||||||||||||||||||||||||||||||||||||
| if (IsReservedProperty(prop.Name)) | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| keyword.HasReservedProperties = true; | ||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -1540,6 +1531,27 @@ private static DynamicKeyword CreateKeywordFromCimClass(string moduleName, Versi | |||||||||||||||||||||||||||||||||||||
| UpdateKnownRestriction(keyword); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return keyword; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| static bool IsMagicProperty(string propertyName) => | ||||||||||||||||||||||||||||||||||||||
| string.Equals(propertyName, "ResourceId", StringComparison.OrdinalIgnoreCase) || | ||||||||||||||||||||||||||||||||||||||
| string.Equals(propertyName, "SourceInfo", StringComparison.OrdinalIgnoreCase) || | ||||||||||||||||||||||||||||||||||||||
| string.Equals(propertyName, "ModuleName", StringComparison.OrdinalIgnoreCase) || | ||||||||||||||||||||||||||||||||||||||
| string.Equals(propertyName, "ModuleVersion", StringComparison.OrdinalIgnoreCase) || | ||||||||||||||||||||||||||||||||||||||
| string.Equals(propertyName, "ConfigurationName", StringComparison.OrdinalIgnoreCase); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1535
to
+1540
Collaborator
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. If this change is just to get rid of the Regex, then it doesn't make sense.
Contributor
Author
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. Avoiding Regex can make significant improvement:
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| static bool IsReservedDynamicKeyword(string keyword) => | ||||||||||||||||||||||||||||||||||||||
| string.Equals(keyword, "Synchronization", StringComparison.OrdinalIgnoreCase) || | ||||||||||||||||||||||||||||||||||||||
| string.Equals(keyword, "Certificate", StringComparison.OrdinalIgnoreCase) || | ||||||||||||||||||||||||||||||||||||||
| string.Equals(keyword, "IIS", StringComparison.OrdinalIgnoreCase) || | ||||||||||||||||||||||||||||||||||||||
| string.Equals(keyword, "SQL", StringComparison.OrdinalIgnoreCase); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| static bool IsReservedProperty(string name) => | ||||||||||||||||||||||||||||||||||||||
| string.Equals(name, "Require", StringComparison.OrdinalIgnoreCase) || | ||||||||||||||||||||||||||||||||||||||
| string.Equals(name, "Trigger", StringComparison.OrdinalIgnoreCase) || | ||||||||||||||||||||||||||||||||||||||
| string.Equals(name, "Notify", StringComparison.OrdinalIgnoreCase) || | ||||||||||||||||||||||||||||||||||||||
| string.Equals(name, "Before", StringComparison.OrdinalIgnoreCase) || | ||||||||||||||||||||||||||||||||||||||
| string.Equals(name, "After", StringComparison.OrdinalIgnoreCase) || | ||||||||||||||||||||||||||||||||||||||
| string.Equals(name, "Subscribe", StringComparison.OrdinalIgnoreCase); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.