You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "zeroshade (via GitHub)" <gi...@apache.org> on 2023/04/24 20:41:29 UTC

[GitHub] [arrow] zeroshade commented on a diff in pull request #35307: GH-35306: Fix Schema.Fields() to return copy of fields

zeroshade commented on code in PR #35307:
URL: https://github.com/apache/arrow/pull/35307#discussion_r1175762387


##########
go/arrow/schema.go:
##########
@@ -194,7 +194,11 @@ func (sc *Schema) WithEndianness(e endian.Endianness) *Schema {
 func (sc *Schema) Endianness() endian.Endianness { return sc.endianness }
 func (sc *Schema) IsNativeEndian() bool          { return sc.endianness == endian.NativeEndian }
 func (sc *Schema) Metadata() Metadata            { return sc.meta }
-func (sc *Schema) Fields() []Field               { return sc.fields }
+func (sc *Schema) Fields() []Field { 
+	fields := make([]Field, len(sc.fields))
+	copy(fields, sc.fields)
+	return fields
+}

Review Comment:
   I'm not sure I like this. From a performance standpoint, I'd prefer to return the slice as-is rather than a copy of the slice. Perhaps we should add a new function like `FieldsCopy()` or something to that end?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org