Skip to content

Call 'toArray()' with an empty array instead of a pre-sized array#5277

Merged
adnapibar merged 2 commits into
opensearch-project:mainfrom
adnapibar:call-toarray
Nov 16, 2022
Merged

Call 'toArray()' with an empty array instead of a pre-sized array#5277
adnapibar merged 2 commits into
opensearch-project:mainfrom
adnapibar:call-toarray

Conversation

@adnapibar
Copy link
Copy Markdown
Contributor

Description

Calls to Collection.toArray() is not consistent and in many places and use a pre-sized array parameter. This change refactors the calls to consistently use toArray(new T[0]). The empty array usage is considered faster, safer and cleaner than the sized based array approach.

Ref: https://shipilev.net/blog/2016/arrays-wisdom-ancients/

Issues Resolved

N/A

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Rabi Panda adnapibar@gmail.com

@adnapibar adnapibar requested review from a team and reta as code owners November 16, 2022 02:41
Calls to `Collection.toArray()` is not consistent and in many places and use a pre-sized array parameter. This change makes a consistent use of the `toArray(new T[0])`. The empty array usage is considered faster, safer and cleaner than the sized based array approach.

Signed-off-by: Rabi Panda <adnapibar@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT: null ❌
  • FAILURES:

@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT: null ❌
  • FAILURES:

@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

Comment thread CHANGELOG.md Outdated
Signed-off-by: Rabi Panda <adnapibar@gmail.com>
@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

@reta
Copy link
Copy Markdown
Contributor

reta commented Nov 16, 2022

Just a comment on the subject, seems like similar changes are making its way into JDK (https://bugs.openjdk.org/browse/JDK-8258804 fe)

@reta
Copy link
Copy Markdown
Contributor

reta commented Nov 16, 2022

Just for the record, it seems like new T[0] is equivalent to T[]::new, I have no particular preference towards one or another.

@adnapibar
Copy link
Copy Markdown
Contributor Author

adnapibar commented Nov 16, 2022

Just a comment on the subject, seems like similar changes are making its way into JDK (https://bugs.openjdk.org/browse/JDK-8258804 fe)

No, I think the issue is just to update it internally in JDK. This is the commit openjdk/jdk@39e03a0b

@adnapibar
Copy link
Copy Markdown
Contributor Author

Just a comment on the subject, seems like similar changes are making its way into JDK (https://bugs.openjdk.org/browse/JDK-8258804 fe)

No, I think the issue is just to update it internally in JDK. This is the commit openjdk/jdk@39e03a0b

I think I misunderstood your comment earlier. Yes, there were a few places they have updated it.

@adnapibar adnapibar merged commit 9fc3f40 into opensearch-project:main Nov 16, 2022
andrross pushed a commit to andrross/OpenSearch that referenced this pull request Nov 5, 2024
…ensearch-project#5277)

Calls to `Collection.toArray()` is not consistent and in many places and use a
pre-sized array parameter. This change makes a consistent use of the
`toArray(new T[0])`. The empty array usage is considered faster, safer and
cleaner than the sized based array approach.

Signed-off-by: Rabi Panda <adnapibar@gmail.com>
reta pushed a commit that referenced this pull request Nov 5, 2024
) (#16563)

Calls to `Collection.toArray()` is not consistent and in many places and use a
pre-sized array parameter. This change makes a consistent use of the
`toArray(new T[0])`. The empty array usage is considered faster, safer and
cleaner than the sized based array approach.

Signed-off-by: Rabi Panda <adnapibar@gmail.com>
Co-authored-by: Rabi Panda <adnapibar@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants