1818import java .util .ArrayList ;
1919import java .util .Arrays ;
2020import java .util .Collection ;
21- import java .util .List ;
21+ import java .util .HashSet ;
22+ import java .util .Set ;
2223
2324/**
2425 * An internal representation used for fast accumulation of unknown expr IDs and attributes. For
2728 */
2829final class AccumulatedUnknowns {
2930 private static final int MAX_UNKNOWN_ATTRIBUTE_SIZE = 500_000 ;
30- private final List <Long > exprIds ;
31- private final List <CelAttribute > attributes ;
31+ private final Set <Long > exprIds ;
32+ private final Set <CelAttribute > attributes ;
3233
33- List <Long > exprIds () {
34+ Set <Long > exprIds () {
3435 return exprIds ;
3536 }
3637
37- List <CelAttribute > attributes () {
38+ Set <CelAttribute > attributes () {
3839 return attributes ;
3940 }
4041
@@ -55,19 +56,20 @@ static AccumulatedUnknowns create(Collection<Long> ids) {
5556 }
5657
5758 static AccumulatedUnknowns create (Collection <Long > exprIds , Collection <CelAttribute > attributes ) {
58- return new AccumulatedUnknowns (new ArrayList <>(exprIds ), new ArrayList <>(attributes ));
59+ return new AccumulatedUnknowns (new HashSet <>(exprIds ), new HashSet <>(attributes ));
5960 }
6061
6162 private static void enforceMaxAttributeSize (
62- List <CelAttribute > lhsAttributes , List <CelAttribute > rhsAttributes ) {
63- int totalSize = lhsAttributes .size () + rhsAttributes .size ();
64- if (totalSize > MAX_UNKNOWN_ATTRIBUTE_SIZE ) {
63+ Set <CelAttribute > lhsAttributes , Set <CelAttribute > rhsAttributes ) {
64+ if (lhsAttributes .size () + rhsAttributes .size () > MAX_UNKNOWN_ATTRIBUTE_SIZE ) {
6565 throw new IllegalArgumentException (
66- "Exceeded maximum allowed unknown attributes: " + totalSize );
66+ String .format (
67+ "Exceeded maximum allowed unknown attributes when merging: %s, %s" ,
68+ lhsAttributes .size (), rhsAttributes .size ()));
6769 }
6870 }
6971
70- private AccumulatedUnknowns (List <Long > exprIds , List <CelAttribute > attributes ) {
72+ private AccumulatedUnknowns (Set <Long > exprIds , Set <CelAttribute > attributes ) {
7173 this .exprIds = exprIds ;
7274 this .attributes = attributes ;
7375 }
0 commit comments