Skip to content

[yamlfmt] Change FileDiff to use bytes by default#295

Merged
braydonk merged 1 commit intogoogle:mainfrom
braydonk:format_diff_bytes
Dec 2, 2025
Merged

[yamlfmt] Change FileDiff to use bytes by default#295
braydonk merged 1 commit intogoogle:mainfrom
braydonk:format_diff_bytes

Conversation

@braydonk
Copy link
Copy Markdown
Collaborator

@braydonk braydonk commented Dec 2, 2025

Fixes #292

This PR adjusts FileDiff.Original and FileDiff.Formatted to use byte slice by default, and only do a string cast when requested. This path allows for scenarios where no diff comparison is done to avoid extra allocations.

While it's fairly inconsequential, I also changed some spots where I printed a casted byte array to use Printf instead as it saves an allocation. Those were not hot paths (run once at the end) but I decided to change them anyway since I'm here anyway.

This PR adjusts `FileDiff.Original` and `FileDiff.Formatted` to use byte
slice by default, and only do a string cast when requested. This path
allows for scenarios where no diff comparison is done to avoid extra
allocations.

While it's fairly inconsequential, I also changed some spots where I
printed a casted byte array to use `Printf` instead as it saves an
allocation. Those were not hot paths (run once at the end) but I decided
to change them anyway since I'm here anyway.
@braydonk braydonk merged commit 17d6d33 into google:main Dec 2, 2025
5 checks passed
@d-enk
Copy link
Copy Markdown

d-enk commented Dec 2, 2025

- fmt.Print(string(out))
+ os.Stdout.Write(out)

It was better (no copy)

@braydonk
Copy link
Copy Markdown
Collaborator Author

braydonk commented Dec 2, 2025

You can submit a PR for that if you'd like. I wasn't going to bother anyway since those are outputs run at the end of the program one time.

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.

Reduce content copying

2 participants