From 609047eaccaec28139aa3dedcebbf81b4c7cd895 Mon Sep 17 00:00:00 2001 From: Jerry Lee Date: Sat, 17 Aug 2024 18:02:43 +0800 Subject: [PATCH] optimize: remove unnecessary copy for SINGLE cf input, since the subsequent `thenApply` operation return a new CF --- .../io/foldright/cffu/CompletableFutureUtils.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java index 21076219..45707cf9 100644 --- a/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java +++ b/cffu-core/src/main/java/io/foldright/cffu/CompletableFutureUtils.java @@ -1130,7 +1130,7 @@ public static CompletableFuture> allResultsFastFailOf(CompletionStag requireCfsAndEleNonNull(cfs); final int len = cfs.length; if (len == 0) return completedFuture(arrayList()); - // Defensive copy input cf to non-minimal-stage instance(toNonMinCfCopy) for SINGLE input + // convert input cf to non-minimal-stage instance(toNonMinCfCopy) for SINGLE input // in order to ensure that the returned cf is not minimal-stage CF instance(UnsupportedOperationException) if (len == 1) return toNonMinCf(cfs[0]).thenApply(CompletableFutureUtils::arrayList); @@ -1249,9 +1249,9 @@ public static CompletableFuture> allResultsOf(CompletionStage[] resultSetterCfs = createResultSetterCfs(cfs, result); @@ -1296,9 +1296,9 @@ public static CompletableFuture allFastFailOf(CompletionStage... cfs) { requireCfsAndEleNonNull(cfs); final int len = cfs.length; if (len == 0) return completedFuture(null); - // Defensive copy input cf to non-minimal-stage instance for SINGLE input in order to ensure that + // convert input cf to non-minimal-stage instance for SINGLE input in order to ensure that // the returned cf is not minimal-stage CF instance(UnsupportedOperationException) - if (len == 1) return toNonMinCfCopy(cfs[0]).thenApply(unused -> null); + if (len == 1) return toNonMinCf(cfs[0]).thenApply(unused -> null); final CompletableFuture[] successOrBeIncomplete = new CompletableFuture[len]; // NOTE: fill ONE MORE element of failedOrBeIncomplete LATER @@ -1345,9 +1345,9 @@ public static CompletableFuture allFastFailOf(CompletionStage... cfs) { public static CompletableFuture allOf(CompletionStage... cfs) { requireNonNull(cfs, "cfs is null"); if (cfs.length == 0) return completedFuture(null); - // Defensive copy input cf to non-minimal-stage instance(toNonMinCfCopy) for SINGLE input + // convert input cf to non-minimal-stage instance(toNonMinCfCopy) for SINGLE input // in order to ensure that the returned cf is not minimal-stage CF instance(UnsupportedOperationException) - if (cfs.length == 1) return toNonMinCfCopy(requireNonNull(cfs[0], "cf1 is null")).thenApply(unused -> null); + if (cfs.length == 1) return toNonMinCf(requireNonNull(cfs[0], "cf1 is null")).thenApply(unused -> null); return CompletableFuture.allOf(f_toCfArray(cfs)); }