8000 Remove fast-path check for non-clang compilers in MessageCreator. · protocolbuffers/protobuf@aa5410d · GitHub
[go: up one dir, main page]

Skip to content

Commit aa5410d

Browse files
sbenzaquenshaod2
authored andcommitted
Remove fast-path check for non-clang compilers in MessageCreator.
This check can lead to issues if the translation units are compiled with different compilers. PiperOrigin-RevId: 755012244
1 parent 0cf5489 commit aa5410d

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

src/google/protobuf/message_lite.h

+10-14
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ class MessageCreator {
128128
func_(func) {}
129129

130130
// Template for testing.
131-
template <bool test_call = false, typename MessageLite>
131+
template <typename MessageLite>
132132
MessageLite* New(const MessageLite* prototype_for_func,
133133
const MessageLite* prototype_for_copy, Arena* arena) const;
134134

135-
template <bool test_call = false, typename MessageLite>
135+
template <typename MessageLite>
136136
MessageLite* PlacementNew(const MessageLite* prototype_for_func,
137137
const MessageLite* prototype_for_copy, void* mem,
138138
Arena* arena) const;
@@ -1244,19 +1244,15 @@ T* OnShutdownDelete(T* p) {
12441244
return p;
12451245
}
12461246

1247-
template <bool test_call, typename MessageLite>
1247+
template <typename MessageLite>
12481248
PROTOBUF_ALWAYS_INLINE MessageLite* MessageCreator::PlacementNew(
12491249
const MessageLite* prototype_for_func,
12501250
const MessageLite* prototype_for_copy, void* mem, Arena* arena) const {
12511251
ABSL_DCHECK_EQ(reinterpret_cast<uintptr_t>(mem) % alignment_, 0u);
12521252
const Tag as_tag = tag();
1253-
// When the feature is not enabled we skip the `as_tag` check since it is
1254-
// unnecessary. Except for testing, where we want to test the copy logic even
1255-
// when we can't use it for real messages.
1256-
constexpr bool kMustBeFunc = !test_call && !internal::EnableCustomNew();
12571253
static_assert(kFunc < 0 && !(kZeroInit < 0) && !(kMemcpy < 0),
12581254
"Only kFunc must be the only negative value");
1259-
if (ABSL_PREDICT_FALSE(kMustBeFunc || (int8_t)as_tag < 0)) {
1255+
if (ABSL_PREDICT_FALSE(static_cast<int8_t>(as_tag) < 0)) {
12601256
PROTOBUF_DEBUG_COUNTER("MessageCreator.Func").Inc();
12611257
return static_cast<MessageLite*>(func_(prototype_for_func, mem, arena));
12621258
}
@@ -1345,15 +1341,15 @@ PROTOBUF_ALWAYS_INLINE MessageLite* MessageCreator::PlacementNew(
13451341
return Launder(reinterpret_cast<MessageLite*>(mem));
13461342
}
13471343

1348-
template <bool test_call, typename MessageLite>
1344+
template <typename MessageLite>
13491345
PROTOBUF_ALWAYS_INLINE MessageLite* MessageCreator::New(
13501346
const MessageLite* prototype_for_func,
13511347
const MessageLite* prototype_for_copy, Arena* arena) const {
1352-
return PlacementNew<test_call>(prototype_for_func, prototype_for_copy,
1353-
arena != nullptr
1354-
? arena->AllocateAligned(allocation_size_)
1355-
: ::operator new(allocation_size_),
1356-
arena);
1348+
return PlacementNew(prototype_for_func, prototype_for_copy,
1349+
arena != nullptr
1350+
? arena->AllocateAligned(allocation_size_)
1351+
: ::operator new(allocation_size_),
1352+
arena);
13571353
}
13581354

13591355
} // namespace internal

src/google/protobuf/port.h

-3
Original file line numberDiff line numberDiff line change
@@ -454,19 +454,16 @@ constexpr T* Launder(T* p) {
454454
}
455455

456456
#if defined(PROTOBUF_CUSTOM_VTABLE)
457-
constexpr bool EnableCustomNew() { return true; }
458457
template <typename T>
459458
constexpr bool EnableCustomNewFor() {
460459
return true;
461460
}
462461
#elif ABSL_HAVE_BUILTIN(__is_bitwise_cloneable)
463-
constexpr bool EnableCustomNew() { return true; }
464462
template <typename T>
465463
constexpr bool EnableCustomNewFor() {
466464
return __is_bitwise_cloneable(T);
467465
}
468466
#else
469-
constexpr bool EnableCustomNew() { return false; }
470467
template <typename T>
471468
constexpr bool EnableCustomNewFor() {
472469
return false;

0 commit comments

Comments
 (0)
0