From eb3261f93c4fa029dc4a8a17ab15c21d45ee9599 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Wed, 9 Oct 2013 01:05:46 +0200 Subject: [PATCH] Do not GC-allocate temporary for static array initialization. --- gen/toir.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gen/toir.cpp b/gen/toir.cpp index f229d314..58b3c792 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -508,6 +508,26 @@ DValue* AssignExp::toElem(IRState* p) } } + if (e1->op == TOKslice) + { + // Check if this is an initialization of a static array with an array + // literal that the frontend has foolishly rewritten into an + // assignment of a dynamic array literal to a slice. + Logger::println("performing static array literal assignment"); + SliceExp * const se = static_cast(e1); + Type * const t2 = e2->type->toBasetype(); + Type * const ta = se->e1->type->toBasetype(); + + if (se->lwr == NULL && ta->ty == Tsarray && + e2->op == TOKarrayliteral && + t2->nextOf()->mutableOf()->implicitConvTo(ta->nextOf())) + { + ArrayLiteralExp * const ale = static_cast(e2); + initializeArrayLiteral(p, ale, se->e1->toElem(p)->getLVal()); + return e1->toElem(p); + } + } + DValue* l = e1->toElem(p); DValue* r = e2->toElem(p);