Skip to content

🌱 avoid unnecessary []byte to string conversions #4539

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

spencerschrock
Copy link
Member

What kind of change does this PR introduce?

refactor

What is the current behavior?

We cast []byte to string, so we can use strings.NewReader. We pass this to something that wants an io.Reader, but bytes.NewReader exists and also satisfies io.Reader

What is the new behavior (if this is a feature change)?**

We avoid unnecessary type conversions, saving some time and making less garbage. I didn't profile the improvement, but it bugs me every time I see it.

  • Tests for the changes have been added (for bug fixes/features)

Which issue(s) this PR fixes

NONE

Special notes for your reviewer

Does this PR introduce a user-facing change?

For user-facing changes, please add a concise, human-readable release note to
the release-note

(In particular, describe what changes users might need to make in their
application as a result of this pull request.)

NONE

we just need an io.Reader, so either strings or bytes will do.

Signed-off-by: Spencer Schrock <sschrock@google.com>
regexes have a byte equivalent, and we can avoid making a string copy
unless we actually need it for the snippet.

Signed-off-by: Spencer Schrock <sschrock@google.com>
Copy link

codecov bot commented Feb 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.19%. Comparing base (353ed60) to head (510553d).
Report is 127 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4539      +/-   ##
==========================================
+ Coverage   66.80%   68.19%   +1.39%     
==========================================
  Files         230      247      +17     
  Lines       16602    18635    +2033     
==========================================
+ Hits        11091    12709    +1618     
- Misses       4808     5083     +275     
- Partials      703      843     +140     
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

github-actions bot commented Mar 8, 2025

This pull request has been marked stale because it has been open for 10 days with no activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants