gemini-code-assist[bot] commented on code in PR #443:
URL: https://github.com/apache/tvm-ffi/pull/443#discussion_r2797349289
##########
src/ffi/extra/serialization.cc:
##########
@@ -312,6 +331,15 @@ class ObjectGraphDeserializer {
return array;
}
+ List<Any> DecodeListData(const json::Array& data) {
+ List<Any> list;
+ list.reserve(static_cast<int64_t>(data.size()));
+ for (const auto& elem : data) {
+ list.push_back(GetOrDecodeNode(elem.cast<int64_t>()));
+ }
+ return list;
+ }
Review Comment:

This function is very similar to `DecodeArrayData`. To avoid code
duplication, you could use a template function.
For example:
```cpp
template <typename SeqType>
SeqType DecodeSequenceData(const json::Array& data) {
SeqType seq;
seq.reserve(static_cast<int64_t>(data.size()));
for (const auto& elem : data) {
seq.push_back(GetOrDecodeNode(elem.cast<int64_t>()));
}
return seq;
}
```
Then `DecodeArrayData` could be `return
DecodeSequenceData<Array<Any>>(data);` and this function could be `return
DecodeSequenceData<List<Any>>(data);`.
##########
src/ffi/extra/serialization.cc:
##########
@@ -152,6 +159,15 @@ class ObjectGraphSerializer {
return data;
}
+ json::Array CreateArrayData(const List<Any>& value) {
+ json::Array data;
+ data.reserve(static_cast<int64_t>(value.size()));
+ for (const Any& item : value) {
+ data.push_back(GetOrCreateNodeIndex(item));
+ }
+ return data;
+ }
Review Comment:

This function is identical to `CreateArrayData(const Array<Any>&)`. To avoid
code duplication, you could use a template function that can handle both
`Array<Any>` and `List<Any>`.
For example:
```cpp
template <typename SeqType>
json::Array CreateSequenceData(const SeqType& value) {
json::Array data;
data.reserve(static_cast<int64_t>(value.size()));
for (const Any& item : value) {
data.push_back(GetOrCreateNodeIndex(item));
}
return data;
}
```
Then both `CreateArrayData` overloads could call this template.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]