From 85334314da621070e0a2675cab01fcdb8cb650ba Mon Sep 17 00:00:00 2001 From: Steven Arzt Date: Wed, 15 Sep 2021 09:42:57 +0200 Subject: [PATCH] Check whether we have a next element instead of accessing it and catching the exception. Exceptions are notoriously slow in Java, so we want to avoid that. --- dexlib2/src/main/java/org/jf/util/CollectionUtils.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/dexlib2/src/main/java/org/jf/util/CollectionUtils.java b/dexlib2/src/main/java/org/jf/util/CollectionUtils.java index 23e23dc9..c2aa33e2 100644 --- a/dexlib2/src/main/java/org/jf/util/CollectionUtils.java +++ b/dexlib2/src/main/java/org/jf/util/CollectionUtils.java @@ -78,11 +78,10 @@ public class CollectionUtils { Iterator elements2 = it2.iterator(); for (T element1: it1) { T element2; - try { - element2 = elements2.next(); - } catch (NoSuchElementException ex) { + if (!elements2.hasNext()) { return 1; } + element2 = elements2.next(); int res = comparator.compare(element1, element2); if (res != 0) return res; } @@ -97,11 +96,10 @@ public class CollectionUtils { Iterator elements2 = it2.iterator(); for (T element1: it1) { T element2; - try { - element2 = elements2.next(); - } catch (NoSuchElementException ex) { + if (!elements2.hasNext()) { return 1; } + element2 = elements2.next(); int res = element1.compareTo(element2); if (res != 0) return res; }