neovim/neovim — pull request #783 by aktau (2014-05-30 15:05:38+00:00)
Title: [RFC] Nul terminate pascal strings

I would like to request comments on this one.

Lowering the amounts malloc/free pairs is a good way to be nicer to the system, and in this case it saves lines of code too. We used to have:

1. libuv incoming buffer (I don't know if that's reused over different incoming messages, I hope so)
2. msgpack decoding buffer (don't know if reused either)
3. msgpack element to String (`xmemdup`)
4. String to cstr (`xstrndup`), which was doubly ineffecient because it also scans for `\0`, which it won't find (in the general case).

The last step is what I aim to eliminate. In theory, the 3rd step is the only one where I see problems for eliminating continuous allocation. But if it comes to that, we can create a small pool of strings to reuse (and when there's nothing in the pool on an incoming message, either enlarge the pool or fallback to `xmemdup`/`free`).

Ping @tarruda since this concerns the API, and @justinmk / @philix because I believe you guys have been dabbling in the same area of the code lately as well.