Skip to content

Commit

Permalink
optimize list creation
Browse files Browse the repository at this point in the history
  • Loading branch information
prusnak committed Nov 21, 2024
1 parent 8494ab2 commit f956754
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions hid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,7 @@ cdef class device:
n = hid_read(c_hid, cbuff, c_max_length)
if n is -1:
raise IOError('read error')
res = []
for i in range(n):
res.append(cbuff[i])
res = list(cbuff[:n])
finally:
if max_length > 16:
free(cbuff)
Expand Down Expand Up @@ -377,11 +375,9 @@ cdef class device:
cbuff[0] = report_num
with nogil:
n = hid_get_feature_report(c_hid, cbuff, c_max_length)
res = []
if n < 0:
raise IOError('read error')
for i in range(n):
res.append(cbuff[i])
res = list(cbuff[:n])
finally:
if max_length > 16:
free(cbuff)
Expand Down Expand Up @@ -414,11 +410,9 @@ cdef class device:
cbuff[0] = report_num
with nogil:
n = hid_get_input_report(c_hid, cbuff, c_max_length)
res = []
if n < 0:
raise IOError('read error')
for i in range(n):
res.append(cbuff[i])
res = list(cbuff[:n])
finally:
if max_length > 16:
free(cbuff)
Expand Down

0 comments on commit f956754

Please sign in to comment.