aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax
diff options
context:
space:
mode:
authorGravatar Taras Tsugrii <ttsugrii@fb.com>2018-07-31 10:43:23 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-31 10:44:49 -0700
commit4b8d0ae907749440edb8f5f899e570d58e4d963b (patch)
tree12c1b2bca4477dcf14230b591c9b730afd539bf9 /src/main/java/com/google/devtools/build/lib/syntax
parent3852edd46cb777191728c42e62873e39fd9fe4c4 (diff)
[Skylark] Avoid unnecessary copyOf invocations.
According to async-profiler, about 50% of `Tuple.getSlice` method invocation is spent in `ImmutableList.copyOf` which is completely unnecessary for cases when an `ImmutableList` instance is passed. Closes #5699. PiperOrigin-RevId: 206787490
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/SkylarkList.java10
1 files changed, 10 insertions, 0 deletions
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 8900397476..f541c7735b 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
@@ -627,6 +627,16 @@ public abstract class SkylarkList<E> extends BaseMutableList<E>
return create(ImmutableList.<T>copyOf(contents));
}
+ /**
+ * Returns a {@code Tuple} whose items are given by an immutable list.
+ *
+ * <p>This method is a specialization of a {@link #copyOf(Iterable)} that avoids an unnecessary
+ * {@code copyOf} invocation.
+ */
+ public static <T> Tuple<T> copyOf(ImmutableList<T> contents) {
+ return create(contents);
+ }
+
/** Returns a {@code Tuple} with the given items. */
public static <T> Tuple<T> of(T... elements) {
return Tuple.create(ImmutableList.copyOf(elements));