Fixed quadratic memory use in array append for PHP and Ruby.

pull/8379/head
Joshua Haberman 4 years ago
parent fd8aabf32d
commit 9b5e357df5
  1. 3
      php/ext/google/protobuf/php-upb.c
  2. 3
      ruby/ext/google/protobuf_c/ruby-upb.c

@ -7047,10 +7047,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;
}

@ -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;
}

Loading…
Cancel
Save