From cb2fdb8bb2cc4247926e1359de6f0280b909a1d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petar=20=C5=A0egina?= Date: Wed, 27 Sep 2017 20:18:03 +0100 Subject: [PATCH] Replace stream operation with simple iteration Although the stream approach is elegant, we already have a simple loop iterating over the rectangles which we can reuse for finding the starting rectangle and save the overhead of the stream / additional iteration over the rectangles. Test: manual - verify smart select still works Change-Id: I4e4195ded4268a7c18ad1b0bc352a9c273396932 --- core/java/android/widget/SmartSelectSprite.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/core/java/android/widget/SmartSelectSprite.java b/core/java/android/widget/SmartSelectSprite.java index 27b93bc74969d..fe4f76e1aa0c5 100644 --- a/core/java/android/widget/SmartSelectSprite.java +++ b/core/java/android/widget/SmartSelectSprite.java @@ -374,21 +374,21 @@ final class SmartSelectSprite { final List shapes = new LinkedList<>(); final List cornerAnimators = new LinkedList<>(); - final RectF centerRectangle = destinationRectangles - .stream() - .filter((r) -> contains(r, start)) - .findFirst() - .orElseThrow(() -> new IllegalArgumentException( - "Center point is not inside any of the rectangles!")); + RectF centerRectangle = null; int startingOffset = 0; for (RectF rectangle : destinationRectangles) { - if (rectangle.equals(centerRectangle)) { + if (contains(rectangle, start)) { + centerRectangle = rectangle; break; } startingOffset += rectangle.width(); } + if (centerRectangle == null) { + throw new IllegalArgumentException("Center point is not inside any of the rectangles!"); + } + startingOffset += start.x - centerRectangle.left; final float centerRectangleHalfHeight = centerRectangle.height() / 2;