Skip to content

Commit

Permalink
Iterate over filetypes without creating an iterator. As this is some…
Browse files Browse the repository at this point in the history
…times

    used in the inner loop when iterating over large sets, the amount of garbage
    created here is important.

    RELNOTES: None.
    PiperOrigin-RevId: 240734371
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent 1e9dc2c commit 2cc9928
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec.VisibleForSerialization;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.concurrent.Immutable;

Expand All @@ -43,12 +44,12 @@ public static FileType of(final String ext) {
return new SingletonFileType(ext);
}

public static FileType of(final ImmutableList<String> extensions) {
return new ListFileType(extensions);
public static FileType of(final List<String> extensions) {
return new ListFileType(ImmutableList.copyOf(extensions));
}

public static FileType of(final String... extensions) {
return of(ImmutableList.copyOf(extensions));
return of(Arrays.asList(extensions));
}

@AutoCodec.VisibleForSerialization
Expand All @@ -67,7 +68,7 @@ public boolean apply(String path) {
}

@Override
public ImmutableList<String> getExtensions() {
public List<String> getExtensions() {
return ImmutableList.of(ext);
}
}
Expand All @@ -94,8 +95,8 @@ public boolean apply(String path) {
}

@Override
public ImmutableList<String> getExtensions() {
return extensions;
public List<String> getExtensions() {
return ImmutableList.copyOf(extensions);
}

@Override
Expand All @@ -121,12 +122,12 @@ public String toString() {

/**
* Get a list of filename extensions this matcher handles. The first entry in the list (if
* available) is the primary extension that code can use to construct output file names. The list
* can be empty for some matchers.
* available) is the primary extension that code can use to construct output file names.
* The list can be empty for some matchers.
*
* @return a list of filename extensions
*/
public ImmutableList<String> getExtensions() {
public List<String> getExtensions() {
return ImmutableList.of();
}

Expand Down

0 comments on commit 2cc9928

Please sign in to comment.