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