-
Notifications
You must be signed in to change notification settings - Fork 22
Add std::move for container by-value parameters #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1082,7 +1082,12 @@ def input_conversion( | |
| else: | ||
| cleanup_code = "del %s" % temp_var | ||
|
|
||
| return code, "deref(%s)" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large maps | ||
| if cpp_type.is_ref: | ||
| call_as = "deref(%s)" % temp_var | ||
| else: | ||
| call_as = "move(deref(%s))" % temp_var | ||
| return code, call_as, cleanup_code | ||
|
|
||
| def call_method(self, res_type: CppType, cy_call_str: str, with_const: bool = True) -> str: | ||
| return "_r = %s" % cy_call_str | ||
|
|
@@ -1251,7 +1256,12 @@ def input_conversion( | |
| ) | ||
| else: | ||
| cleanup_code = "del %s" % temp_var | ||
| return code, "deref(%s)" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large sets | ||
| if cpp_type.topmost_is_ref: | ||
| call_as = "deref(%s)" % temp_var | ||
| else: | ||
| call_as = "move(deref(%s))" % temp_var | ||
| return code, call_as, cleanup_code | ||
|
|
||
| elif tt.base_type in self.converters.names_of_wrapper_classes: | ||
| base_type = tt.base_type | ||
|
|
@@ -1293,7 +1303,12 @@ def input_conversion( | |
|
|
||
| else: | ||
| cleanup_code = "del %s" % temp_var | ||
| return code, "deref(%s)" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large sets | ||
| if cpp_type.is_ref: | ||
| call_as = "deref(%s)" % temp_var | ||
| else: | ||
| call_as = "move(deref(%s))" % temp_var | ||
| return code, call_as, cleanup_code | ||
| else: | ||
| inner = self.converters.cython_type(tt) | ||
| # cython cares for conversion of stl containers with std types: | ||
|
|
@@ -1726,7 +1741,12 @@ def input_conversion( | |
| ) | ||
| else: | ||
| cleanup_code = "del %s" % temp_var | ||
| return code, "deref(%s)" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large vectors | ||
| if cpp_type.topmost_is_ref: | ||
| call_as = "deref(%s)" % temp_var | ||
| else: | ||
| call_as = "move(deref(%s))" % temp_var | ||
| return code, call_as, cleanup_code | ||
|
|
||
| elif tt.base_type in self.converters.names_of_wrapper_classes: | ||
| # Case 2: We wrap a std::vector<> with a base type we need to wrap | ||
|
|
@@ -1752,8 +1772,11 @@ def input_conversion( | |
|
|
||
| if cpp_type.is_ptr: | ||
| call_fragment = temp_var | ||
| else: | ||
| elif cpp_type.topmost_is_ref: | ||
| call_fragment = "deref(%s)" % temp_var | ||
| else: | ||
| # Use move() for by-value parameters to avoid copying large vectors | ||
| call_fragment = "move(deref(%s))" % temp_var | ||
|
|
||
| return code, call_fragment, cleanup_code | ||
|
|
||
|
|
@@ -1802,7 +1825,12 @@ def input_conversion( | |
| locals(), | ||
| ) | ||
|
|
||
| return code, "%s" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large vectors | ||
| if cpp_type.topmost_is_ref: | ||
| call_as = "%s" % temp_var | ||
| else: | ||
| call_as = "move(%s)" % temp_var | ||
| return code, call_as, cleanup_code | ||
|
|
||
| elif inner_contains_classes_to_wrap and tt.base_type != "libcpp_vector": | ||
| # Only if the template argument which is neither a class-to-wrap nor a std::vector | ||
|
|
@@ -1857,7 +1885,12 @@ def input_conversion( | |
| "Error: For recursion in std::vector<T> to work, we need a ConverterRegistry instance at self.cr" | ||
| ) | ||
|
|
||
| return code, "deref(%s)" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large vectors | ||
| if cpp_type.topmost_is_ref: | ||
| call_as = "deref(%s)" % temp_var | ||
| else: | ||
| call_as = "move(deref(%s))" % temp_var | ||
| return code, call_as, cleanup_code | ||
|
|
||
| else: | ||
| # Case 5: We wrap a regular type | ||
|
|
@@ -1879,7 +1912,12 @@ def input_conversion( | |
| locals(), | ||
| ) | ||
|
|
||
| return code, "%s" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large vectors | ||
| if cpp_type.topmost_is_ref: | ||
| call_as = "%s" % temp_var | ||
| else: | ||
| call_as = "move(%s)" % temp_var | ||
| return code, call_as, cleanup_code | ||
|
|
||
| def call_method(self, res_type: CppType, cy_call_str: str, with_const: bool = True) -> str: | ||
| t = self.converters.cython_type(res_type) | ||
|
|
@@ -2354,7 +2392,12 @@ def input_conversion( | |
| else: | ||
| cleanup_code = "del %s" % temp_var | ||
|
|
||
| return code, "deref(%s)" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large maps | ||
| if cpp_type.is_ref: | ||
| call_as = "deref(%s)" % temp_var | ||
| else: | ||
| call_as = "move(deref(%s))" % temp_var | ||
| return code, call_as, cleanup_code | ||
|
|
||
| def call_method(self, res_type: CppType, cy_call_str: str, with_const: bool = True) -> str: | ||
| return "_r = %s" % cy_call_str | ||
|
|
@@ -2543,7 +2586,12 @@ def input_conversion( | |
| ) | ||
| else: | ||
| cleanup_code = "del %s" % temp_var | ||
| return code, "deref(%s)" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large sets | ||
| if cpp_type.topmost_is_ref: | ||
| call_as = "deref(%s)" % temp_var | ||
| else: | ||
| call_as = "move(deref(%s))" % temp_var | ||
| return code, call_as, cleanup_code | ||
|
Comment on lines
+2589
to
+2594
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent use of Line 2590 uses For consistency with the cleanup code checks (lines 2573, 2610, 2647) and since Apply this diff to make the check consistent: - if cpp_type.topmost_is_ref:
+ if cpp_type.is_ref:
call_as = "deref(%s)" % temp_var
else:
call_as = "move(deref(%s))" % temp_varAlso applies to: 2630-2635, 2663-2668 🤖 Prompt for AI Agents |
||
|
|
||
| elif tt.base_type in self.converters.names_of_wrapper_classes: | ||
| base_type = tt.base_type | ||
|
|
@@ -2579,7 +2627,12 @@ def input_conversion( | |
| ) | ||
| else: | ||
| cleanup_code = "del %s" % temp_var | ||
| return code, "deref(%s)" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large sets | ||
| if cpp_type.is_ref: | ||
| call_as = "deref(%s)" % temp_var | ||
| else: | ||
| call_as = "move(deref(%s))" % temp_var | ||
| return code, call_as, cleanup_code | ||
| else: | ||
| # Primitive types - need explicit iteration | ||
| item = "item%d" % arg_num | ||
|
|
@@ -2607,7 +2660,12 @@ def input_conversion( | |
| ) | ||
| else: | ||
| cleanup_code = "del %s" % temp_var | ||
| return code, "deref(%s)" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large sets | ||
| if cpp_type.is_ref: | ||
| call_as = "deref(%s)" % temp_var | ||
| else: | ||
| call_as = "move(deref(%s))" % temp_var | ||
| return code, call_as, cleanup_code | ||
|
|
||
| def call_method(self, res_type: CppType, cy_call_str: str, with_const: bool = True) -> str: | ||
| return "_r = %s" % cy_call_str | ||
|
|
@@ -2745,7 +2803,12 @@ def input_conversion( | |
| ) | ||
| else: | ||
| cleanup_code = "del %s" % temp_var | ||
| return code, "deref(%s)" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large deques | ||
| if cpp_type.topmost_is_ref: | ||
| call_as = "deref(%s)" % temp_var | ||
| else: | ||
| call_as = "move(deref(%s))" % temp_var | ||
| return code, call_as, cleanup_code | ||
|
Comment on lines
+2806
to
+2811
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent use of Line 2807 uses Apply this diff: - if cpp_type.topmost_is_ref:
+ if cpp_type.is_ref:
call_as = "deref(%s)" % temp_var
else:
call_as = "move(deref(%s))" % temp_varAlso applies to: 2828-2833 🤖 Prompt for AI Agents |
||
|
|
||
| elif tt.base_type in self.converters.names_of_wrapper_classes: | ||
| base_type = tt.base_type | ||
|
|
@@ -2762,7 +2825,12 @@ def input_conversion( | |
| locals(), | ||
| ) | ||
| cleanup_code = "del %s" % temp_var | ||
| return code, "deref(%s)" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large deques | ||
| if cpp_type.is_ref: | ||
| call_as = "deref(%s)" % temp_var | ||
| else: | ||
| call_as = "move(deref(%s))" % temp_var | ||
| return code, call_as, cleanup_code | ||
| else: | ||
| # Primitive types - need explicit iteration | ||
| item = "item%d" % arg_num | ||
|
|
@@ -2913,7 +2981,12 @@ def input_conversion( | |
| ) | ||
| else: | ||
| cleanup_code = "del %s" % temp_var | ||
| return code, "deref(%s)" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large lists | ||
| if cpp_type.topmost_is_ref: | ||
| call_as = "deref(%s)" % temp_var | ||
| else: | ||
| call_as = "move(deref(%s))" % temp_var | ||
| return code, call_as, cleanup_code | ||
|
Comment on lines
+2984
to
+2989
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent use of Line 2985 uses Apply this diff: - if cpp_type.topmost_is_ref:
+ if cpp_type.is_ref:
call_as = "deref(%s)" % temp_var
else:
call_as = "move(deref(%s))" % temp_varAlso applies to: 3006-3011 🤖 Prompt for AI Agents |
||
|
|
||
| elif tt.base_type in self.converters.names_of_wrapper_classes: | ||
| base_type = tt.base_type | ||
|
|
@@ -2930,7 +3003,12 @@ def input_conversion( | |
| locals(), | ||
| ) | ||
| cleanup_code = "del %s" % temp_var | ||
| return code, "deref(%s)" % temp_var, cleanup_code | ||
| # Use move() for by-value parameters to avoid copying large lists | ||
| if cpp_type.is_ref: | ||
| call_as = "deref(%s)" % temp_var | ||
| else: | ||
| call_as = "move(deref(%s))" % temp_var | ||
| return code, call_as, cleanup_code | ||
| else: | ||
| code = Code().add( | ||
| """ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent use of
topmost_is_refvsis_ref.Line 1260 uses
cpp_type.topmost_is_reffor the enum case, while line 1307 usescpp_type.is_reffor the wrapper class case. Both are checking whether to use move semantics for the same logical condition.For consistency and correctness, consider using
cpp_type.is_refin both cases (matching the cleanup code checks at lines 1243 and 1286). Whiletopmost_is_refmay be intentional for nested containers,StdSetConverterdoesn't explicitly handle nesting likeStdVectorConverterdoes.Apply this diff to make the checks consistent:
Also applies to: 1306-1311
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jpfeuffer ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.