This yields several benefits:
1. The code no longer needs to be bootstrapped (since it no longer depends on upb reflection).
2. The upb code generator no longer depends on libprotobuf at all (except for `code_generator_lite.{h,cc}`, which is just one .cc file and has no deps).
PiperOrigin-RevId: 672280579
This allows reusing some common string mapping functions in a lightweight library that does not depend on the rest of C++ protobuf.
PiperOrigin-RevId: 672079929
This change renames the helper functions to HasFieldSingular(), SetHasBit(),
ClearHasBit(), and SwapHasBit(), which should hopefully be less confusing.
First of all, the HasBit(), SetBit(), ClearBit(), and SwapBit() methods are all
private so they are easier to change than a public-facing API.
The function named HasBit is called for both proto2 and proto3 fields. For
proto2 fields, it returns true if and only if the hasbit is set -- i.e. if the
field is present. For proto3 fields, it returns true if and only if the field
is nonempty -- i.e. if the field is present.
See documentation here for what "field presence" means:
https://github.com/protocolbuffers/protobuf/blob/main/docs/field_presence.md
Note that in the proto3 case, what this function is doing has nothing to do
with bits!
The name HasFieldSingular is chosen to emphasize the fact that this function
has the same semantics has HasField, only that it's narrowly applied to
"singular" (i.e., non-repeating, non-oneof, non-weak) fields.
HasField itself is not a great name -- IsPresent is probably more appripriate
-- but it is a public API and therefore hard to change. This change at least
makes the two share a similar name.
(I considered `HasPresence` too but that also leaves room for ambiguity: "has
presence" might be interpreted to refer to whether a field is an explicit
presence field or an implicit presence field).
The other helper functions here do manipulate the hasbit directly. Because of
this, they should just make it obvious in the name.
PiperOrigin-RevId: 671966727
This works around a ReturnValueIgnored errorprone issue. There were several other places where this was already done, this is just catching up the remaining two places.
PiperOrigin-RevId: 671878499
<iostream> embeds a global constructor (to initialize std::cout and such), typically `static ios_base::Init __ioinit;` in libstdc++).
Replacing it by <istream>, <ostream> (or both) when possible has an impact on the number of global constructors involved (and thus on the number of instructions executed at startup).
Closes#18069
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/18069 from serge-sans-paille:feature/remove-useless-iostream 42d1458235
PiperOrigin-RevId: 671788440
This is a no-op cleanup. The methods are package-private so shouldn't be an API break.
I'm about to add some more tests here. This just makes writing the tests easier , as they don't have to catch IOException any more.
PiperOrigin-RevId: 671592242
This ensures that the test for exponential resizing (for amortized linear time)
actually looks exponential.
Previously, we saw in tests that if we add 1000 element-lists 10x in a row, sometimes
we grow the backing array by 6000 bytes twice in a row. (12024 - 18024 - 24024).
Now the test looks much more consistently exponential.
PiperOrigin-RevId: 671577283
Previously, we only make extensions immutable if they were in the FieldSet's
array, maximum size 16. The overflow entries in the TreeMap weren't made
immutable.
PiperOrigin-RevId: 671564444
I will fix this test in the next CL.
This test runs on both `GeneratedMessage` and `GeneratedMessageLite` variants, so we need to first check if `nested instanceof GeneratedMessageLite`, otherwise on the full-variant test, we get `isMutable()` method found on `GeneratedMessage`.
PiperOrigin-RevId: 671563318
This turned out to be much easier for upb than for C++. This CL pretty much
just does a cut-and-paste of the `ProxiedInMapValue` implementation from the
upb code generator to the runtime. This should help a bit with code size since
it removes the need to generate six `ProxiedInMapValue` implementations per
message.
PiperOrigin-RevId: 671438289
Import both the public and private header into impls when the
private is needed.
Also update the tests to use more complete imports.
PiperOrigin-RevId: 671388271
This past reliance doesn't work well with Swift, and the sources
were trying to over hand optimize to minimize rebuilds, and that
likely isn't worth the trouble, so explicit imports.
The remaining places that still use them are where they are
needed within the header to deal with relationships between
the local definitions or where there is a cycle between the
headers and it allows either one to be imported first and still
get a complete definition in the using context.
PiperOrigin-RevId: 671379912
This version works where both sides are the same message, messageview or messagemut type, but not any mix of them (e.g. cannot compare a message against its corresponding view).
PiperOrigin-RevId: 671091099