summaryrefslogtreecommitdiff
path: root/efl/evas
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2015-03-02 07:55:16 +0200
committerKai Huuhko <kai.huuhko@gmail.com>2015-03-02 07:55:16 +0200
commit65d68e7aee5c0fb87ae39309e6ec27463946f3c0 (patch)
treec3866488f0ad13a489f9eda798fa4f3b6b5d92b4 /efl/evas
parentca4899125d7a5efc1f26072164b07a0cd6197b29 (diff)
Evas.Rect: Optimizations
Freelist will keep Rect objects around for quick instancing, casts to extension type will skip unnecessary type tests.
Diffstat (limited to 'efl/evas')
-rw-r--r--efl/evas/efl.evas_rect.pxi24
1 files changed, 14 insertions, 10 deletions
diff --git a/efl/evas/efl.evas_rect.pxi b/efl/evas/efl.evas_rect.pxi
index 1dd1d05..5d55f51 100644
--- a/efl/evas/efl.evas_rect.pxi
+++ b/efl/evas/efl.evas_rect.pxi
@@ -16,12 +16,14 @@
16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>. 16# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
17 17
18from efl.utils.deprecated cimport DEPRECATED 18from efl.utils.deprecated cimport DEPRECATED
19cimport cython
19 20
20 21
21cdef int _spans_intersect(int c1, int l1, int c2, int l2): 22cdef int _spans_intersect(int c1, int l1, int c2, int l2):
22 return not (((c2 + l2) <= c1) or (c2 >= (c1 + l1))) 23 return not (((c2 + l2) <= c1) or (c2 >= (c1 + l1)))
23 24
24 25
26@cython.freelist(8)
25cdef class Rect(object): 27cdef class Rect(object):
26 """ 28 """
27 29
@@ -61,7 +63,7 @@ cdef class Rect(object):
61 if len(args) == 1: 63 if len(args) == 1:
62 o = args[0] 64 o = args[0]
63 if isinstance(o, Rect): 65 if isinstance(o, Rect):
64 other = o 66 other = <Rect>o
65 self.x0 = other.x0 67 self.x0 = other.x0
66 self.y0 = other.y0 68 self.y0 = other.y0
67 self._w = other._w 69 self._w = other._w
@@ -71,16 +73,19 @@ cdef class Rect(object):
71 elif len(args) == 2: 73 elif len(args) == 2:
72 self.x0, self.y0 = args[0] 74 self.x0, self.y0 = args[0]
73 self._w, self._h = args[1] 75 self._w, self._h = args[1]
74 elif len(args) > 1: 76 elif len(args) == 4:
75 self.x0, self.y0, self._w, self._h = args 77 self.x0 = <int>args[0]
78 self.y0 = <int>args[1]
79 self._w = <int>args[2]
80 self._h = <int>args[3]
76 81
77 if kargs: 82 if kargs:
78 if "rect" in kargs: 83 if "rect" in kargs:
79 o = kargs["rect"] 84 other = <Rect?>kargs["rect"]
80 self.x0 = o.x 85 self.x0 = other.x0
81 self.y0 = o.y 86 self.y0 = other.y0
82 self._w = o.w 87 self._w = other._w
83 self._h = o.h 88 self._h = other._h
84 elif "geometry" in kargs: 89 elif "geometry" in kargs:
85 self.x0, self.y0, self._w, self._h = kargs["geometry"] 90 self.x0, self.y0, self._w, self._h = kargs["geometry"]
86 else: 91 else:
@@ -472,9 +477,8 @@ cdef class Rect(object):
472 477
473 """ 478 """
474 cdef Rect o 479 cdef Rect o
475 cdef int left, right, top, bottom, a, b, c, d
476 if isinstance(obj, Rect): 480 if isinstance(obj, Rect):
477 o = obj 481 o = <Rect>obj
478 elif isinstance(obj, (tuple, list)) and len(obj) == 2: 482 elif isinstance(obj, (tuple, list)) and len(obj) == 2:
479 o = Rect(pos=obj) 483 o = Rect(pos=obj)
480 else: 484 else: