[tekui-devel] tekui: pushClipRect() optimized using a Rectangle pool

hg-notify at neoscientists.org hg-notify at neoscientists.org
Tue Feb 5 02:46:00 CET 2008


details:   http://hg.teklib.org/tekui/rev/4eec5851a14a
changeset: 343:4eec5851a14a
user:      Timm S. Mueller <tmueller at neoscientists.org>
date:      Sun Jan 27 13:07:47 2008 +0100
description:
pushClipRect() optimized using a Rectangle pool

diffs (80 lines):

diff -r 3ac721bc4aea -r 4eec5851a14a tek/class/ui/drawable.lua
--- a/tek/class/ui/drawable.lua	Sun Jan 27 03:16:07 2008 +0100
+++ b/tek/class/ui/drawable.lua	Sun Jan 27 13:07:47 2008 +0100
@@ -16,6 +16,7 @@ local min = math.min
 local min = math.min
 local max = math.max
 local overlap = ui.Region.overlapCoords
+local HUGE = ui.HUGE
 
 module("tek.class.ui.drawable", tek.class.ui.object)
 _VERSION = "Drawable 3.0"
@@ -37,6 +38,7 @@ function Drawable.new(class, self)
 	self.ShiftY = 0
 	self.ClipStack = { }
 	self.ClipRect = { }
+	self.RectPool = { }
 	return self
 end
 
@@ -129,31 +131,34 @@ end
 end
 
 function Drawable:pushClipRect(x0, y0, x1, y1)
-	x0 = x0 + self.ShiftX
-	y0 = y0 + self.ShiftY
-	x1 = x1 + self.ShiftX
-	y1 = y1 + self.ShiftY
-	insert(self.ClipStack, { x0, y0, x1, y1 })
-	if self.ClipRect[1] then
-		x0, y0, x1, y1 = overlap(x0, y0, x1, y1, unpack(self.ClipRect))
+	local cr = self.ClipRect
+	local sx = self.ShiftX
+	local sy = self.ShiftY
+	x0 = x0 + sx
+	y0 = y0 + sy
+	x1 = x1 + sx
+	y1 = y1 + sy
+	local r = remove(self.RectPool) or { }
+	r[1], r[2], r[3], r[4] = x0, y0, x1, y1
+	insert(self.ClipStack, r)
+	if cr[1] then
+		x0, y0, x1, y1 = overlap(x0, y0, x1, y1, cr[1], cr[2], cr[3], cr[4])
 		if not x0 then
 			x0, y0, x1, y1 = -1, -1, -1, -1
 		end
 	end
-	self.ClipRect[1] = x0
-	self.ClipRect[2] = y0
-	self.ClipRect[3] = x1
-	self.ClipRect[4] = y1
+	cr[1], cr[2], cr[3], cr[4] = x0, y0, x1, y1
 	self.Visual:setcliprect(x0, y0, x1 - x0 + 1, y1 - y0 + 1)
 end
 
 function Drawable:popClipRect()
 	local cs = self.ClipStack
-	remove(cs)
+	local cr = self.ClipRect
+	insert(self.RectPool, remove(cs))
 	local x0, y0, x1, y1
 	if #cs > 0 then
-		x0, y0, x1, y1 = unpack(cs[1])
-		for i = 2, #cs do
+		x0, y0, x1, y1 = 0, 0, HUGE, HUGE
+		for i = 1, #cs do
 			x0, y0, x1, y1 = overlap(x0, y0, x1, y1, unpack(cs[i]))
 			if not x0 then
 				x0, y0, x1, y1 = -1, -1, -1, -1
@@ -161,10 +166,7 @@ function Drawable:popClipRect()
 			end
 		end
 	end
-	self.ClipRect[1] = x0
-	self.ClipRect[2] = y0
-	self.ClipRect[3] = x1
-	self.ClipRect[4] = y1
+	cr[1], cr[2], cr[3], cr[4] = x0, y0, x1, y1
 	if x0 then
 		self.Visual:setcliprect(x0, y0, x1 - x0 + 1, y1 - y0 + 1)
 	else


More information about the tekui-devel mailing list