Remove the duplication check in SupportedSurfaceCombination
It should be rare case to have duplicated items in the supported output sizes list. Doing the duplication check needs O(n^2) level of time. Remove the duplication check save the time for most cases.
Bug: 256737415
Test: SupportedSurfaceCombinationTest
Change-Id: Ib55b5f56edb14f8703b6237c4b191ea2bedfa08d
diff --git a/camera/camera-camera2/src/main/java/androidx/camera/camera2/internal/SupportedOutputSizesCollector.java b/camera/camera-camera2/src/main/java/androidx/camera/camera2/internal/SupportedOutputSizesCollector.java
index 02e0614..589530a 100644
--- a/camera/camera-camera2/src/main/java/androidx/camera/camera2/internal/SupportedOutputSizesCollector.java
+++ b/camera/camera-camera2/src/main/java/androidx/camera/camera2/internal/SupportedOutputSizesCollector.java
@@ -173,13 +173,7 @@
// result.
Arrays.sort(outputSizes, new CompareSizesByArea(true));
- // Removes the duplicate items
- List<Size> resultList = new ArrayList<>();
- for (Size size: outputSizes) {
- if (!resultList.contains(size)) {
- resultList.add(size);
- }
- }
+ List<Size> resultList = Arrays.asList(outputSizes);
if (resultList.isEmpty()) {
throw new IllegalArgumentException(
@@ -700,6 +694,12 @@
indexBigEnough = i;
} else {
+ // If duplicated miniBoundingSize items exist in the list, the size will be added
+ // into the removeSizes list. Removes it from the removeSizes list to keep the
+ // miniBoundingSize items in the final result list.
+ if (indexBigEnough >= 0) {
+ removeSizes.remove(supportedSizesList.get(indexBigEnough));
+ }
break;
}
}