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


##########
java/fury-core/src/main/java/org/apache/fury/Fury.java:
##########
@@ -1220,6 +1240,47 @@ public Object 
deserializeJavaObjectAndClass(FuryReadableChannel channel) {
     return deserializeJavaObjectAndClass(buf);
   }
 
+  @SuppressWarnings("unchecked")
+  @Override
+  public <T> T copy(T obj) {
+    if (Objects.isNull(obj)) {
+      return null;
+    }
+    try {
+      if (obj instanceof FuryCopyable) {
+        return (T) ((FuryCopyable<?>) obj).copy(this);
+      } else {
+        return (T) 
classResolver.getOrUpdateClassInfo(obj.getClass()).getSerializer().copy(obj);
+      }
+    } catch (StackOverflowError e) {
+      throw processCopyStackOverflowError(e);
+    } finally {
+      if (copyRefTracking && copyDepth == 0) {
+        resetCopy();
+      }
+    }
+  }
+
+  /**
+   * Record the mapping between the object currently being copied and the 
newly generated object
+   * after copying.
+   *
+   * @param originObj the origin object instance
+   * @param newObj the new object instance
+   */
+  public void copyReference(Object originObj, Object newObj) {
+    if (Objects.nonNull(originObj) && Objects.nonNull(newObj)) {
+      originToCopyMap.put(originObj, newObj);
+    }
+  }
+
+  public Object getCopyObject(Object originObj) {
+    if (Objects.isNull(originObj)) {

Review Comment:
   We'd better check null directly, we need to reduce call stack for inline



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