Skip to content

Commit d6a229b

Browse files
Mickaël SchoentgenBoboTiG
authored andcommitted
Mac: reduce the number of function calls
The `int()` builtin function is no more called. This is a small improvement.
1 parent 7f69d87 commit d6a229b

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ History:
33
<see Git checking messages for history>
44

55
6.0.1 2020/xx/xx
6+
- Mac: reduce the number of function calls
67
- :heart: contributors: @
78

89
6.0.0 2020/06/30

mss/darwin.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def cfactory(func, argtypes, restype):
9292

9393
uint32 = ctypes.c_uint32
9494
void = ctypes.c_void_p
95-
size_t = ctypes.c_size_t
9695
pointer = ctypes.POINTER
9796

9897
cfactory(
@@ -109,14 +108,14 @@ def cfactory(func, argtypes, restype):
109108
argtypes=[CGRect, uint32, uint32, uint32],
110109
restype=void,
111110
)
112-
cfactory(func="CGImageGetWidth", argtypes=[void], restype=size_t)
113-
cfactory(func="CGImageGetHeight", argtypes=[void], restype=size_t)
111+
cfactory(func="CGImageGetWidth", argtypes=[void], restype=int)
112+
cfactory(func="CGImageGetHeight", argtypes=[void], restype=int)
114113
cfactory(func="CGImageGetDataProvider", argtypes=[void], restype=void)
115114
cfactory(func="CGDataProviderCopyData", argtypes=[void], restype=void)
116115
cfactory(func="CFDataGetBytePtr", argtypes=[void], restype=void)
117116
cfactory(func="CFDataGetLength", argtypes=[void], restype=ctypes.c_uint64)
118-
cfactory(func="CGImageGetBytesPerRow", argtypes=[void], restype=size_t)
119-
cfactory(func="CGImageGetBitsPerPixel", argtypes=[void], restype=size_t)
117+
cfactory(func="CGImageGetBytesPerRow", argtypes=[void], restype=int)
118+
cfactory(func="CGImageGetBitsPerPixel", argtypes=[void], restype=int)
120119
cfactory(func="CGDataProviderRelease", argtypes=[void], restype=void)
121120
cfactory(func="CFRelease", argtypes=[void], restype=void)
122121

@@ -183,8 +182,8 @@ def _grab_impl(self, monitor):
183182
if not image_ref:
184183
raise ScreenShotError("CoreGraphics.CGWindowListCreateImage() failed.")
185184

186-
width = int(core.CGImageGetWidth(image_ref))
187-
height = int(core.CGImageGetHeight(image_ref))
185+
width = core.CGImageGetWidth(image_ref)
186+
height = core.CGImageGetHeight(image_ref)
188187
prov = copy_data = None
189188
try:
190189
prov = core.CGImageGetDataProvider(image_ref)
@@ -195,8 +194,8 @@ def _grab_impl(self, monitor):
195194
data = bytearray(raw.contents)
196195

197196
# Remove padding per row
198-
bytes_per_row = int(core.CGImageGetBytesPerRow(image_ref))
199-
bytes_per_pixel = int(core.CGImageGetBitsPerPixel(image_ref))
197+
bytes_per_row = core.CGImageGetBytesPerRow(image_ref)
198+
bytes_per_pixel = core.CGImageGetBitsPerPixel(image_ref)
200199
bytes_per_pixel = (bytes_per_pixel + 7) // 8
201200

202201
if bytes_per_pixel * width != bytes_per_row:

0 commit comments

Comments
 (0)