minor optimisation (do not have to branch on NO_TRIANGLE | FIRST | SECOND twice in update function; update function was branching on this itself, and call to 'getTriangleStageVector' was branching again which was redundant)

This commit is contained in:
2024-07-31 21:21:45 +01:00
parent 6e6de41889
commit cf38d160d5
2 changed files with 51 additions and 44 deletions

Binary file not shown.

View File

@@ -93,10 +93,7 @@ struct
(0, Real32.fromInt mouseX, Real32.fromInt mouseY, r, g, b) (0, Real32.fromInt mouseX, Real32.fromInt mouseY, r, g, b)
end end
fun getTriangleStageVector (model: app_type, drawVec) = fun getFirstTriangleStageVector (x1, y1, drawVec) =
case #triangleStage model of
NO_TRIANGLE => drawVec
| FIRST {x1, y1} =>
let let
val halfWidth = Real32.fromInt (Constants.windowWidth div 2) val halfWidth = Real32.fromInt (Constants.windowWidth div 2)
val halfHeight = Real32.fromInt (Constants.windowHeight div 2) val halfHeight = Real32.fromInt (Constants.windowHeight div 2)
@@ -113,7 +110,8 @@ struct
in in
Vector.concat [firstVec, drawVec] Vector.concat [firstVec, drawVec]
end end
| SECOND {x1, y1, x2, y2} =>
fun getSecondTriangleStageVector (x1, y1, x2, y2, drawVec) =
let let
val halfWidth = Real32.fromInt (Constants.windowWidth div 2) val halfWidth = Real32.fromInt (Constants.windowWidth div 2)
val halfHeight = Real32.fromInt (Constants.windowHeight div 2) val halfHeight = Real32.fromInt (Constants.windowHeight div 2)
@@ -141,6 +139,14 @@ struct
Vector.concat [firstVec, secVec, drawVec] Vector.concat [firstVec, secVec, drawVec]
end end
fun getTriangleStageVector (model: app_type, drawVec) =
case #triangleStage model of
NO_TRIANGLE => drawVec
| FIRST {x1, y1} =>
getFirstTriangleStageVector (x1, y1, drawVec)
| SECOND {x1, y1, x2, y2} =>
getSecondTriangleStageVector (x1, y1, x2, y2, drawVec)
fun update (model, mouseX, mouseY, inputMsg) = fun update (model, mouseX, mouseY, inputMsg) =
let let
open DrawMessage open DrawMessage
@@ -183,7 +189,7 @@ struct
end end
| FIRST {x1, y1} => | FIRST {x1, y1} =>
let let
val drawVec = getTriangleStageVector (model, buttonVec) val drawVec = getFirstTriangleStageVector (x1, y1, buttonVec)
val drawMsg = DRAW_BUTTON drawVec val drawMsg = DRAW_BUTTON drawVec
val newTriangleStage = SECOND val newTriangleStage = SECOND
@@ -195,7 +201,8 @@ struct
end end
| SECOND {x1, y1, x2, y2} => | SECOND {x1, y1, x2, y2} =>
let let
val drawVec = getTriangleStageVector (model, buttonVec) val drawVec =
getSecondTriangleStageVector (x1, y1, x2, y2, buttonVec)
val drawMsg = DRAW_BUTTON drawVec val drawMsg = DRAW_BUTTON drawVec
val newTriangleStage = NO_TRIANGLE val newTriangleStage = NO_TRIANGLE