You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2022/03/15 09:21:32 UTC
[camel] 01/02: CAMEL-17762: avoid unnecessary array copies
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit ee53649a5d56e72d8766e7d7615e745300e68f9e
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Mon Mar 14 18:32:15 2022 +0100
CAMEL-17762: avoid unnecessary array copies
---
core/camel-api/src/main/java/org/apache/camel/ResumableSet.java | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/core/camel-api/src/main/java/org/apache/camel/ResumableSet.java b/core/camel-api/src/main/java/org/apache/camel/ResumableSet.java
index 4e4693d..4f82216 100644
--- a/core/camel-api/src/main/java/org/apache/camel/ResumableSet.java
+++ b/core/camel-api/src/main/java/org/apache/camel/ResumableSet.java
@@ -17,6 +17,7 @@
package org.apache.camel;
+import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.function.Predicate;
@@ -30,8 +31,8 @@ public interface ResumableSet<T> {
* @return
*/
default T[] resumeEach(T[] input, Predicate<T> resumableCheck) {
-
- T[] tmp = Arrays.copyOf(input, input.length);
+ @SuppressWarnings("unchecked")
+ T[] tmp = (T[]) Array.newInstance(input.getClass().getComponentType(), input.length);
int count = 0;
for (T entry : input) {
@@ -41,7 +42,7 @@ public interface ResumableSet<T> {
}
}
- if (count != input.length) {
+ if (count > 0 && count != input.length) {
return Arrays.copyOf(tmp, count);
}