Use Class.cast instead of unchecked casts to eliminate @SuppressWarnings("unchecked") in TextFormat.parse overloads.
Shouldn't be a performance problem - this is only available in full runtime (not android) where hotspot has a class.cast intrinsic (and text proto parsing is relatively slow anyway, this won't be the bottleneck).
PiperOrigin-RevId: 970171466
Use Collection<?> for the sizing check to eliminate unchecked cast warning and narrow @SuppressWarnings("unchecked") to the specific ProtobufList fast-path assignment.
PiperOrigin-RevId: 970165037
In AbstractMessageLite.toByteArray(), check if getSerializedSize() == 0 and return Internal.EMPTY_BYTE_ARRAY directly instead of allocating a new 0-byte array and CodedOutputStream wrappers.
PiperOrigin-RevId: 970010400
Use Class.cast instead of an unchecked generic cast to avoid compiler warnings and ensure runtime type safety.
Not a big deal but a nice opportunity to remove a warning.
This is only used in the full runtime AFAIK, where hotspot has an intrinsic for Class.cast so shouldn't be a performance issue.
PiperOrigin-RevId: 969794451
0-length packed fields occur but are fairly rare since our serializers will emit nothing instead of emitting a 0-length packed field. But, there's little reason to leave inequality case behind since we're checking against <=0 anyway.
PiperOrigin-RevId: 967271476
In OSS Java protobuf generation, this change wraps the file descriptor initialization inside a nested static class named `InternalDescriptors`. This prevents statically initializing the generated file's outer class when only its descriptor is accessed, which avoids premature loading of dependencies like `DescriptorsProto` and `JavaFeaturesProto`.
PiperOrigin-RevId: 964796532
This is the test for an issue where if the 10th byte was 0x81 (a non-zero value with was accidentally included in cl/962791052 and submitted, which was intended to be submitted separately.
PiperOrigin-RevId: 963393786
Directly invoke getParserForClass and getDefaultInstance in GeneratedMessageLite instead of routing through dynamicMethod. This builds on the work added in cl/944139195.
This allows removing the GET_PARSER and GET_DEFAULT_INSTANCE switch cases from dynamicMethod in compiler/java/lite/message.cc and removing the corresponding enum values from MethodToInvoke.
Additionally, updates the Samsung bug fallback path in GeneratedMessageLite.getDefaultInstance to allocate an instance via UnsafeUtil without calling method getters on the uninitialized object, triggering static initialization (<clinit>) safely without reflection or method call cycles.
PiperOrigin-RevId: 962355079
* `protoc`: Included in zips alongside binary
* Java: Generated classes have been added to the Maven `util` artifact
* Ruby: Generated classes have been added to gems
* CMake: `.proto` files are included in installation
PiperOrigin-RevId: 957382561
Previously, for strings whose length prefix could span more than one varint
byte, the encoder walked the string twice: Utf8.encodedLength to size the
prefix, then Utf8.encode to write the bytes. Update this logic to just write
the string in one pass and avoid calling Utf8.encodedLength.
For ServerProcessor, the current optimal String.getBytes(UTF_8) is called. For
MobileProcessor, the string is written to the buffer directly with no
additional allocation first, and then the length is written as the prefix.
This approach is faster for mobile than Utf8.encodedLength, which requires
iterating over the string character by character. This approach is also
guaranteed to not overrun the buffer, because the buffer was already sized
using Utf8.encodedLength.
Message Runtime Before(ns) After(ns) Speedup
------------------------ ------- --------- --------- -------
google_message1 (228 B) JVM 253.8 199.4 1.26x
google_message1 ART 460.9 407.3 1.13x
google_message2 (85 KB) JVM 156309 130485 1.25x
google_message2 ART 201538 178130 1.13x
PiperOrigin-RevId: 955379320
This is achieved by making the recently-added `pushLimitBeforeMessage` and `popLimitAfterMessage` package-protected so that it can be used by CodedInputStreamReader which was otherwise doing its own pushing-and-popping without properly checking these boundary conditions.
PiperOrigin-RevId: 955353136
Check instanceof LazyStringArrayList as that'll be the most common case and it's cheap (a pointer on the klass) rather than a loop on the set of interfaces.
PiperOrigin-RevId: 954927009
I think it's most common that we're comparing protos against protos, where we'll be comparing ProtobufArrayLists against ProtobufArrayLists.
It's faster to check instanceof SomeFinalClass (a pointer comparison) than to check instanceof SomeInterface (walk a set of interfaces)
PiperOrigin-RevId: 954892499
Messages without required fields omit GET_MEMOIZED_IS_INITIALIZED and SET_MEMOIZED_IS_INITIALIZED switch cases from dynamicMethod to minimize gencode size.
For those messages, dynamicMethod returns null, skipping memoization and delegating directly to MessageSchema.isInitialized(), which evaluates to true in O(1) time.
PiperOrigin-RevId: 954754880
Checking if the high bit is set is equivalent to checking if the value is negative. This change avoids a bitwise AND instruction in the generated assembly.
Before/After:
```
boolean FizzBuzz.isMutable() [20 bytes]
0x000040c0 ldr w0, [x1, #12]
0x000040c4 and w0, w0, #0x80000000 <--- THIS INSTRUCTION CAN GO
0x000040c8 cmp w0, #0x0 (0)
0x000040cc cset w0, ne
0x000040d0 ret
boolean FizzBuzz.isMutable2() [16 bytes]
0x000040e0 ldr w0, [x1, #12]
0x000040e4 cmp w0, #0x0 (0)
0x000040e8 cset w0, lt
0x000040ec ret
```
PiperOrigin-RevId: 948755487
Introduce reusable `SequentialEnumVerifier` and `BitmaskEnumVerifier` in the runtime and instantiate them inline within the generated message schema to eliminate custom nested verifier classes and enable stripping unused enum classes.
PiperOrigin-RevId: 947467062
Introduce reusable `SequentialEnumVerifier` and `BitmaskEnumVerifier` in the runtime and instantiate them inline within the generated message schema to eliminate custom nested verifier classes and enable stripping unused enum classes.
PiperOrigin-RevId: 947383511
This fixes a minor style guide issue where generic classes should end in
a single uppercase chart.
We could have gone with 'B' but there are so many generics in here that
it seems reasonable to keep a longer name.
PiperOrigin-RevId: 947378949
Fixes style guide rule that generic types should end in a single
uppercase char.
I could have made this `M` but it feels like there's enough generics in here that I narrowly chose the larger name.
PiperOrigin-RevId: 947370402