diff options
author | Richard Biener <rguenther@suse.de> | 2014-02-12 16:01:03 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2014-02-12 16:01:03 +0000 |
commit | 3a938d756bad13643f32468815db337d3e5c1821 (patch) | |
tree | 4573e5bb36217b90a92b4e79ed9e8f3631260871 /gcc/vec.c | |
parent | ad0188be2152e741de7aa4b839a3e8b72b930dfa (diff) | |
download | gcc-3a938d756bad13643f32468815db337d3e5c1821.zip gcc-3a938d756bad13643f32468815db337d3e5c1821.tar.gz gcc-3a938d756bad13643f32468815db337d3e5c1821.tar.bz2 |
vec.c (vec_prefix::calculate_allocation): Move as inline variant to vec.h.
2014-02-12 Richard Biener <rguenther@suse.de>
* vec.c (vec_prefix::calculate_allocation): Move as
inline variant to vec.h.
(vec_prefix::calculate_allocation_1): New out-of-line version.
* vec.h (vec_prefix::calculate_allocation_1): Declare.
(vec_prefix::m_has_auto_buf): Rename to ...
(vec_prefix::m_using_auto_storage): ... this.
(vec_prefix::calculate_allocation): Inline the easy cases
and dispatch to calculate_allocation_1 which doesn't need the
prefix address.
(va_heap::reserve): Use gcc_checking_assert.
(vec<T, A, vl_embed>::embedded_init): Add argument to initialize
m_using_auto_storage.
(auto_vec): Change m_vecpfx member to a vec<T, va_heap, vl_embed>
member and adjust.
(vec<T, va_heap, vl_ptr>::reserve): Remove redundant check.
(vec<T, va_heap, vl_ptr>::release): Avoid casting.
(vec<T, va_heap, vl_ptr>::using_auto_storage): Simplify.
From-SVN: r207729
Diffstat (limited to 'gcc/vec.c')
-rw-r--r-- | gcc/vec.c | 51 |
1 files changed, 16 insertions, 35 deletions
@@ -171,46 +171,27 @@ vec_prefix::release_overhead (void) /* Calculate the number of slots to reserve a vector, making sure that - RESERVE slots are free. If EXACT grow exactly, otherwise grow - exponentially. PFX is the control data for the vector. */ + it is of at least DESIRED size by growing ALLOC exponentially. */ unsigned -vec_prefix::calculate_allocation (vec_prefix *pfx, unsigned reserve, - bool exact) +vec_prefix::calculate_allocation_1 (unsigned alloc, unsigned desired) { - unsigned alloc = 0; - unsigned num = 0; - - if (pfx) - { - alloc = pfx->m_alloc; - num = pfx->m_num; - } - else if (!reserve) - gcc_unreachable (); - /* We must have run out of room. */ - gcc_assert (alloc - num < reserve); - - if (exact) - /* Exact size. */ - alloc = num + reserve; + gcc_assert (alloc < desired); + + /* Exponential growth. */ + if (!alloc) + alloc = 4; + else if (alloc < 16) + /* Double when small. */ + alloc = alloc * 2; else - { - /* Exponential growth. */ - if (!alloc) - alloc = 4; - else if (alloc < 16) - /* Double when small. */ - alloc = alloc * 2; - else - /* Grow slower when large. */ - alloc = (alloc * 3 / 2); - - /* If this is still too small, set it to the right size. */ - if (alloc < num + reserve) - alloc = num + reserve; - } + /* Grow slower when large. */ + alloc = (alloc * 3 / 2); + + /* If this is still too small, set it to the right size. */ + if (alloc < desired) + alloc = desired; return alloc; } |