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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Efficient ToBase64String #1153

Merged
merged 6 commits into from Mar 25, 2020
Merged

Conversation

JimBobSquarePants
Copy link
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 馃懏.
  • I have provided test coverage for my change (where applicable)

Description

Prevents allocation of an array when saving to a Base64 encoded string.

@codecov
Copy link

codecov bot commented Mar 25, 2020

Codecov Report

Merging #1153 into master will decrease coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1153      +/-   ##
==========================================
- Coverage   82.29%   82.23%   -0.06%     
==========================================
  Files         680      680              
  Lines       29301    29301              
  Branches     3279     3279              
==========================================
- Hits        24112    24096      -16     
- Misses       4500     4516      +16     
  Partials      689      689              
Flag Coverage 螖
#unittests 82.23% <100.00%> (-0.06%) 猬囷笍
Impacted Files Coverage 螖
src/ImageSharp/ImageExtensions.cs 68.42% <100.00%> (酶)
...sing/Extensions/Convolution/BokehBlurExtensions.cs 25.00% <0.00%> (-50.00%) 猬囷笍
...s/ArrayPoolMemoryAllocator.CommonFactoryMethods.cs 77.77% <0.00%> (-11.12%) 猬囷笍
...mats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs 91.71% <0.00%> (-4.15%) 猬囷笍

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update 26b89ed...3dd4951. Read the comment docs.

Comment on lines 130 to 131
buffer.AsSpan().CopyTo(sharedBuffer);
return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(sharedBuffer)}";
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to operate on a copy instead of ArraySegment<byte>.Array?

ToBase64String(array, offset, length) seems to be available on all platforms. I don't even think we need the BASE64SPAN define.

Copy link
Member Author

Choose a reason for hiding this comment

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

Haha yes, much better. Will update.

Copy link
Member

@antonfirsov antonfirsov left a comment

Choose a reason for hiding this comment

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

Looks good now!

@JimBobSquarePants JimBobSquarePants merged commit 6682529 into master Mar 25, 2020
@JimBobSquarePants JimBobSquarePants deleted the js/more-efficient-base64 branch March 25, 2020 21:28
@JimBobSquarePants JimBobSquarePants added this to the 1.0.0-rc1 milestone Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants