Skip to content

Conversation

@Lukasa
Copy link
Contributor

@Lukasa Lukasa commented Jun 29, 2023

Motivation:

In two different places in this module we "reserve" space by moving the writer index forward. This isn't the correct way to do that, and it's a bit of a needless performance
optimization. Instead, just write a zero in that location and come back to it.

Modifications:

  • Replace unmotivated writer index move with a write.
  • Add tests.

Result:

Fewer crashes

Motivation:

In two different places in this module we "reserve" space by
moving the writer index forward. This isn't the correct way to
do that, and it's a bit of a needless performance
optimization. Instead, just write a zero in that location and
come back to it.

Modifications:

- Replace unmotivated writer index move with a write.
- Add tests.

Result:

Fewer crashes
@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Jun 29, 2023

/// payload
self.moveWriterIndex(forwardBy: 5)
self.writeMultipleIntegers(UInt32(0), UInt8(0))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: there's also writeRepeatedBytes (or something similar to that) which might be a teeny tiny bit more obvious.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I actually thought this one made more sense given the packet format laid out above.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense, I was looking at it as the diff from “move the writer by 5”.

@Lukasa Lukasa merged commit db57f32 into apple:main Jun 29, 2023
@Lukasa Lukasa deleted the cb-correctly-resize-buffer branch June 29, 2023 07:33
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