-
Type:
Improvement
-
Resolution: Won't Fix
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
I request that the following functions be exposed as a public api:
bool bson_reserve(bson_t *bson, uint32_t size);
uint32_t bson_capacity(bson_t *bson);
bson_reserve currently exists as the hidden function _bson_grow.
bson_capacity could be implemented like his:
uint32_t bson_capacity(bson_t *bson) {
if (bson->flags & BSON_FLAG_INLINE) {
return ((bson_impl_inline_t *) bson)->len;
} else {
return ((bson_impl_alloc_t *) bson)->len;
}
}
These functions would be useful in cases where the developer is dynamically building a bson document – using the bson_append_*() functions – but already has a high degree of knowledge about the size of the resulting document (or just makes a guess and wants to remove the amount of calls to realloc() drastically).