Skip to content

Conversation

Lukasa
Copy link
Contributor

@Lukasa Lukasa commented Dec 12, 2022

Motivation:

withVeryUnsafeBytes has a reference to self that it is using. This necessarily triggers a copy when we subsequently use self inside the block. The effect of that copy is an extra retain/release pair, and a call to beginAccess, that we simply don't need.

Modifications:

Replace the call to _setBytesAssumingUniqueBufferAccess with a manually inlined equivalent.

Result:

Avoids the extra copy of self, removes a retain/release and a beginAccess.

Motivation:

withVeryUnsafeBytes has a reference to `self` that it is using. This
necessarily triggers a copy when we subsequently use `self` inside the
block. The effect of that copy is an extra retain/release pair, and a
call to beginAccess, that we simply don't need.

Modifications:

Replace the call to `_setBytesAssumingUniqueBufferAccess` with a
manually inlined equivalent.

Result:

Avoids the extra copy of `self`, removes a retain/release and a
beginAccess.
@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Dec 12, 2022
Copy link
Member

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

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

Nice one!

@Lukasa Lukasa merged commit abf2b35 into apple:main Dec 12, 2022
@Lukasa Lukasa deleted the cb-remove-implicit-copy branch December 12, 2022 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants