diff options
author | Robert Kausch <robert.kausch@freac.org> | 2019-03-02 18:06:46 +0100 |
---|---|---|
committer | Erik de Castro Lopo <erikd@mega-nerd.com> | 2019-03-08 07:00:12 +1100 |
commit | b936e398e2c49c1b766db9aefbd24e3563b4a751 (patch) | |
tree | fdeb7a6bdc8dcabb240f74ac09fc2f2d0ba65515 /src | |
parent | cc15b7427a9d4c94233dcad24cd8ed4c43f6c261 (diff) | |
download | flac-b936e398e2c49c1b766db9aefbd24e3563b4a751.tar.gz |
Speed up FLAC__bitwriter_write_byte_block (metadata writing)
Diffstat (limited to 'src')
-rw-r--r-- | src/libFLAC/bitwriter.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/libFLAC/bitwriter.c b/src/libFLAC/bitwriter.c index bfe79b02..6e86585b 100644 --- a/src/libFLAC/bitwriter.c +++ b/src/libFLAC/bitwriter.c @@ -410,6 +410,10 @@ inline FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FL { uint32_t i; + /* grow capacity upfront to prevent constant reallocation during writes */ + if(bw->capacity <= bw->words + nvals / (FLAC__BITS_PER_WORD / 8) + 1 && !bitwriter_grow_(bw, nvals * 8)) + return false; + /* this could be faster but currently we don't need it to be since it's only used for writing metadata */ for(i = 0; i < nvals; i++) { if(!FLAC__bitwriter_write_raw_uint32_nocheck(bw, (FLAC__uint32)(vals[i]), 8)) |