Skip to content

Add copyBytesFrom#30

Merged
yassernasc merged 4 commits intomainfrom
copyBytesFrom
Mar 3, 2026
Merged

Add copyBytesFrom#30
yassernasc merged 4 commits intomainfrom
copyBytesFrom

Conversation

@yassernasc yassernasc requested a review from a team March 2, 2026 19:38
@yassernasc yassernasc requested review from a team and kasperisager March 2, 2026 20:17
test/basic.js Outdated
test('copyBytesFrom', (t) => {
const u16 = new Uint16Array([0, 0xffff])

Buffer.copyBytesFrom(u16)[0] = 42

Choose a reason for hiding this comment

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

What is the impact of this?

Copy link
Contributor

Choose a reason for hiding this comment

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

To verify that a copy is actually made. If the function didn't copy the input buffer the assertions below would fail.

index.js Outdated
if (offset || length) {
const sliceEnd = length ? (length += offset) : view.length

view = view.slice(offset, sliceEnd)
Copy link
Contributor

Choose a reason for hiding this comment

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

slice() creates a copy as well so this will double copy the memory.

Copy link
Contributor

@kasperisager kasperisager left a comment

Choose a reason for hiding this comment

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

Let's add some additional tests as well. Looks good now otherwise!

@yassernasc yassernasc requested a review from kasperisager March 3, 2026 13:18
@yassernasc yassernasc merged commit ef3f38d into main Mar 3, 2026
3 checks passed
@yassernasc yassernasc deleted the copyBytesFrom branch March 3, 2026 13:30
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.

3 participants