| 1 |
/* This may look like C code, but it is really -*- C++ -*- */ |
| 2 |
|
| 3 |
/* Array-list container. |
| 4 |
|
| 5 |
Copyright (C) 2025 Free Software Foundation, Inc. |
| 6 |
Written by Bruno Haible <[email protected]>. |
| 7 |
|
| 8 |
This file is part of GNU GPERF. |
| 9 |
|
| 10 |
This program is free software: you can redistribute it and/or modify |
| 11 |
it under the terms of the GNU General Public License as published by |
| 12 |
the Free Software Foundation; either version 3 of the License, or |
| 13 |
(at your option) any later version. |
| 14 |
|
| 15 |
This program is distributed in the hope that it will be useful, |
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
GNU General Public License for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License |
| 21 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 22 |
|
| 23 |
#include <config.h> |
| 24 |
|
| 25 |
/* Specification. */ |
| 26 |
#include "arraylist.h" |
| 27 |
|
| 28 |
#include <new> |
| 29 |
|
| 30 |
void ArrayListRepresentation::ensure_capacity (size_t n, size_t size_of_T) |
| 31 |
{ |
| 32 |
size_t new_max = 2 * _nitems_max + 1; |
| 33 |
if (new_max < n) |
| 34 |
new_max = n; |
| 35 |
void *new_item = realloc (_item, new_max * size_of_T); |
| 36 |
if (new_item == NULL) |
| 37 |
throw std::bad_alloc(); |
| 38 |
/* The realloc() call has moved the elements from the old storage to the |
| 39 |
new storage. The old storage is thus now considered uninitialized. */ |
| 40 |
_item = new_item; |
| 41 |
_nitems_max = new_max; |
| 42 |
} |