Skip to content
This repository was archived by the owner on Aug 2, 2023. It is now read-only.

Add a code analyzer to fix certain Memory<T> usage#2236

Merged
ahsonkhan merged 2 commits intodotnet:masterfrom
ahsonkhan:AddMemSpanCodeAnalyzer
May 1, 2018
Merged

Add a code analyzer to fix certain Memory<T> usage#2236
ahsonkhan merged 2 commits intodotnet:masterfrom
ahsonkhan:AddMemSpanCodeAnalyzer

Conversation

@ahsonkhan
Copy link
Contributor

@ahsonkhan ahsonkhan commented May 1, 2018

Fixes #2215

Swap the order of Memory<T>.Slice(start, length).Span to be Memory<T>.Span.Slice(start, length)

Screenshots:

  1. image

  2. image

  3. image

Majority of the code here is template code. Focus on the following files:

corefxlab fix - #2237

cc @dotnet/corefxlab-contrib, @khellang, @VSadov, @KrzysztofCwalina, @terrajobst

@ahsonkhan ahsonkhan added the area-CodeAnalyzer Code Analyzer for Span<T> Usage label May 1, 2018
@ahsonkhan ahsonkhan merged commit 0ec4fa5 into dotnet:master May 1, 2018
@ahsonkhan ahsonkhan deleted the AddMemSpanCodeAnalyzer branch May 1, 2018 03:32
@KrzysztofCwalina
Copy link
Member

Would it be possible to write a analyzer that detects when there are multiple unnecessary calls to Memory.Span in a single method body?

@ahsonkhan
Copy link
Contributor Author

Would it be possible to write a analyzer that detects when there are multiple unnecessary calls to Memory.Span in a single method body?

I believe so, but it would be significantly more complex and require semantic tracking and analysis. Feel free to file an issue for it. I am assuming it would only highlight the issue, since offering a fix in that case seems futile.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeAnalyzer Code Analyzer for Span<T> Usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend the SpanUsage code analyzer to check for Memory<T>.Slice(...).Span

2 participants