From dec921809b1dcec46e0d390fba072dae1d9b3b18 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 26 Jun 2018 01:59:12 +0900 Subject: [PATCH] shareable: Refactoring --- internal/shareable/shareable.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/shareable/shareable.go b/internal/shareable/shareable.go index ed7186417..5bcb5b750 100644 --- a/internal/shareable/shareable.go +++ b/internal/shareable/shareable.go @@ -94,17 +94,20 @@ type Image struct { backend *backend - // If node is nil, the image is not shared. node *packing.Node } +func (i *Image) isShared() bool { + return i.node != nil +} + func (i *Image) ensureNotShared() { if i.backend == nil { i.allocate(false) return } - if i.node == nil { + if !i.isShared() { return } @@ -124,7 +127,7 @@ func (i *Image) region() (x, y, width, height int) { if i.backend == nil { panic("not reached") } - if i.node == nil { + if !i.isShared() { w, h := i.backend.restorable.Size() return 0, 0, w, h } @@ -223,7 +226,7 @@ func (i *Image) dispose(markDisposed bool) { return } - if i.node == nil { + if !i.isShared() { i.backend.restorable.Dispose() return }