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

Simplify and optimize RemoveMagicPrefixLine. #36

Merged
merged 1 commit into from
May 17, 2017
Merged

Simplify and optimize RemoveMagicPrefixLine. #36

merged 1 commit into from
May 17, 2017

Conversation

dmitshur
Copy link
Collaborator

This PR implements a suggestion from https://github.com/andygrunwald/go-gerrit/pull/10/files#r116843309.

If body has ")]}'\n" prefix, there's no need to use bytes.IndexByte to find the first '\n' character, it's known to be at index 4 because bytes.HasPrefix(body, []byte(")]}'\n")) was true.

Since this is called often, it's probably a good idea to factor out []byte(")]}'\n") into a package scope variable, instead of potentially allocating once per RemoveMagicPrefixLine call.

If body has ")]}'\n" prefix, there's no need to use bytes.IndexByte to
find the first '\n' character, it's known to be at index 4 because
bytes.HasPrefix(body, []byte(")]}'\n")) was true.

Since this is called often, it's probably a good idea to factor out
[]byte(")]}'\n") into a package scope variable, instead of potentially
allocating once per RemoveMagicPrefixLine call.
@codecov-io
Copy link

codecov-io commented May 16, 2017

Codecov Report

Merging #36 into master will decrease coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #36     +/-   ##
=========================================
- Coverage   17.55%   17.45%   -0.1%     
=========================================
  Files          20       20             
  Lines        1726     1724      -2     
=========================================
- Hits          303      301      -2     
  Misses       1393     1393             
  Partials       30       30
Impacted Files Coverage Δ
gerrit.go 82.84% <100%> (-0.17%) ⬇️

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 978d5a3...09cddf5. Read the comment docs.

@dmitshur
Copy link
Collaborator Author

Thanks for reviewing. Feel free to merge at your convenience; I can't do it myself.

@andygrunwald andygrunwald merged commit 73dc271 into andygrunwald:master May 17, 2017
@andygrunwald
Copy link
Owner

Thank you @shurcooL :)

@dmitshur dmitshur deleted the patch-1 branch May 17, 2017 19:01
@opalmer opalmer modified the milestone: 0.3.0 Jun 5, 2017
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.

4 participants