changeset 493:26c082870dcf

Use a cached static float[16] instead of a list for default Matrix data.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 05 Oct 2013 22:00:53 +0200
parents 887de1309491
children 6be9c99a3a24
files pytouhou/utils/matrix.pyx
diffstat 1 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/utils/matrix.pyx
+++ b/pytouhou/utils/matrix.pyx
@@ -14,18 +14,23 @@
 
 from libc.math cimport sin, cos
 from libc.stdlib cimport malloc, free
+from libc.string cimport memcpy
+
+
+cdef float[16] identity
+identity[:] = [1, 0, 0, 0,
+               0, 1, 0, 0,
+               0, 0, 1, 0,
+               0, 0, 0, 1]
 
 
 cdef class Matrix:
     def __init__(self, data=None):
-        if data is None:
-            data = [1, 0, 0, 0,
-                    0, 1, 0, 0,
-                    0, 0, 1, 0,
-                    0, 0, 0, 1]
-        for i in xrange(4):
-            for j in xrange(4):
-                self.data[i*4+j] = data[4*i+j]
+        if data is not None:
+            for i in xrange(16):
+                self.data[i] = data[i]
+        else:
+            memcpy(self.data, identity, 16 * sizeof(float))
 
 
     def __mul__(Matrix self, Matrix other):