vybhavjs commented on code in PR #3079:
URL: https://github.com/apache/fory/pull/3079#discussion_r2643547538


##########
java/fory-core/src/main/java/org/apache/fory/collection/ListSnapshot.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fory.collection;
+
+import java.util.AbstractList;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.fory.annotation.Internal;
+
+/**
+ * A specialized list implementation that creates a snapshot of elements for 
iteration with indexed
+ * access support. This class is designed to efficiently handle concurrent 
list serialization by
+ * creating a lightweight snapshot that can be iterated without holding 
references to the original
+ * list elements.
+ *
+ * <p>The implementation uses an array-based storage for entries and provides 
optimized iteration
+ * through a custom iterator. It includes memory management features such as 
automatic array
+ * reallocation when clearing large collections to prevent memory leaks.
+ *
+ * <p><strong>Important:</strong> The returned iterator from {@link 
#iterator()} must be consumed
+ * completely before calling {@code iterator()} again. The iterator maintains 
its position through a
+ * shared index, and calling {@code iterator()} again before the previous 
iterator is fully consumed
+ * will result in incorrect iteration behavior.
+ *
+ * <p>This class is marked as {@code @Internal} and should not be used 
directly by application code.
+ * It's specifically designed for internal serialization purposes.
+ *
+ * @param <E> the type of elements maintained by this list
+ * @since 1.0
+ */
+@Internal
+public class ListSnapshot<E> extends AbstractList<E> {

Review Comment:
   That was my initial thought as most of the code is duplicated, and 
implementing `get(index)` is possible even with `CollectionSnapshot`. t seemed 
a bit odd semantically as now, non-list classes like `CopyOnWriteArraySet`, 
`ConcurrentSkipListSet` etc are being wrapped in a List implementation, and I 
wasn't sure if that would break something at runtime.
   
   **All tests pass with that change though** - so should I go with that 
approach instead?



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