Skip to content

Change some memcpy to memmove#6616

Merged
erikcorry merged 1 commit into
mainfrom
erikcorry/memmove
Apr 20, 2026
Merged

Change some memcpy to memmove#6616
erikcorry merged 1 commit into
mainfrom
erikcorry/memmove

Conversation

@erikcorry

Copy link
Copy Markdown
Contributor

The buffer.c++ ones can probably overlap, while the identity-transform-stream.c++ ones are just being
cautious.

The buffer.c++ ones can probably overlap, while the
identity-transform-stream.c++ ones are just being
cautious.
@erikcorry erikcorry requested review from a team as code owners April 20, 2026 11:48
@ask-bonk

ask-bonk Bot commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Good — all memcpy calls in both files have been converted. The changes are complete within these files.

Let me do a final review of the complete diff to make sure I haven't missed anything:

  1. buffer.c++: Three memcpymemmove changes, all in the decode() function, all involving copies into the incomplete character buffer. The overlap justification is real — data can point into the kNativeDecoder buffer (which also contains the incomplete character buffer) when a user passes decoder.lastChar as input to decoder.write(). The lastChar getter returns a subarray view of the state buffer at [kIncompleteCharactersStart, kIncompleteCharactersEnd), and getIncompleteCharacterBuffer(statePtr) returns state.begin() + kIncompleteCharactersStart — the exact same memory region.

  2. identity-transform-stream.c++: Four memcpymemmove changes. The read buffer and write buffer come from separate callers (one from readHelper, one from writeHelper), so they can't overlap. This is purely defensive. No harm, slight theoretical overhead (negligible for these sizes).

Both changes are safe, correct, and well-commented. No backward compatibility issues, no security concerns, no missing compat flags needed. The buffer.c++ changes fix a real (if unlikely) UB scenario. The identity-transform-stream.c++ changes are harmless defensive hardening.

LGTM

github run

@erikcorry erikcorry enabled auto-merge April 20, 2026 11:56
@codspeed-hq

codspeed-hq Bot commented Apr 20, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 28.38%

❌ 1 regressed benchmark
✅ 71 untouched benchmarks
⏩ 129 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
simpleStringBody[Response] 19.3 µs 26.9 µs -28.38%

Comparing erikcorry/memmove (d7413cc) with main (4e71c55)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@erikcorry erikcorry merged commit 16908c9 into main Apr 20, 2026
21 checks passed
@erikcorry erikcorry deleted the erikcorry/memmove branch April 20, 2026 12:27
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.

2 participants