]> git.ipfire.org Git - thirdparty/gcc.git/commit
gccrs: prealloc the initilizer vector
authorPhilip Herron <herron.philip@googlemail.com>
Thu, 17 Apr 2025 15:19:35 +0000 (16:19 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 28 Apr 2025 14:18:55 +0000 (16:18 +0200)
commite186cea1c25456cfd8006311f60363913ba803c7
treea9fdd551fc94a9565330df6404843ca846162406
parentefb94eb85d2382c795fa7b69feeb5425590519dc
gccrs: prealloc the initilizer vector

There are two cases when initilizing an array, this is the
const context which means we need to build the array ctor,
which means using lots of memory, its super inefficient
because we are using a big wrapper over the GCC internals here
but preallocating the vectors here causes a:

  terminate called after throwing an instance of 'std::bad_alloc'

So this is a handy error condition to rely on for this senario.

Fixes Rust-GCC#3713
Fixes Rust-GCC#3727

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::array_copied_expr): prealloc the vector

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/backend/rust-compile-expr.cc