Skip to content

Commit ea298bd

Browse files
ysoldakdeadprogram
authored andcommitted
alloc: use pre-allocated error
1 parent dbe1e66 commit ea298bd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tinydraw.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"tinygo.org/x/drivers"
99
)
1010

11+
var errEmptyRectangle = errors.New("tinydraw: empty rectangle")
12+
1113
// Line draws a line between two points
1214
func Line(display drivers.Displayer, x0 int16, y0 int16, x1 int16, y1 int16, color color.RGBA) {
1315
if x0 == x1 {
@@ -66,7 +68,7 @@ func Line(display drivers.Displayer, x0 int16, y0 int16, x1 int16, y1 int16, col
6668
// Rectangle draws a rectangle given a point, width and height
6769
func Rectangle(display drivers.Displayer, x int16, y int16, w int16, h int16, color color.RGBA) error {
6870
if w <= 0 || h <= 0 {
69-
return errors.New("empty rectangle")
71+
return errEmptyRectangle
7072
}
7173
Line(display, x, y, x+w-1, y, color)
7274
Line(display, x, y, x, y+h-1, color)
@@ -78,7 +80,7 @@ func Rectangle(display drivers.Displayer, x int16, y int16, w int16, h int16, co
7880
// FilledRectangle draws a filled rectangle given a point, width and height
7981
func FilledRectangle(display drivers.Displayer, x int16, y int16, w int16, h int16, color color.RGBA) error {
8082
if w <= 0 || h <= 0 {
81-
return errors.New("empty rectangle")
83+
return errEmptyRectangle
8284
}
8385
for i := x; i < x+w; i++ {
8486
Line(display, i, y, i, y+h-1, color)

0 commit comments

Comments
 (0)