# HG changeset patch # User Emmanuel Gil Peyrot # Date 1381003253 -7200 # Node ID 26c082870dcfcdd18f9a799d621852799480e83c # Parent 887de13094914d65ff153590fd4e90a4cb46e723 Use a cached static float[16] instead of a list for default Matrix data. diff --git a/pytouhou/utils/matrix.pyx b/pytouhou/utils/matrix.pyx --- 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):