chaokunyang commented on code in PR #1942:
URL: https://github.com/apache/fury/pull/1942#discussion_r1843170398


##########
python/pyfury/_serialization.pyx:
##########
@@ -1644,29 +1664,143 @@ cdef class CollectionSerializer(Serializer):
     cpdef int16_t get_xtype_id(self):
         return -FuryType.LIST.value
 
+    cdef pair[int8_t, int64_t] write_header(self, Buffer buffer, value):
+        cdef int8_t collect_flag = COLLECTION_DEFAULT_FLAG
+        elem_type = type(next(iter(value)))
+        for s in value:
+            if type(s) is not elem_type:
+                collect_flag |= COLLECTION_NOT_SAME_TYPE
+                break
+        if self.fury.ref_tracking:
+            collect_flag |= COLLECTION_TRACKING_REF
+        buffer.write_varint64((len(value) << 4) | collect_flag)
+        return pair[int8_t, int64_t](collect_flag, obj2int(elem_type))
+
     cpdef write(self, Buffer buffer, value):
-        buffer.write_varint32(len(value))
+        if len(value) == 0:
+            buffer.write_varint64(0)
+            return
+        cdef pair[int8_t, int64_t] header_pair = self.write_header(buffer, 
value)
+        cdef int8_t collect_flag = header_pair.first
+        cdef int64_t elem_type_ptr = header_pair.second
+        cdef elem_type = <type>int2obj(elem_type_ptr)
         cdef MapRefResolver ref_resolver = self.ref_resolver
         cdef ClassResolver class_resolver = self.class_resolver
+        if (collect_flag & COLLECTION_NOT_SAME_TYPE) == 0:
+            if elem_type is str:

Review Comment:
   you still write null flag and type here, this should be skipped for same 
type and not-null elements. could you take 
`org.apache.fury.serializer.collection.AbstractCollectionSerializer#writeSameTypeElements`
 as a reference?



-- 
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]

Reply via email to