From f3c901af9d7c281946925cdc7c4ccdd22b1eaa1e Mon Sep 17 00:00:00 2001 From: Alexey Prokhin Date: Sat, 10 Sep 2011 13:23:47 +0400 Subject: [PATCH] Use _d_arraycatT to append an element to an array instead of reallocating the array --- gen/arrays.cpp | 9 +++++++-- gen/arrays.h | 2 ++ gen/toir.cpp | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gen/arrays.cpp b/gen/arrays.cpp index 52472686..48bf9a21 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -896,11 +896,11 @@ DSliceValue* DtoCatArrays(Type* arrayType, Expression* exp1, Expression* exp2) // TypeInfo ti args.push_back(DtoTypeInfoOf(arrayType)); // byte[] x - LLValue *val = DtoSlice(exp1->toElem(gIR)); + LLValue *val = DtoLoad(DtoSlicePtr(exp1->toElem(gIR))); val = DtoAggrPaint(val, fn->getFunctionType()->getParamType(1)); args.push_back(val); // byte[] y - val = DtoSlice(exp2->toElem(gIR)); + val = DtoLoad(DtoSlicePtr(exp2->toElem(gIR))); val = DtoAggrPaint(val, fn->getFunctionType()->getParamType(2)); args.push_back(val); } @@ -954,6 +954,9 @@ DSliceValue* DtoCatArrays(Type* type, Expression* exp1, Expression* exp2) #endif ////////////////////////////////////////////////////////////////////////////////////////// + +#if DMDV1 + DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2) { Logger::println("DtoCatArrayElement"); @@ -1015,6 +1018,8 @@ DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2) } } +#endif + ////////////////////////////////////////////////////////////////////////////////////////// DSliceValue* DtoAppendDChar(DValue* arr, Expression* exp, const char *func) diff --git a/gen/arrays.h b/gen/arrays.h index 93c955d7..231b1c52 100644 --- a/gen/arrays.h +++ b/gen/arrays.h @@ -32,7 +32,9 @@ DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, llvm::Value* newd void DtoCatAssignElement(Loc& loc, Type* type, DValue* arr, Expression* exp); DSliceValue* DtoCatAssignArray(DValue* arr, Expression* exp); DSliceValue* DtoCatArrays(Type* type, Expression* e1, Expression* e2); +#if DMDV1 DSliceValue* DtoCatArrayElement(Type* type, Expression* exp1, Expression* exp2); +#endif DSliceValue* DtoAppendDCharToString(DValue* arr, Expression* exp); DSliceValue* DtoAppendDCharToUnicodeString(DValue* arr, Expression* exp); diff --git a/gen/toir.cpp b/gen/toir.cpp index d2b517aa..cede55ce 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -2428,8 +2428,11 @@ DValue* CatExp::toElem(IRState* p) Logger::print("CatExp::toElem: %s @ %s\n", toChars(), type->toChars()); LOG_SCOPE; - bool arrNarr = e1->type->toBasetype() == e2->type->toBasetype(); +#if DMDV2 + return DtoCatArrays(type, e1, e2); +#else + bool arrNarr = e1->type->toBasetype() == e2->type->toBasetype(); // array ~ array if (arrNarr) { @@ -2441,6 +2444,7 @@ DValue* CatExp::toElem(IRState* p) { return DtoCatArrayElement(type, e1, e2); } +#endif } //////////////////////////////////////////////////////////////////////////////////////////