|
@@ -1015,8 +1015,7 @@ struct FieldNumberSorter {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
-bool IsIndexInHasBitSet(const uint32* has_bit_set,
|
|
|
|
- uint32 has_bit_index) {
|
|
|
|
|
|
+bool IsIndexInHasBitSet(const uint32* has_bit_set, uint32 has_bit_index) {
|
|
GOOGLE_DCHECK_NE(has_bit_index, ~0u);
|
|
GOOGLE_DCHECK_NE(has_bit_index, ~0u);
|
|
return ((has_bit_set[has_bit_index / 32] >> (has_bit_index % 32)) &
|
|
return ((has_bit_set[has_bit_index / 32] >> (has_bit_index % 32)) &
|
|
static_cast<uint32>(1)) != 0;
|
|
static_cast<uint32>(1)) != 0;
|
|
@@ -1874,8 +1873,8 @@ uint32* Reflection::MutableHasBits(Message* message) const {
|
|
return GetPointerAtOffset<uint32>(message, schema_.HasBitsOffset());
|
|
return GetPointerAtOffset<uint32>(message, schema_.HasBitsOffset());
|
|
}
|
|
}
|
|
|
|
|
|
-uint32 Reflection::GetOneofCase(
|
|
|
|
- const Message& message, const OneofDescriptor* oneof_descriptor) const {
|
|
|
|
|
|
+uint32 Reflection::GetOneofCase(const Message& message,
|
|
|
|
+ const OneofDescriptor* oneof_descriptor) const {
|
|
return GetConstRefAtOffset<uint32>(
|
|
return GetConstRefAtOffset<uint32>(
|
|
message, schema_.GetOneofCaseOffset(oneof_descriptor));
|
|
message, schema_.GetOneofCaseOffset(oneof_descriptor));
|
|
}
|
|
}
|
|
@@ -1886,8 +1885,7 @@ uint32* Reflection::MutableOneofCase(
|
|
message, schema_.GetOneofCaseOffset(oneof_descriptor));
|
|
message, schema_.GetOneofCaseOffset(oneof_descriptor));
|
|
}
|
|
}
|
|
|
|
|
|
-const ExtensionSet& Reflection::GetExtensionSet(
|
|
|
|
- const Message& message) const {
|
|
|
|
|
|
+const ExtensionSet& Reflection::GetExtensionSet(const Message& message) const {
|
|
return GetConstRefAtOffset<ExtensionSet>(message,
|
|
return GetConstRefAtOffset<ExtensionSet>(message,
|
|
schema_.GetExtensionSetOffset());
|
|
schema_.GetExtensionSetOffset());
|
|
}
|
|
}
|
|
@@ -1901,8 +1899,8 @@ Arena* Reflection::GetArena(Message* message) const {
|
|
return GetInternalMetadataWithArena(*message).arena();
|
|
return GetInternalMetadataWithArena(*message).arena();
|
|
}
|
|
}
|
|
|
|
|
|
-const InternalMetadataWithArena&
|
|
|
|
-Reflection::GetInternalMetadataWithArena(const Message& message) const {
|
|
|
|
|
|
+const InternalMetadataWithArena& Reflection::GetInternalMetadataWithArena(
|
|
|
|
+ const Message& message) const {
|
|
return GetConstRefAtOffset<InternalMetadataWithArena>(
|
|
return GetConstRefAtOffset<InternalMetadataWithArena>(
|
|
message, schema_.GetMetadataOffset());
|
|
message, schema_.GetMetadataOffset());
|
|
}
|
|
}
|
|
@@ -1920,7 +1918,7 @@ const Type& Reflection::DefaultRaw(const FieldDescriptor* field) const {
|
|
|
|
|
|
// Simple accessors for manipulating has_bits_.
|
|
// Simple accessors for manipulating has_bits_.
|
|
bool Reflection::HasBit(const Message& message,
|
|
bool Reflection::HasBit(const Message& message,
|
|
- const FieldDescriptor* field) const {
|
|
|
|
|
|
+ const FieldDescriptor* field) const {
|
|
GOOGLE_DCHECK(!field->options().weak());
|
|
GOOGLE_DCHECK(!field->options().weak());
|
|
if (schema_.HasHasbits()) {
|
|
if (schema_.HasHasbits()) {
|
|
return IsIndexInHasBitSet(GetHasBits(message), schema_.HasBitIndex(field));
|
|
return IsIndexInHasBitSet(GetHasBits(message), schema_.HasBitIndex(field));
|
|
@@ -1980,8 +1978,7 @@ bool Reflection::HasBit(const Message& message,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void Reflection::SetBit(Message* message,
|
|
|
|
- const FieldDescriptor* field) const {
|
|
|
|
|
|
+void Reflection::SetBit(Message* message, const FieldDescriptor* field) const {
|
|
GOOGLE_DCHECK(!field->options().weak());
|
|
GOOGLE_DCHECK(!field->options().weak());
|
|
if (!schema_.HasHasbits()) {
|
|
if (!schema_.HasHasbits()) {
|
|
return;
|
|
return;
|
|
@@ -1992,7 +1989,7 @@ void Reflection::SetBit(Message* message,
|
|
}
|
|
}
|
|
|
|
|
|
void Reflection::ClearBit(Message* message,
|
|
void Reflection::ClearBit(Message* message,
|
|
- const FieldDescriptor* field) const {
|
|
|
|
|
|
+ const FieldDescriptor* field) const {
|
|
GOOGLE_DCHECK(!field->options().weak());
|
|
GOOGLE_DCHECK(!field->options().weak());
|
|
if (!schema_.HasHasbits()) {
|
|
if (!schema_.HasHasbits()) {
|
|
return;
|
|
return;
|
|
@@ -2003,7 +2000,7 @@ void Reflection::ClearBit(Message* message,
|
|
}
|
|
}
|
|
|
|
|
|
void Reflection::SwapBit(Message* message1, Message* message2,
|
|
void Reflection::SwapBit(Message* message1, Message* message2,
|
|
- const FieldDescriptor* field) const {
|
|
|
|
|
|
+ const FieldDescriptor* field) const {
|
|
GOOGLE_DCHECK(!field->options().weak());
|
|
GOOGLE_DCHECK(!field->options().weak());
|
|
if (!schema_.HasHasbits()) {
|
|
if (!schema_.HasHasbits()) {
|
|
return;
|
|
return;
|
|
@@ -2027,24 +2024,24 @@ bool Reflection::HasOneof(const Message& message,
|
|
}
|
|
}
|
|
|
|
|
|
bool Reflection::HasOneofField(const Message& message,
|
|
bool Reflection::HasOneofField(const Message& message,
|
|
- const FieldDescriptor* field) const {
|
|
|
|
|
|
+ const FieldDescriptor* field) const {
|
|
return (GetOneofCase(message, field->containing_oneof()) == field->number());
|
|
return (GetOneofCase(message, field->containing_oneof()) == field->number());
|
|
}
|
|
}
|
|
|
|
|
|
void Reflection::SetOneofCase(Message* message,
|
|
void Reflection::SetOneofCase(Message* message,
|
|
- const FieldDescriptor* field) const {
|
|
|
|
|
|
+ const FieldDescriptor* field) const {
|
|
*MutableOneofCase(message, field->containing_oneof()) = field->number();
|
|
*MutableOneofCase(message, field->containing_oneof()) = field->number();
|
|
}
|
|
}
|
|
|
|
|
|
void Reflection::ClearOneofField(Message* message,
|
|
void Reflection::ClearOneofField(Message* message,
|
|
- const FieldDescriptor* field) const {
|
|
|
|
|
|
+ const FieldDescriptor* field) const {
|
|
if (HasOneofField(*message, field)) {
|
|
if (HasOneofField(*message, field)) {
|
|
ClearOneof(message, field->containing_oneof());
|
|
ClearOneof(message, field->containing_oneof());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void Reflection::ClearOneof(
|
|
|
|
- Message* message, const OneofDescriptor* oneof_descriptor) const {
|
|
|
|
|
|
+void Reflection::ClearOneof(Message* message,
|
|
|
|
+ const OneofDescriptor* oneof_descriptor) const {
|
|
// TODO(jieluo): Consider to cache the unused object instead of deleting
|
|
// TODO(jieluo): Consider to cache the unused object instead of deleting
|
|
// it. It will be much faster if an application switches a lot from
|
|
// it. It will be much faster if an application switches a lot from
|
|
// a few oneof fields. Time/space tradeoff
|
|
// a few oneof fields. Time/space tradeoff
|
|
@@ -2118,13 +2115,13 @@ void* Reflection::MutableRawRepeatedString(Message* message,
|
|
// used for all types except messages.
|
|
// used for all types except messages.
|
|
template <typename Type>
|
|
template <typename Type>
|
|
const Type& Reflection::GetField(const Message& message,
|
|
const Type& Reflection::GetField(const Message& message,
|
|
- const FieldDescriptor* field) const {
|
|
|
|
|
|
+ const FieldDescriptor* field) const {
|
|
return GetRaw<Type>(message, field);
|
|
return GetRaw<Type>(message, field);
|
|
}
|
|
}
|
|
|
|
|
|
template <typename Type>
|
|
template <typename Type>
|
|
void Reflection::SetField(Message* message, const FieldDescriptor* field,
|
|
void Reflection::SetField(Message* message, const FieldDescriptor* field,
|
|
- const Type& value) const {
|
|
|
|
|
|
+ const Type& value) const {
|
|
if (field->containing_oneof() && !HasOneofField(*message, field)) {
|
|
if (field->containing_oneof() && !HasOneofField(*message, field)) {
|
|
ClearOneof(message, field->containing_oneof());
|
|
ClearOneof(message, field->containing_oneof());
|
|
}
|
|
}
|
|
@@ -2135,7 +2132,7 @@ void Reflection::SetField(Message* message, const FieldDescriptor* field,
|
|
|
|
|
|
template <typename Type>
|
|
template <typename Type>
|
|
Type* Reflection::MutableField(Message* message,
|
|
Type* Reflection::MutableField(Message* message,
|
|
- const FieldDescriptor* field) const {
|
|
|
|
|
|
+ const FieldDescriptor* field) const {
|
|
field->containing_oneof() ? SetOneofCase(message, field)
|
|
field->containing_oneof() ? SetOneofCase(message, field)
|
|
: SetBit(message, field);
|
|
: SetBit(message, field);
|
|
return MutableRaw<Type>(message, field);
|
|
return MutableRaw<Type>(message, field);
|
|
@@ -2143,29 +2140,29 @@ Type* Reflection::MutableField(Message* message,
|
|
|
|
|
|
template <typename Type>
|
|
template <typename Type>
|
|
const Type& Reflection::GetRepeatedField(const Message& message,
|
|
const Type& Reflection::GetRepeatedField(const Message& message,
|
|
- const FieldDescriptor* field,
|
|
|
|
- int index) const {
|
|
|
|
|
|
+ const FieldDescriptor* field,
|
|
|
|
+ int index) const {
|
|
return GetRaw<RepeatedField<Type> >(message, field).Get(index);
|
|
return GetRaw<RepeatedField<Type> >(message, field).Get(index);
|
|
}
|
|
}
|
|
|
|
|
|
template <typename Type>
|
|
template <typename Type>
|
|
const Type& Reflection::GetRepeatedPtrField(const Message& message,
|
|
const Type& Reflection::GetRepeatedPtrField(const Message& message,
|
|
- const FieldDescriptor* field,
|
|
|
|
- int index) const {
|
|
|
|
|
|
+ const FieldDescriptor* field,
|
|
|
|
+ int index) const {
|
|
return GetRaw<RepeatedPtrField<Type> >(message, field).Get(index);
|
|
return GetRaw<RepeatedPtrField<Type> >(message, field).Get(index);
|
|
}
|
|
}
|
|
|
|
|
|
template <typename Type>
|
|
template <typename Type>
|
|
void Reflection::SetRepeatedField(Message* message,
|
|
void Reflection::SetRepeatedField(Message* message,
|
|
- const FieldDescriptor* field,
|
|
|
|
- int index, Type value) const {
|
|
|
|
|
|
+ const FieldDescriptor* field, int index,
|
|
|
|
+ Type value) const {
|
|
MutableRaw<RepeatedField<Type> >(message, field)->Set(index, value);
|
|
MutableRaw<RepeatedField<Type> >(message, field)->Set(index, value);
|
|
}
|
|
}
|
|
|
|
|
|
template <typename Type>
|
|
template <typename Type>
|
|
Type* Reflection::MutableRepeatedField(Message* message,
|
|
Type* Reflection::MutableRepeatedField(Message* message,
|
|
- const FieldDescriptor* field,
|
|
|
|
- int index) const {
|
|
|
|
|
|
+ const FieldDescriptor* field,
|
|
|
|
+ int index) const {
|
|
RepeatedPtrField<Type>* repeated =
|
|
RepeatedPtrField<Type>* repeated =
|
|
MutableRaw<RepeatedPtrField<Type> >(message, field);
|
|
MutableRaw<RepeatedPtrField<Type> >(message, field);
|
|
return repeated->Mutable(index);
|
|
return repeated->Mutable(index);
|
|
@@ -2173,13 +2170,13 @@ Type* Reflection::MutableRepeatedField(Message* message,
|
|
|
|
|
|
template <typename Type>
|
|
template <typename Type>
|
|
void Reflection::AddField(Message* message, const FieldDescriptor* field,
|
|
void Reflection::AddField(Message* message, const FieldDescriptor* field,
|
|
- const Type& value) const {
|
|
|
|
|
|
+ const Type& value) const {
|
|
MutableRaw<RepeatedField<Type> >(message, field)->Add(value);
|
|
MutableRaw<RepeatedField<Type> >(message, field)->Add(value);
|
|
}
|
|
}
|
|
|
|
|
|
template <typename Type>
|
|
template <typename Type>
|
|
Type* Reflection::AddField(Message* message,
|
|
Type* Reflection::AddField(Message* message,
|
|
- const FieldDescriptor* field) const {
|
|
|
|
|
|
+ const FieldDescriptor* field) const {
|
|
RepeatedPtrField<Type>* repeated =
|
|
RepeatedPtrField<Type>* repeated =
|
|
MutableRaw<RepeatedPtrField<Type> >(message, field);
|
|
MutableRaw<RepeatedPtrField<Type> >(message, field);
|
|
return repeated->Add();
|
|
return repeated->Add();
|