diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-03-14 02:30:33 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-03-14 02:30:33 +0100 |
commit | 52bb6a506ce502f6c91127713c2ea20a84be31f3 (patch) | |
tree | 451e3250bac018e74d36e678c94ef92083add036 /src/blueshift_randr.pyx | |
parent | reduce allocations in vidmode (diff) | |
download | blueshift-52bb6a506ce502f6c91127713c2ea20a84be31f3.tar.gz blueshift-52bb6a506ce502f6c91127713c2ea20a84be31f3.tar.bz2 blueshift-52bb6a506ce502f6c91127713c2ea20a84be31f3.tar.xz |
do less allocations in randr + seal i very minor memory leak
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | src/blueshift_randr.pyx | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/src/blueshift_randr.pyx b/src/blueshift_randr.pyx index 85f3133..f54a5c9 100644 --- a/src/blueshift_randr.pyx +++ b/src/blueshift_randr.pyx @@ -28,6 +28,18 @@ cdef extern int blueshift_randr_apply(unsigned long long int use_crtcs, cdef extern void blueshift_randr_close() + +cdef unsigned short int* r_c +cdef unsigned short int* g_c +cdef unsigned short int* b_c +r_c = <unsigned short int*>malloc(256 * 2) +g_c = <unsigned short int*>malloc(256 * 2) +b_c = <unsigned short int*>malloc(256 * 2) +if (r_c is NULL) or (g_c is NULL) or (b_c is NULL): + raise MemoryError() + + + def randr_open(int use_screen): ''' Start stage of colour curve control @@ -56,6 +68,7 @@ def randr_read(int use_crtc): for j in range(s): c.append(got[i + j]) i += s + free(got) return (r, g, b) @@ -69,28 +82,19 @@ def randr_apply(unsigned long long use_crtcs, r_curve, g_curve, b_curve): @param b_curve:list<unsigned short int> The blue colour curve @return Zero on success ''' - cdef unsigned short int* r - cdef unsigned short int* g - cdef unsigned short int* b - r = <unsigned short int*>malloc(256 * 2) - g = <unsigned short int*>malloc(256 * 2) - b = <unsigned short int*>malloc(256 * 2) - if (r is NULL) or (g is NULL) or (b is NULL): - raise MemoryError() for i in range(256): - r[i] = r_curve[i] & 0xFFFF - g[i] = g_curve[i] & 0xFFFF - b[i] = b_curve[i] & 0xFFFF - rc = blueshift_randr_apply(use_crtcs, r, g, b) - free(r) - free(g) - free(b) - return rc + r_c[i] = r_curve[i] & 0xFFFF + g_c[i] = g_curve[i] & 0xFFFF + b_c[i] = b_curve[i] & 0xFFFF + return blueshift_randr_apply(use_crtcs, r_c, g_c, b_c) def randr_close(): ''' Resource freeing stage of colour curve control ''' + free(r_c) + free(g_c) + free(b_c) blueshift_randr_close() |