From 6874fff0f62475724071e2ff9b7c9b67ae48f5a9 Mon Sep 17 00:00:00 2001
From: faiface <faiface@ksp.sk>
Date: Wed, 8 Mar 2017 00:43:01 +0100
Subject: [PATCH] slightly optimize Sprite.SetPicture

---
 graphics.go | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/graphics.go b/graphics.go
index 79997f2..9468d16 100644
--- a/graphics.go
+++ b/graphics.go
@@ -20,6 +20,13 @@ func NewSprite(pic Picture) *Sprite {
 // SetPicture changes the Sprite's Picture. The new Picture may have a different size, everything
 // works.
 func (s *Sprite) SetPicture(pic Picture) {
+	oldPic := s.d.Picture
+	s.d.Picture = pic
+
+	if oldPic.Bounds() == pic.Bounds() {
+		return
+	}
+
 	var (
 		bounds     = pic.Bounds()
 		center     = bounds.Center()
@@ -41,7 +48,6 @@ func (s *Sprite) SetPicture(pic Picture) {
 	}
 
 	s.d.Dirty()
-	s.d.Picture = pic
 }
 
 // Picture returns the current Sprite's Picture.
-- 
GitLab