Repository: shiro Updated Branches: refs/heads/master cc77f33d1 -> 01b35626a
SHIRO-566 Use Collections wrappers to save memory and cpu. Fixes #19 Project: http://git-wip-us.apache.org/repos/asf/shiro/repo Commit: http://git-wip-us.apache.org/repos/asf/shiro/commit/da4c167b Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/da4c167b Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/da4c167b Branch: refs/heads/master Commit: da4c167b924af4440e033b42a3b8e691f0e5d8cd Parents: cc77f33 Author: Matt Bishop <[email protected]> Authored: Mon May 30 10:47:28 2016 -0700 Committer: Brian Demers <[email protected]> Committed: Wed Jun 29 14:11:44 2016 -0700 ---------------------------------------------------------------------- .../java/org/apache/shiro/util/CollectionUtils.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/shiro/blob/da4c167b/lang/src/main/java/org/apache/shiro/util/CollectionUtils.java ---------------------------------------------------------------------- diff --git a/lang/src/main/java/org/apache/shiro/util/CollectionUtils.java b/lang/src/main/java/org/apache/shiro/util/CollectionUtils.java index 4b9c8e4..67e9901 100644 --- a/lang/src/main/java/org/apache/shiro/util/CollectionUtils.java +++ b/lang/src/main/java/org/apache/shiro/util/CollectionUtils.java @@ -18,7 +18,7 @@ */ package org.apache.shiro.util; -import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedHashSet; @@ -39,6 +39,11 @@ public class CollectionUtils { if (elements == null || elements.length == 0) { return Collections.emptySet(); } + + if (elements.length == 1) { + return Collections.singleton(elements[0]); + } + LinkedHashSet<E> set = new LinkedHashSet<E>(elements.length * 4 / 3 + 1); Collections.addAll(set, elements); return set; @@ -97,11 +102,9 @@ public class CollectionUtils { if (elements == null || elements.length == 0) { return Collections.emptyList(); } - // Avoid integer overflow when a large array is passed in - int capacity = computeListCapacity(elements.length); - ArrayList<E> list = new ArrayList<E>(capacity); - Collections.addAll(list, elements); - return list; + + // Integer overflow does not occur when a large array is passed in because the list array already exists + return Arrays.asList(elements); } /*public static <E> Deque<E> asDeque(E... elements) {
