]> Cypherpunks repositories - gostls13.git/commitdiff
image/draw: optimize drawFillSrc.
authorNigel Tao <nigeltao@golang.org>
Fri, 27 Feb 2015 10:43:53 +0000 (21:43 +1100)
committerNigel Tao <nigeltao@golang.org>
Sat, 28 Feb 2015 01:26:54 +0000 (01:26 +0000)
benchmark                    old ns/op     new ns/op     delta
BenchmarkFillSrc             46781         46000         -1.67%

Change-Id: I0ab25d42d5763f1a0fe5a67ee00b83f0aa55f1f6
Reviewed-on: https://go-review.googlesource.com/6235
Reviewed-by: Rob Pike <r@golang.org>
src/image/draw/draw.go

index 7f9127168e666f4f4b4ff6b657b40801bfdbf1c9..649634114449c56ad1e810d6e60a5eb0a5a8f6ff 100644 (file)
@@ -245,16 +245,20 @@ func drawFillOver(dst *image.RGBA, r image.Rectangle, src *image.Uniform) {
 
 func drawFillSrc(dst *image.RGBA, r image.Rectangle, src *image.Uniform) {
        sr, sg, sb, sa := src.RGBA()
+       sr8 := uint8(sr >> 8)
+       sg8 := uint8(sg >> 8)
+       sb8 := uint8(sb >> 8)
+       sa8 := uint8(sa >> 8)
        // The built-in copy function is faster than a straightforward for loop to fill the destination with
        // the color, but copy requires a slice source. We therefore use a for loop to fill the first row, and
        // then use the first row as the slice source for the remaining rows.
        i0 := dst.PixOffset(r.Min.X, r.Min.Y)
        i1 := i0 + r.Dx()*4
        for i := i0; i < i1; i += 4 {
-               dst.Pix[i+0] = uint8(sr >> 8)
-               dst.Pix[i+1] = uint8(sg >> 8)
-               dst.Pix[i+2] = uint8(sb >> 8)
-               dst.Pix[i+3] = uint8(sa >> 8)
+               dst.Pix[i+0] = sr8
+               dst.Pix[i+1] = sg8
+               dst.Pix[i+2] = sb8
+               dst.Pix[i+3] = sa8
        }
        firstRow := dst.Pix[i0:i1]
        for y := r.Min.Y + 1; y < r.Max.Y; y++ {