Skip to content

Commit

Permalink
Merge pull request #8364 from haberman/ruby-memory-footprint
Browse files Browse the repository at this point in the history
[Ruby] Fixed quadratic memory usage when appending to arrays.
  • Loading branch information
haberman committed Mar 2, 2021
2 parents 85e5204 + 88243e4 commit 069f989
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions ruby/ext/google/protobuf_c/ruby-upb.c
Expand Up @@ -6663,10 +6663,9 @@ void upb_array_set(upb_array *arr, size_t i, upb_msgval val) {
}

bool upb_array_append(upb_array *arr, upb_msgval val, upb_arena *arena) {
if (!_upb_array_realloc(arr, arr->len + 1, arena)) {
if (!upb_array_resize(arr, arr->len + 1, arena)) {
return false;
}
arr->len++;
upb_array_set(arr, arr->len - 1, val);
return true;
}
Expand Down

0 comments on commit 069f989

Please sign in to comment.