nastra commented on code in PR #5733:
URL: https://github.com/apache/iceberg/pull/5733#discussion_r989198389


##########
api/src/main/java/org/apache/iceberg/PartitionSpec.java:
##########
@@ -67,10 +67,7 @@ private PartitionSpec(
       Schema schema, int specId, List<PartitionField> fields, int 
lastAssignedFieldId) {
     this.schema = schema;
     this.specId = specId;
-    this.fields = new PartitionField[fields.size()];
-    for (int i = 0; i < this.fields.length; i += 1) {
-      this.fields[i] = fields.get(i);
-    }
+    this.fields = fields.toArray(new PartitionField[fields.size()]);

Review Comment:
   nit: `this.fields = fields.toArray(new PartitionField[0]);` is slightly 
better/better according to 
https://shipilev.net/blog/2016/arrays-wisdom-ancients/#_new_reflective_array
   
   > Bottom line: toArray(new T[0]) seems faster, safer, and contractually 
cleaner, and therefore should be the default choice now. Future VM 
optimizations may close this performance gap for toArray(new T[size]), 
rendering the current "believed to be optimal" usages on par with an actually 
optimal one. [Further](https://bugs.openjdk.java.net/browse/JDK-8060192) 
[improvements](http://mail.openjdk.java.net/pipermail/valhalla-spec-experts/2015-December/000047.html)
 in toArray APIs would follow the same logic as toArray(new T[0]) — the 
collection itself should create the appropriate storage.



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