Skip to content

Commit 422b290

Browse files
committed
Pyray : potential optimization
1 parent b3f8d5c commit 422b290

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

pyray/__init__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ def pointer(self, struct):
6262
## simple value converters
6363
# will fail if fed wrong arguments
6464

65-
def as_is(value):
66-
return value
67-
6865
def to_bytes(value):
6966
if type(value) is bytes: return value
7067
else: return value.encode('utf-8', 'ignore')
@@ -88,7 +85,7 @@ def makeFunc(c_func):
8885
elif c_arg_type.kind == 'pointer':
8986
converters.append(to_pointer)
9087
else:
91-
converters.append(as_is)
88+
converters.append(None) # None = leave as is
9289

9390
# not sure if this would bring any speedup
9491
#converters = tuple(converters)
@@ -98,17 +95,19 @@ def makeFunc(c_func):
9895
if c_result_type is ffi.typeof('char *'):
9996
resultConverter = to_str
10097
elif c_result_type:
101-
resultConverter = as_is
98+
resultConverter = None # None = leave as is
10299

103100
# use a closure to bring converters into c function call
104101
def func(*args):
105102
nonlocal converters, resultConverter
106103

107-
result = c_func(* (convert(arg) for (arg, convert) in zip(args, converters) ) )
104+
result = c_func(* (convert(arg) if convert else arg for (arg, convert) in zip(args, converters) ) )
108105

109-
if result is None or resultConverter is None:
106+
if result is None:
110107
return
111-
return resultConverter(result)
108+
if resultConverter:
109+
return resultConverter(result)
110+
return result
112111

113112
return func
114113

0 commit comments

Comments
 (0)