chris-zen / coremidi

CoreMIDI library for Rust
https://chris-zen.github.io/coremidi/coremidi/
MIT License
75 stars 20 forks source link

Allow empty PacketBuffer and initial control of the capacity #12

Closed chris-zen closed 5 years ago

chris-zen commented 5 years ago

This PR gives a PacketBuffer the capability to be empty at any moment, as well as to be created with an specific capacity from the beginning. It also makes some minor refactoring.

PacketBuffer keeps backward compatibility, but introduces new methods:

@Boddlnagg and @raphlinus I'm pinging you in case you are interested in reviewing.

Boddlnagg commented 5 years ago

FWIW, I had a quick look at the changes and except for the one comment I can't see anything blatantly wrong. I remember that I wrote the code in such a way that a PacketBuffer cannot be empty (and I had a comment in there to indicate this), but it looks like your changes touch all the relevant places where this would make a difference.

chris-zen commented 5 years ago

@Boddlnagg I appreciate you had a look. I am wondering if this would be good for midir. The main purpose for me was to allow allocating enough memory for the buffer once at the beginning, and then re-use it without more allocations the rest of the time.

chris-zen commented 5 years ago

@Boddlnagg FYI I have been using this code for quite some time now and I didn't have any trouble. I'm going to merge and release.