MaxGraey / as-string-sink

An efficient dynamically sized string buffer (aka String Builder) for AssemblyScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

make ensureCapacity be public

yjhmelody opened this issue · comments

commented

pub fn reserve(&mut self, additional: usize)
Ensures that this String’s capacity is at least additional bytes larger than its length.
The capacity may be increased by more than additional bytes if it chooses, to prevent frequent reallocations.
If you do not want this “at least” behavior, see the reserve_exact method.

It's the rust string api.

As I said before, if I have a set of strings, I can first calculate the total length and then write it, so that I only need to reallocate the memory once. This theoretically has a performance increase of 1 times.

In addition, other rust string APIs are also useful.