bytes_ostream is an incremental builder for a discontiguous byte container. managed_bytes is a non-incremental (size must be known up front) byte container, that is also compatible with LSA. So far, conversion between them involves copying. This is unfortunate, since query_result is generated as a bytes_ostream, but is later converted to managed_bytes (today, this is done in cql3::expr::get_non_pk_values() and compound_view_wrapper::explode(). If the two types could be made compatible, we could use managed_bytes_view instead of creating new objects and avoid a copy. It's also nicer to have one less vocabulary type. This patch makes bytes_ostream use managed_bytes' internal representation (blob_storage instead of bytes_ostream::chunk) and provides a conversion to managed_bytes. All bytes_ostream users are left in place, but the goal is to make bytes_ostream a write-only type with the only observer a conversion to managed_bytes. It turns out to be relatively simple. The internal representations were already similar. I made blob_storage::ref_type self-initializing to reduce churn (good practice anyway) and added a private constructor to managed_bytes for the conversion. Note that bytes_ostream can only be used to construct a non-LSA managed_bytes, but LSA uses of managed_bytes are very strictly controlled (the entry points to memtable and cache) so that's not a problem. A unit test is added. Closes #10986
16 KiB
16 KiB