sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1805429 - /sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java
Date Fri, 18 Aug 2017 13:49:27 GMT
Author: desruisseaux
Date: Fri Aug 18 13:49:27 2017
New Revision: 1805429

URL: http://svn.apache.org/viewvc?rev=1805429&view=rev
Log:
More efficient copy if the record is already a DefaultRecord instance.

Modified:
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java?rev=1805429&r1=1805428&r2=1805429&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/util/iso/DefaultRecord.java
[UTF-8] Fri Aug 18 13:49:27 2017
@@ -104,19 +104,25 @@ public class DefaultRecord implements Re
      *
      * @since 0.8
      */
+    @SuppressWarnings("SuspiciousSystemArraycopy")
     public DefaultRecord(final Record record) {
         this(record.getRecordType());
-        for (final Map.Entry<MemberName,Integer> entry : definition.memberIndices().entrySet())
{
-            final MemberName name = entry.getKey();
-            final Object value = record.locate(name);
-            if (value != null) {
-                final int index = entry.getValue();
-                final Class<?> valueClass = definition.getValueClass(index);
-                if (valueClass != null && !valueClass.isInstance(value)) {
-                    throw new ClassCastException(Errors.format(Errors.Keys.IllegalPropertyValueClass_3,
-                            name, valueClass, value.getClass()));
+        if (record instanceof DefaultRecord) {
+            final Object source = ((DefaultRecord) record).values;
+            System.arraycopy(source, 0, values, 0, Array.getLength(source));
+        } else {
+            for (final Map.Entry<MemberName,Integer> entry : definition.memberIndices().entrySet())
{
+                final MemberName name = entry.getKey();
+                final Object value = record.locate(name);
+                if (value != null) {
+                    final int index = entry.getValue();
+                    final Class<?> valueClass = definition.getValueClass(index);
+                    if (valueClass != null && !valueClass.isInstance(value)) {
+                        throw new ClassCastException(Errors.format(Errors.Keys.IllegalPropertyValueClass_3,
+                                name, valueClass, value.getClass()));
+                    }
+                    Array.set(values, index, value);
                 }
-                Array.set(values, index, value);
             }
         }
     }



Mime
View raw message