Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ public Iterator<B> iterator() {

@Override
public Object[] toArray() {
return delegate.stream().map(baseEl -> converter().convert(baseEl)).toArray();
Object[] result = new Object[size()];
int i = 0;
for (A a : delegate) {
result[i++] = converter().convert(a);
}
return result;
}

@Override
Expand Down
25 changes: 20 additions & 5 deletions runtime/src/main/java/dev/cel/runtime/Activation.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,9 @@ public static Activation copyOf(Map<String, ?> map) {
final ImmutableMap<String, Object> copy =
(map instanceof ImmutableMap)
? (ImmutableMap<String, Object>) map
: map.entrySet().stream()
// ImmutableMaps are null-hostile, but the Activation is not, so make sure that null
// values and entries are skipped.
.filter(entry -> entry.getKey() != null && entry.getValue() != null)
.collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
: // ImmutableMaps are null-hostile, but the Activation is not, so make sure that null
// values and entries are skipped.
toImmutableMapFilteringNulls(map);
return new Activation() {

@Override
Expand All @@ -128,6 +126,23 @@ public String toString() {
};
}

/**
* Creates an {@link ImmutableMap} from the given {@link Map} filtering out null keys and values.
*
* <p>Used instead of the one-liner for performance reasons.
*/
private static ImmutableMap<String, Object> toImmutableMapFilteringNulls(Map<String, ?> map) {
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builderWithExpectedSize(map.size());
for (Map.Entry<String, ?> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (key != null && value != null) {
builder.put(key, value);
}
}
return builder.buildOrThrow();
}

/**
* Extends this binder by another binder. Names will be attempted to first resolve in the other
* binder, then in this binder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,10 @@ private IntermediateResult dispatchCall(
return IntermediateResult.create(attr, unknowns.get());
}

Object[] argArray = Arrays.stream(argResults).map(IntermediateResult::value).toArray();
Object[] argArray = new Object[argResults.length];
for (int i = 0; i < argResults.length; i++) {
argArray[i] = argResults[i].value();
}
ImmutableList<String> overloadIds = reference.overloadIds();
CelResolvedOverload overload =
findOverloadOrThrow(frame, expr, callExpr.function(), overloadIds, argArray);
Expand Down
Loading