Skip to content
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

Implement early bail-out #5410

Merged
merged 6 commits into from
Feb 18, 2022
Merged

Conversation

costin-zaharia-sonarsource
Copy link
Member

Fixes #5375

@pavel-mikula-sonarsource
Copy link
Contributor

1st round of comments was resolved in #5405

End Class

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI (no change needed): This line should not have been removed. There should be empty line before&after Class and Namespace lines

Copy link
Contributor

@pavel-mikula-sonarsource pavel-mikula-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with few nitpicks

@@ -46,6 +47,8 @@ public abstract class LocksReleasedAllPathsBase : SymbolicRuleCheck
"TryEnterWriteLock"
};

protected abstract ISafeSyntaxWalker GetSyntaxWalker(LockAcquireReleaseCollector collector);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be explicit about the price of the operation. Get should give something that exists.

Suggested change
protected abstract ISafeSyntaxWalker GetSyntaxWalker(LockAcquireReleaseCollector collector);
protected abstract ISafeSyntaxWalker CreateSyntaxWalker(LockAcquireReleaseCollector collector);


protected sealed class LockAcquireReleaseCollector
{
private static readonly HashSet<string> LockTypes = new() { "Mutex" }; // For some APIs ctor can directly acquire the lock (e.g. Mutex).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this already need a hashset already? A single string should perform way better. Even an array could be a bit faster by not computing the hash code.

// ToDo: Implement early bail-out if there's no interesting descendant node in context.Node to avoid useless SE runs https://github.com/SonarSource/sonar-dotnet/issues/5375
public override bool ShouldExecute() =>
NodeContext.Node.DescendantNodes().OfType<IdentifierNameSyntax>().Any(x => ShouldExecuteFor(x.Identifier));
protected override ISafeSyntaxWalker GetSyntaxWalker(LockAcquireReleaseCollector collector) => new LockAcquireReleaseWalker(collector);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: It's not a property and body is not trivial. Should be on the next line

Suggested change
protected override ISafeSyntaxWalker GetSyntaxWalker(LockAcquireReleaseCollector collector) => new LockAcquireReleaseWalker(collector);
protected override ISafeSyntaxWalker GetSyntaxWalker(LockAcquireReleaseCollector collector) =>
new LockAcquireReleaseWalker(collector);

// ToDo: Implement early bail-out if there's no interesting descendant node in context.Node to avoid useless SE runs https://github.com/SonarSource/sonar-dotnet/issues/5375
public override bool ShouldExecute() =>
NodeContext.Node.DescendantNodes().OfType<IdentifierNameSyntax>().Any(x => ShouldExecuteFor(x.Identifier));
protected override ISafeSyntaxWalker GetSyntaxWalker(LockAcquireReleaseCollector collector) => new LockAcquireReleaseWalker(collector);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nitpick, body should be on the next line

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Base automatically changed from costin/SafeSyntaxWalker to master February 18, 2022 14:12
@costin-zaharia-sonarsource costin-zaharia-sonarsource marked this pull request as ready for review February 18, 2022 14:12
@costin-zaharia-sonarsource costin-zaharia-sonarsource merged commit 763723d into master Feb 18, 2022
@costin-zaharia-sonarsource costin-zaharia-sonarsource deleted the costin/exit-early-cs branch February 18, 2022 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

S2222 performance: Improve early bailout logic
2 participants