Skip to content

Commit

Permalink
VERY important field-access optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
bafto committed Jul 26, 2024
1 parent fe8a825 commit 642c8f1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 642c8f1

Please sign in to comment.