Skip to content

Commit f6b3708

Browse files
Mizuchimeta-codesync[bot]
authored andcommitted
Revert D94950111: Use for_each_field_id_ascending in Json5ProtocolWriter
Differential Revision: D94950111 Original commit changeset: 30c3a3adc7e0 Original Phabricator Diff: D94950111 fbshipit-source-id: bd6f6c6f1ce8370222a34bdfce8e40fa3b2d97f7
1 parent faac4b4 commit f6b3708

3 files changed

Lines changed: 10 additions & 39 deletions

File tree

third-party/thrift/src/thrift/lib/cpp2/op/Get.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,10 @@ constexpr void for_each_field_id_ascending_impl(
497497
std::array<int16_t, N> fieldIds{};
498498
std::copy_n(pa::field_ids<T>() + 1, N, fieldIds.begin());
499499
std::sort(fieldIds.begin(), fieldIds.end());
500-
return std::move(fieldIds);
500+
return fieldIds;
501501
});
502502

503-
// Use array-based expansion instead of fold expression to avoid exceeding
504-
// compiler's expression nesting limit for structs with >256 fields.
505-
std::array<int, sizeof...(I) + 1> unused{
506-
{0, (f(field_id<sortedFieldIds[I]>{}), 0)...}};
507-
static_cast<void>(unused);
503+
(f(field_id<sortedFieldIds[I]>{}), ...);
508504
}
509505

510506
template <size_t... I, typename F>

third-party/thrift/src/thrift/lib/cpp2/op/detail/Encode.h

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ class SimpleJSONProtocolWriter;
4444

4545
namespace op::detail {
4646

47-
template <class Protocol>
48-
FieldOrder getFieldOrder(const Protocol& prot) {
49-
if constexpr (requires { prot.fieldOrder(); }) {
50-
return prot.fieldOrder();
51-
}
52-
return FieldOrder::Serialization;
53-
}
54-
5547
template <typename T, typename Tag>
5648
inline constexpr bool kIsStrongType =
5749
std::is_enum_v<folly::remove_cvref_t<T>> &&
@@ -557,8 +549,13 @@ struct StructEncode {
557549
uint32_t operator()(Protocol& prot, const T& t) const {
558550
uint32_t s = 0;
559551
s += prot.writeStructBegin(op::get_class_name_v<T>.data());
560-
auto writeField = [&]<class Id>(Id) {
561-
static_assert(type::is_field_id_v<Id>);
552+
op::for_each_ordinal<T>([&](auto id) {
553+
// To respect the SerializeInFieldIdOrder annotation, we perform a custom
554+
// mapping to FieldId that may switch the current ordinal being visited.
555+
// This new field id is the source of truth, and the old ordinal value
556+
// should not be used in this function.
557+
using Id = type::field_id<detail::pa::field_ids_in_serialization_order<
558+
T>()[static_cast<size_t>(decltype(id)::value)]>;
562559
using TypeTag = op::get_type_tag<T, Id>;
563560
using FieldTag = op::get_field_tag<T, Id>;
564561
auto&& field = op::get<Id>(t);
@@ -572,20 +569,7 @@ struct StructEncode {
572569
folly::to_underlying(Id::value));
573570
s += Encode<TypeTag>{}(prot, *field);
574571
s += prot.writeFieldEnd();
575-
};
576-
if (getFieldOrder(prot) == FieldOrder::Serialization) {
577-
op::for_each_ordinal<T>([&](auto id) {
578-
// To respect the SerializeInFieldIdOrder annotation, we perform a
579-
// custom mapping to FieldId that may switch the current ordinal being
580-
// visited. This new field id is the source of truth, and the old
581-
// ordinal value should not be used in this function.
582-
using Id = type::field_id<detail::pa::field_ids_in_serialization_order<
583-
T>()[static_cast<size_t>(decltype(id)::value)]>;
584-
writeField(Id{});
585-
});
586-
} else {
587-
op::for_each_field_id_ascending<T>(writeField);
588-
}
572+
});
589573
s += prot.writeFieldStop();
590574
s += prot.writeStructEnd();
591575
return s;

third-party/thrift/src/thrift/lib/cpp2/protocol/Protocol.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,6 @@ constexpr bool usesFieldNames() {
460460
}
461461
}
462462

463-
/// Specifies the order in which struct fields are serialized.
464-
enum class FieldOrder {
465-
/// Field declaration order in IDL, unless SerializeInFieldIdOrder annotation
466-
/// is present, in which case field id ascending order.
467-
Serialization,
468-
/// Field id ascending order (1, 2, 3, ...).
469-
IdAscending,
470-
};
471-
472463
} // namespace apache::thrift
473464

474465
#endif

0 commit comments

Comments
 (0)