From a5c9f2b736f0d152289628e2ff14d1888b512244 Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Sun, 14 May 2017 00:38:35 +0000 Subject: [PATCH] allow constructing a auto_vec with a preallocation, and a possibly larger actual allocation size This allows us to set the capacity of the vector when we construct it, and still use a stack buffer when the size is small enough. gcc/ChangeLog: 2017-05-13 Trevor Saunders * genrecog.c (int_set::int_set): Explicitly construct our auto_vec base class. * vec.h (auto_vec::auto_vec): New constructor. From-SVN: r248019 --- gcc/ChangeLog | 6 ++++++ gcc/genrecog.c | 8 +++++--- gcc/vec.h | 12 ++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9cc3d51..1f0c05a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,11 @@ 2017-05-13 Trevor Saunders + * genrecog.c (int_set::int_set): Explicitly construct our + auto_vec base class. + * vec.h (auto_vec::auto_vec): New constructor. + +2017-05-13 Trevor Saunders + * bitmap.h (class auto_bitmap): New constructor taking bitmap_obstack * argument. diff --git a/gcc/genrecog.c b/gcc/genrecog.c index 6a9e610..b69043f 100644 --- a/gcc/genrecog.c +++ b/gcc/genrecog.c @@ -1407,14 +1407,16 @@ struct int_set : public auto_vec iterator end (); }; -int_set::int_set () {} +int_set::int_set () : auto_vec () {} -int_set::int_set (uint64_t label) +int_set::int_set (uint64_t label) : + auto_vec () { safe_push (label); } -int_set::int_set (const int_set &other) +int_set::int_set (const int_set &other) : + auto_vec () { safe_splice (other); } diff --git a/gcc/vec.h b/gcc/vec.h index fee4616..914f89c 100644 --- a/gcc/vec.h +++ b/gcc/vec.h @@ -1272,6 +1272,18 @@ public: this->m_vec = &m_auto; } + auto_vec (size_t s) + { + if (s > N) + { + this->create (s); + return; + } + + m_auto.embedded_init (MAX (N, 2), 0, 1); + this->m_vec = &m_auto; + } + ~auto_vec () { this->release (); -- 2.7.4