From 642c8f160c6e65c94a79def071e4587e9f094b37 Mon Sep 17 00:00:00 2001 From: Hendrik Ziegler Date: Fri, 26 Jul 2024 09:53:24 +0200 Subject: [PATCH] VERY important field-access optimization --- src/compiler/compiler.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/compiler.go b/src/compiler/compiler.go index f8b8be3b..8392e73b 100644 --- a/src/compiler/compiler.go +++ b/src/compiler/compiler.go @@ -912,13 +912,15 @@ func (c *compiler) VisitBinaryExpr(e *ast.BinaryExpr) ast.VisitResult { c.latestReturnType = c.ddpbooltyp return ast.VisitRecurse case ast.BIN_FIELD_ACCESS: - rhs, rhsTyp, _ := c.evaluate(e.Rhs) + rhs, rhsTyp, rhsIsTemp := c.evaluate(e.Rhs) if structType, isStruct := rhsTyp.(*ddpIrStructType); isStruct { fieldIndex := getFieldIndex(e.Lhs.Token().Literal, structType) fieldType := structType.fieldIrTypes[fieldIndex] fieldPtr := c.indexStruct(rhs, fieldIndex) if fieldType.IsPrimitive() { c.latestReturn = c.cbb.NewLoad(fieldType.IrType(), fieldPtr) + } else if !rhsIsTemp { + c.latestReturn, c.latestIsTemp = fieldPtr, false } else { dest := c.NewAlloca(fieldType.IrType()) c.deepCopyInto(dest, fieldPtr, fieldType)