+16
-10
lines changedFilter options
+16
-10
lines changed Original file line number Diff line number Diff line change
@@ -358,6 +358,11 @@ inline bool IsString(const FieldDescriptor* field) {
358
358
}
359
359
360
360
361
+
inline bool IsArenaStringPtr(const FieldDescriptor* field) {
362
+
return field->cpp_string_type() == FieldDescriptor::CppStringType::kString ||
363
+
field->cpp_string_type() == FieldDescriptor::CppStringType::kView;
364
+
}
365
+
361
366
bool IsProfileDriven(const Options& options);
362
367
363
368
// Returns true if `field` is unlikely to be present based on PDProto profile.
Original file line number Diff line number Diff line change
@@ -292,8 +292,7 @@ void EmitNonDefaultCheckForString(io::Printer* p, absl::string_view prefix,
292
292
const FieldDescriptor* field, bool split,
293
293
absl::AnyInvocable<void()> emit_body) {
294
294
ABSL_DCHECK(field->cpp_type() == FieldDescriptor::CPPTYPE_STRING);
295
-
ABSL_DCHECK(field->cpp_string_type() ==
296
-
FieldDescriptor::CppStringType::kString);
295
+
ABSL_DCHECK(IsArenaStringPtr(field));
297
296
p->Emit(
298
297
{
299
298
{"condition", [&] { EmitNonDefaultCheck(p, prefix, field); }},
@@ -392,7 +391,7 @@ void MayEmitMutableIfNonDefaultCheck(io::Printer* p, absl::string_view prefix,
392
391
bool with_enclosing_braces_always) {
393
392
if (ShouldEmitNonDefaultCheck(field)) {
394
393
if (field->cpp_type() == FieldDescriptor::CPPTYPE_STRING &&
395
-
field->cpp_string_type() == FieldDescriptor::CppStringType::kString) {
394
+
IsArenaStringPtr(field)) {
396
395
// If a field is backed by std::string, when default initialized it will
397
396
// point to a global empty std::string instance. We prefer to spend some
398
397
// extra cycles here to create a local string instance in the else branch,
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
13
13
14
14
#include "absl/log/absl_check.h"
15
15
#include "absl/strings/str_cat.h"
16
-
#include "absl/strings/str_format.h"
17
16
#include "absl/strings/string_view.h"
18
17
#include "absl/strings/substitute.h"
19
18
#include "absl/types/optional.h"
@@ -219,11 +218,6 @@ Getters RepeatedFieldGetters(const FieldDescriptor* field,
219
218
return getters;
220
219
}
221
220
222
-
bool IsArenaStringPtr(const FieldDescriptor* field) {
223
-
return field->cpp_string_type() == FieldDescriptor::CppStringType::kString ||
224
-
field->cpp_string_type() == FieldDescriptor::CppStringType::kView;
225
-
}
226
-
227
221
Getters StringFieldGetters(const FieldDescriptor* field, const Options& opts) {
228
222
std::string member = FieldMemberName(field, ShouldSplit(field, opts));
229
223
Original file line number Diff line number Diff line change
@@ -311,6 +311,13 @@ TEST(StringViewFieldTest, RepeatedSetAndGetByReflection) {
311
311
StrEq("222222222222"));
312
312
}
313
313
314
+
TEST(StringViewFieldTest, MergeAndClearEmptyImplicitPresence) {
315
+
TestStringView message, other;
316
+
other.set_implicit_presence("");
317
+
message.MergeFrom(other);
318
+
message.Clear();
319
+
}
320
+
314
321
} // namespace
315
322
} // namespace protobuf
316
323
} // namespace google
Original file line number Diff line number Diff line change
@@ -8,10 +8,11 @@ option java_multiple_files = true;
8
8
option optimize_for = SPEED;
9
9
option features.(pb.cpp).string_type = VIEW;
10
10
11
-
// NEXT_TAG = 5;
11
+
// NEXT_TAG = 6;
12
12
message TestStringView {
13
13
string singular_string = 1;
14
14
bytes singular_bytes = 2;
15
+
string implicit_presence = 5 [features.field_presence = IMPLICIT];
15
16
16
17
repeated string repeated_string = 3;
17
18
repeated bytes repeated_bytes = 4;
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4