diff options
author | robot-contrib <[email protected]> | 2025-05-14 06:53:03 +0300 |
---|---|---|
committer | robot-contrib <[email protected]> | 2025-05-14 07:05:42 +0300 |
commit | 286dbc77293811055ff4f9303cd376eff9e50104 (patch) | |
tree | a50eea3eb2b824c7c68e15b4cc3e127731776d32 /contrib/restricted/aws/aws-c-common/source/byte_buf.c | |
parent | 0bf9db6399352012396e7791bcfd762e944b33c2 (diff) |
Update contrib/restricted/aws/aws-c-common to 0.12.2
commit_hash:fc6e67f9b12b0b888c90bb97bf2b1cbfcd74a044
Diffstat (limited to 'contrib/restricted/aws/aws-c-common/source/byte_buf.c')
-rw-r--r-- | contrib/restricted/aws/aws-c-common/source/byte_buf.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/contrib/restricted/aws/aws-c-common/source/byte_buf.c b/contrib/restricted/aws/aws-c-common/source/byte_buf.c index b815b6bfb74..da3748e812b 100644 --- a/contrib/restricted/aws/aws-c-common/source/byte_buf.c +++ b/contrib/restricted/aws/aws-c-common/source/byte_buf.c @@ -816,6 +816,25 @@ int aws_byte_buf_reserve_relative(struct aws_byte_buf *buffer, size_t additional return aws_byte_buf_reserve(buffer, requested_capacity); } +int aws_byte_buf_reserve_smart(struct aws_byte_buf *buffer, size_t requested_capacity) { + + if (requested_capacity <= buffer->capacity) { + AWS_POSTCONDITION(aws_byte_buf_is_valid(buffer)); + return AWS_OP_SUCCESS; + } + size_t double_current_capacity = aws_add_size_saturating(buffer->capacity, buffer->capacity); + size_t new_capacity = aws_max_size(requested_capacity, double_current_capacity); + return aws_byte_buf_reserve(buffer, new_capacity); +} + +int aws_byte_buf_reserve_smart_relative(struct aws_byte_buf *buffer, size_t additional_length) { + size_t requested_capacity = 0; + if (AWS_UNLIKELY(aws_add_size_checked(buffer->len, additional_length, &requested_capacity))) { + return AWS_OP_ERR; + } + return aws_byte_buf_reserve_smart(buffer, requested_capacity); +} + struct aws_byte_cursor aws_byte_cursor_right_trim_pred( const struct aws_byte_cursor *source, aws_byte_predicate_fn *predicate) { |