From af6bda48c33e81861ec2040fc0dd9743f3ed00c0 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 27 Sep 2019 03:28:07 +0900 Subject: [PATCH] Reduce division operators It looks like runtime.wasmDiv takes account for a big part at CPU usages with examples/sprites. --- internal/graphicscommand/command.go | 3 ++- internal/shareable/image.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index 9df0439fa..b673bc7e2 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -192,7 +192,8 @@ func (q *commandQueue) Flush() { const dstAdjustmentFactor = 1.0 / 256.0 const texelAdjustmentFactor = 1.0 / 512.0 - for i := 0; i < q.nvertices/graphics.VertexFloatNum; i++ { + n := q.nvertices / graphics.VertexFloatNum + for i := 0; i < n; i++ { s := q.srcSizes[i] // Convert pixels to texels. diff --git a/internal/shareable/image.go b/internal/shareable/image.go index 61d4c4591..bffbe190e 100644 --- a/internal/shareable/image.go +++ b/internal/shareable/image.go @@ -303,7 +303,8 @@ func (i *Image) DrawTriangles(img *Image, vertices []float32, indices []uint16, ox, oy, _, _ := img.region() oxf, oyf := float32(ox), float32(oy) - for i := 0; i < len(vertices)/graphics.VertexFloatNum; i++ { + n := len(vertices) / graphics.VertexFloatNum + for i := 0; i < n; i++ { vertices[i*graphics.VertexFloatNum+2] += oxf vertices[i*graphics.VertexFloatNum+3] += oyf vertices[i*graphics.VertexFloatNum+4] += oxf