From 00d0938f61c0698d0c30a76d1838e2514c9b19f8 Mon Sep 17 00:00:00 2001 From: Googler Date: Thu, 14 Apr 2016 21:25:55 +0000 Subject: Use Iterables.addAll() in SkylarkList. It is probably more efficient in the common case where the Iterable is a collection. String and list handling in Skylark results in a *lot* of calls to this method, and the use of addAll should reduce the amount of copying and GCing that needs to occur. An alternative would be to change the underlying type of SkylarkList from ArrayList to LinkedList, which would reduce the copying and GCing due to list concatenation even more. There is probably a downside to that but it is not clear if it is significant. -- MOS_MIGRATED_REVID=119891128 --- src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java index 60d6754766..5855824bb1 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java @@ -282,9 +282,7 @@ import javax.annotation.Nullable; * Assumes that you already checked for Mutability. */ private void addAllUnsafe(Iterable elements) { - for (E elem : elements) { - contents.add(elem); - } + Iterables.addAll(contents, elements); } @Override -- cgit v1.2.3