mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/restorable: remove unnecessary copying
After6e5361c328
, WritePixels can expect that the given pixel byte slice is always new, and now can be assumed immutable. Do not copy the slice for restoring. Actually, these copying were introduced at38ce46328a
in order to reuse the same slice regions.
This commit is contained in:
parent
6e5361c328
commit
2405b7e825
@ -278,11 +278,7 @@ func (i *Image) WritePixels(pixels []byte, region image.Rectangle) {
|
||||
|
||||
if region.Eq(image.Rect(0, 0, w, h)) {
|
||||
if pixels != nil {
|
||||
// pixels can point to a shared region.
|
||||
// This function is responsible to copy this.
|
||||
copiedPixels := make([]byte, len(pixels))
|
||||
copy(copiedPixels, pixels)
|
||||
i.basePixels.AddOrReplace(copiedPixels, image.Rect(0, 0, w, h))
|
||||
i.basePixels.AddOrReplace(pixels, image.Rect(0, 0, w, h))
|
||||
} else {
|
||||
i.basePixels.Clear(image.Rect(0, 0, w, h))
|
||||
}
|
||||
@ -299,11 +295,7 @@ func (i *Image) WritePixels(pixels []byte, region image.Rectangle) {
|
||||
}
|
||||
|
||||
if pixels != nil {
|
||||
// pixels can point to a shared region.
|
||||
// This function is responsible to copy this.
|
||||
copiedPixels := make([]byte, len(pixels))
|
||||
copy(copiedPixels, pixels)
|
||||
i.basePixels.AddOrReplace(copiedPixels, region)
|
||||
i.basePixels.AddOrReplace(pixels, region)
|
||||
} else {
|
||||
i.basePixels.Clear(region)
|
||||
}
|
||||
|
@ -461,6 +461,7 @@ func TestWritePixels(t *testing.T) {
|
||||
}
|
||||
img.WritePixels(pix, image.Rect(5, 7, 9, 11))
|
||||
// Check the region (5, 7)-(9, 11). Outside state is indeterminate.
|
||||
pix = make([]byte, 4*4*4)
|
||||
for i := range pix {
|
||||
pix[i] = 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user