Skip to content

Commit

Permalink
Remove unnecessary unknown value adaptation in ProtoAdapter
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 697786696
  • Loading branch information
l46kok authored and copybara-github committed Nov 21, 2024
1 parent b061eb8 commit 5cce232
Showing 1 changed file with 0 additions and 12 deletions.
12 changes: 0 additions & 12 deletions common/src/main/java/dev/cel/common/internal/ProtoAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.ImmutableMap.toImmutableMap;

import dev.cel.expr.ExprValue;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.primitives.Ints;
Expand Down Expand Up @@ -205,9 +204,6 @@ public Object adaptProtoToValue(MessageOrBuilder proto) {

@SuppressWarnings({"unchecked", "rawtypes"})
public Optional<Object> adaptFieldToValue(FieldDescriptor fieldDescriptor, Object fieldValue) {
if (isUnknown(fieldValue)) {
return Optional.of(fieldValue);
}
if (fieldDescriptor.isMapField()) {
Descriptor entryDescriptor = fieldDescriptor.getMessageType();
FieldDescriptor keyFieldDescriptor = entryDescriptor.findFieldByNumber(1);
Expand Down Expand Up @@ -255,9 +251,6 @@ public Optional<Object> adaptValueToFieldType(
if (isWrapperType(fieldDescriptor) && fieldValue.equals(NullValue.NULL_VALUE)) {
return Optional.empty();
}
if (isUnknown(fieldValue)) {
return Optional.of(fieldValue);
}
if (fieldDescriptor.isMapField()) {
Descriptor entryDescriptor = fieldDescriptor.getMessageType();
FieldDescriptor keyDescriptor = entryDescriptor.findFieldByNumber(1);
Expand Down Expand Up @@ -590,11 +583,6 @@ private static boolean isWrapperType(FieldDescriptor fieldDescriptor) {
return wellKnownProto != null && wellKnownProto.isWrapperType();
}

private static boolean isUnknown(Object object) {
return object instanceof ExprValue
&& ((ExprValue) object).getKindCase() == ExprValue.KindCase.UNKNOWN;
}

private static int intCheckedCast(long value) {
try {
return Ints.checkedCast(value);
Expand Down

0 comments on commit 5cce232

Please sign in to comment.