pitrou commented on code in PR #40565:
URL: https://github.com/apache/arrow/pull/40565#discussion_r1530355138
##########
python/pyarrow/src/arrow/python/arrow_to_pandas.cc:
##########
@@ -620,37 +620,42 @@ inline Status ConvertAsPyObjects(const PandasOptions&
options, const ChunkedArra
using ArrayType = typename TypeTraits<Type>::ArrayType;
using Scalar = typename MemoizationTraits<Type>::Scalar;
- ::arrow::internal::ScalarMemoTable<Scalar> memo_table(options.pool);
- std::vector<PyObject*> unique_values;
- int32_t memo_size = 0;
-
- auto WrapMemoized = [&](const Scalar& value, PyObject** out_values) {
- int32_t memo_index;
- RETURN_NOT_OK(memo_table.GetOrInsert(value, &memo_index));
- if (memo_index == memo_size) {
- // New entry
- RETURN_NOT_OK(wrap_func(value, out_values));
- unique_values.push_back(*out_values);
- ++memo_size;
- } else {
- // Duplicate entry
- Py_INCREF(unique_values[memo_index]);
- *out_values = unique_values[memo_index];
- }
- return Status::OK();
- };
-
- auto WrapUnmemoized = [&](const Scalar& value, PyObject** out_values) {
- return wrap_func(value, out_values);
- };
+ std::shared_ptr<::arrow::internal::ScalarMemoTable<Scalar>> memo_table =
nullptr;
+ std::shared_ptr<std::vector<PyObject*>> unique_values = nullptr;
+ std::shared_ptr<int32_t> memo_size = std::make_shared<int32_t>(0);
+
+ std::function<Status(const typename MemoizationTraits<Type>::Scalar&,
PyObject**)>
Review Comment:
Or, better, just keep the existing `WrapMemoized` and `WrapUnmemoized`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]