Skip to content

Commit 0178064

Browse files
Avoid more array wrapping as list
PiperOrigin-RevId: 807696716
1 parent 68a2efb commit 0178064

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

java/core/src/main/java/com/google/protobuf/Descriptors.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,7 @@ private void crossLink() throws DescriptorValidationException {
22362236
case ENUM:
22372237
// We guarantee elsewhere that an enum type always has at least
22382238
// one possible value.
2239-
defaultValue = getEnumType().getValues().get(0);
2239+
defaultValue = getEnumType().getValue(0);
22402240
break;
22412241
case MESSAGE:
22422242
defaultValue = null;
@@ -2380,6 +2380,14 @@ public List<EnumValueDescriptor> getValues() {
23802380
return Collections.unmodifiableList(Arrays.asList(values));
23812381
}
23822382

2383+
public int getValueCount() {
2384+
return values.length;
2385+
}
2386+
2387+
public EnumValueDescriptor getValue(int index) {
2388+
return values[index];
2389+
}
2390+
23832391
/** Determines if the given field number is reserved. */
23842392
public boolean isReservedNumber(final int number) {
23852393
for (final EnumDescriptorProto.EnumReservedRange range : proto.getReservedRangeList()) {

src/google/protobuf/compiler/java/internal_helpers.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ void GenerateLarge(
306306
" }\n");
307307
}
308308
printer->Print(
309-
" return getDescriptor().getValues().get(index());\n"
309+
" return getDescriptor().getValue(index());\n"
310310
"}\n"
311311
"public final com.google.protobuf.Descriptors.EnumDescriptor\n"
312312
" getDescriptorForType() {\n"
@@ -328,15 +328,15 @@ void GenerateLarge(
328328
// immutable outer class).
329329
printer->Print(
330330
" return "
331-
"$file$.getDescriptor().getEnumTypes().get($index$);\n",
331+
"$file$.getDescriptor().getEnumType($index$);\n",
332332
"file",
333333
name_resolver->GetClassName(descriptor->file(),
334334
immutable_api),
335335
"index", absl::StrCat(descriptor->index()));
336336
} else {
337337
printer->Print(
338338
" return "
339-
"$parent$.$descriptor$.getEnumTypes().get($index$);\n",
339+
"$parent$.$descriptor$.getEnumType($index$);\n",
340340
"parent",
341341
name_resolver->GetClassName(descriptor->containing_type(),
342342
immutable_api),

0 commit comments

Comments
 (0)