avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomwh...@apache.org
Subject svn commit: r1573582 - in /avro/trunk: CHANGES.txt lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java lang/java/ipc/src/test/java/org/apache/avro/generic/TestDeepCopy.java
Date Mon, 03 Mar 2014 15:25:58 GMT
Author: tomwhite
Date: Mon Mar  3 15:25:57 2014
New Revision: 1573582

URL: http://svn.apache.org/r1573582
Log:
AVRO-1455. Deep copy does not need to create new instances for primitives.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
    avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/generic/TestDeepCopy.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1573582&r1=1573581&r2=1573582&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Mon Mar  3 15:25:57 2014
@@ -10,6 +10,9 @@ Trunk (not yet released)
 
   OPTIMIZATIONS
 
+    AVRO-1455. Deep copy does not need to create new instances for primitives.
+    (tomwhite)
+
   IMPROVEMENTS
 
     AVRO-1441. Java: Improve documentation for Maven configuration.

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java?rev=1573582&r1=1573581&r2=1573582&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/generic/GenericData.java Mon Mar
 3 15:25:57 2014
@@ -921,7 +921,7 @@ public class GenericData {
         }
         return (T)arrayCopy;
       case BOOLEAN:
-        return (T)new Boolean((Boolean)value);
+        return value; // immutable
       case BYTES:
         ByteBuffer byteBufferValue = (ByteBuffer) value;
         int start = byteBufferValue.position();
@@ -931,18 +931,18 @@ public class GenericData {
         byteBufferValue.position(start);
         return (T)ByteBuffer.wrap(bytesCopy, 0, length);
       case DOUBLE:
-        return (T)new Double((Double)value);
+        return value; // immutable
       case ENUM:
         // Enums are immutable; shallow copy will suffice
         return value;
       case FIXED:
         return (T)createFixed(null, ((GenericFixed) value).bytes(), schema);
       case FLOAT:
-        return (T)new Float((Float)value);
+        return value; // immutable
       case INT:
-        return (T)new Integer((Integer)value);
+        return value; // immutable
       case LONG:
-        return (T)new Long((Long)value);
+        return value; // immutable
       case MAP:
         Map<CharSequence, Object> mapValue = (Map) value;
         Map<CharSequence, Object> mapCopy = 

Modified: avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/generic/TestDeepCopy.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/generic/TestDeepCopy.java?rev=1573582&r1=1573581&r2=1573582&view=diff
==============================================================================
--- avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/generic/TestDeepCopy.java (original)
+++ avro/trunk/lang/java/ipc/src/test/java/org/apache/avro/generic/TestDeepCopy.java Mon Mar
 3 15:25:57 2014
@@ -69,7 +69,8 @@ public class TestDeepCopy {
     interopBuilder.setRecordField(rootBuilder.build());
     
     interopBuilder.setStringField("Hello");
-    interopBuilder.setUnionField(true);
+    interopBuilder.setUnionField(Arrays.asList(new ByteBuffer[] {
+        ByteBuffer.wrap(new byte[] { 1, 2 }) }));
     
     Interop interop = interopBuilder.build();
     
@@ -90,6 +91,11 @@ public class TestDeepCopy {
       // Original field and deep copy should be different instances:
       if ((field.schema().getType() != Type.ENUM)
            && (field.schema().getType() != Type.NULL)
+           && (field.schema().getType() != Type.BOOLEAN)
+           && (field.schema().getType() != Type.INT)
+           && (field.schema().getType() != Type.LONG)
+           && (field.schema().getType() != Type.FLOAT)
+           && (field.schema().getType() != Type.DOUBLE)
            && (field.schema().getType() != Type.STRING)) {
         assertFalse("Field " + field.name() + " is same instance in deep copy",
             interop.get(field.pos()) == 



Mime
View raw message