Merge pull request #7583 from haberman/sync-stage

Integrate from Piper for C++, Java, and Python
This commit is contained in:
Joshua Haberman 2020-06-01 18:42:07 -07:00 committed by GitHub
commit c0b79c5a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 387 additions and 2172 deletions

View File

@ -1,10 +1,15 @@
Unreleased Changes
C++:
* Removed deprecated unsafe arena string accessors
* Enabled heterogeneous lookup for std::string keys in maps.
* Improved the randomness of map ordering.
* Removed implicit conversion from StringPiece to std::string
* Fix use-after-destroy bug when the Map is allocated in the arena.
* Improved the randomness of proto map ordering
Python:
* Reject lowercase t for Timestamp json format. Fixes a conformance test.
* Improved the error message when AttributeError is returned from __getattr__
in EnumTypeWrapper.

View File

@ -343,23 +343,3 @@ unique, so there should be no problem with this, but MSVC prints warning
nevertheless. So, we disable it. Unfortunately, this warning will also be
produced when compiling code which merely uses protocol buffers, meaning you
may have to disable it in your code too.
Cross-compiling
===============
When cross-compiling you will need to disable building the tests which are ON
by default. You can do so by specifying the following flags when configuring
your build:
-Dprotobuf_BUILD_TESTS=OFF
Alternatively you can compile (or download) 'protoc' for your host machine
prior to configuring your target build. To specify an existing 'protoc' binary
for your build, specify the following flag:
-DWITH_PROTOC=<path to your protoc binary>
You can also save compilation time by disabling building 'protoc' for your
target build:
-Dprotobuf_BUILD_PROTOC_BINARIES=OFF

View File

@ -28,4 +28,3 @@ Required.Proto3.JsonInput.DoubleFieldTooSmall
Required.Proto3.JsonInput.FloatFieldTooLarge
Required.Proto3.JsonInput.FloatFieldTooSmall
Required.Proto3.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool
Required.Proto3.JsonInput.TimestampJsonInputLowercaseT

View File

@ -19,4 +19,3 @@ Required.Proto3.JsonInput.DoubleFieldTooSmall
Required.Proto3.JsonInput.FloatFieldTooLarge
Required.Proto3.JsonInput.FloatFieldTooSmall
Required.Proto3.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool
Required.Proto3.JsonInput.TimestampJsonInputLowercaseT

View File

@ -417,7 +417,7 @@ jspb.Message.EMPTY_LIST_SENTINEL_ = goog.DEBUG && Object.freeze ?
*/
jspb.Message.isArray_ = function(o) {
return jspb.Message.ASSUME_LOCAL_ARRAYS ? o instanceof Array :
goog.isArray(o);
Array.isArray(o);
};
/**
@ -1433,7 +1433,7 @@ jspb.Message.prototype.syncMapFields_ = function() {
if (this.wrappers_) {
for (var fieldNumber in this.wrappers_) {
var val = this.wrappers_[fieldNumber];
if (goog.isArray(val)) {
if (Array.isArray(val)) {
for (var i = 0; i < val.length; i++) {
if (val[i]) {
val[i].toArray();
@ -1823,7 +1823,7 @@ jspb.Message.copyInto = function(fromMessage, toMessage) {
*/
jspb.Message.clone_ = function(obj) {
var o;
if (goog.isArray(obj)) {
if (Array.isArray(obj)) {
// Allocate array of correct size.
var clonedArray = new Array(obj.length);
// Use array iteration where possible because it is faster than for-in.

View File

@ -269,7 +269,6 @@ class JsonFormatTest(JsonFormatBase):
}
self.assertEqual(expected_dict, message_dict)
def testExtensionSerializationJsonMatchesProto3Spec(self):
"""See go/proto3-json-spec for spec.
"""
@ -295,7 +294,6 @@ class JsonFormatTest(JsonFormatBase):
'}}') % (ext1_text, ext2_text)
self.assertEqual(json.loads(golden_text), json.loads(message_text))
def testJsonEscapeString(self):
message = json_format_proto3_pb2.TestMessage()
if sys.version_info[0] < 3:
@ -1036,6 +1034,15 @@ class JsonFormatTest(JsonFormatBase):
OverflowError,
'date value out of range',
json_format.MessageToJson, message)
# Lower case t does not accept.
text = '{"value": "0001-01-01t00:00:00Z"}'
with self.assertRaises(json_format.ParseError) as e:
json_format.Parse(text, message)
self.assertEqual(
'Failed to parse value field: '
'time data \'0001-01-01t00:00:00\' does not match format '
'\'%Y-%m-%dT%H:%M:%S\', lowercase \'t\' is not accepted.',
str(e.exception))
def testInvalidOneof(self):
message = json_format_proto3_pb2.TestOneof()

View File

@ -160,6 +160,10 @@ class Timestamp(object):
else:
second_value = time_value[:point_position]
nano_value = time_value[point_position + 1:]
if 't' in second_value:
raise ValueError(
'time data \'{0}\' does not match format \'%Y-%m-%dT%H:%M:%S\', '
'lowercase \'t\' is not accepted'.format(second_value))
date_object = datetime.strptime(second_value, _TIMESTAMPFOMAT)
td = date_object - datetime(1970, 1, 1)
seconds = td.seconds + td.days * _SECONDS_PER_DAY

View File

@ -225,15 +225,6 @@ class PROTOBUF_EXPORT Any PROTOBUF_FINAL :
std::string* mutable_type_url();
std::string* release_type_url();
void set_allocated_type_url(std::string* type_url);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_type_url();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_type_url(
std::string* type_url);
private:
const std::string& _internal_type_url() const;
void _internal_set_type_url(const std::string& value);
@ -250,15 +241,6 @@ class PROTOBUF_EXPORT Any PROTOBUF_FINAL :
std::string* mutable_value();
std::string* release_value();
void set_allocated_value(std::string* value);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_value();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_value(
std::string* value);
private:
const std::string& _internal_value() const;
void _internal_set_value(const std::string& value);
@ -350,25 +332,6 @@ inline void Any::set_allocated_type_url(std::string* type_url) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url)
}
inline std::string* Any::unsafe_arena_release_type_url() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Any.type_url)
GOOGLE_DCHECK(GetArena() != nullptr);
return type_url_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Any::unsafe_arena_set_allocated_type_url(
std::string* type_url) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (type_url != nullptr) {
} else {
}
type_url_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
type_url, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Any.type_url)
}
// bytes value = 2;
inline void Any::clear_value() {
@ -431,25 +394,6 @@ inline void Any::set_allocated_value(std::string* value) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value)
}
inline std::string* Any::unsafe_arena_release_value() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Any.value)
GOOGLE_DCHECK(GetArena() != nullptr);
return value_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Any::unsafe_arena_set_allocated_value(
std::string* value) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (value != nullptr) {
} else {
}
value_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
value, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Any.value)
}
#ifdef __GNUC__
#pragma GCC diagnostic pop

View File

@ -261,15 +261,6 @@ class PROTOBUF_EXPORT Api PROTOBUF_FINAL :
std::string* mutable_name();
std::string* release_name();
void set_allocated_name(std::string* name);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_name();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_name(
std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
@ -286,15 +277,6 @@ class PROTOBUF_EXPORT Api PROTOBUF_FINAL :
std::string* mutable_version();
std::string* release_version();
void set_allocated_version(std::string* version);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_version();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_version(
std::string* version);
private:
const std::string& _internal_version() const;
void _internal_set_version(const std::string& value);
@ -496,15 +478,6 @@ class PROTOBUF_EXPORT Method PROTOBUF_FINAL :
std::string* mutable_name();
std::string* release_name();
void set_allocated_name(std::string* name);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_name();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_name(
std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
@ -521,15 +494,6 @@ class PROTOBUF_EXPORT Method PROTOBUF_FINAL :
std::string* mutable_request_type_url();
std::string* release_request_type_url();
void set_allocated_request_type_url(std::string* request_type_url);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_request_type_url();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_request_type_url(
std::string* request_type_url);
private:
const std::string& _internal_request_type_url() const;
void _internal_set_request_type_url(const std::string& value);
@ -546,15 +510,6 @@ class PROTOBUF_EXPORT Method PROTOBUF_FINAL :
std::string* mutable_response_type_url();
std::string* release_response_type_url();
void set_allocated_response_type_url(std::string* response_type_url);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_response_type_url();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_response_type_url(
std::string* response_type_url);
private:
const std::string& _internal_response_type_url() const;
void _internal_set_response_type_url(const std::string& value);
@ -733,15 +688,6 @@ class PROTOBUF_EXPORT Mixin PROTOBUF_FINAL :
std::string* mutable_name();
std::string* release_name();
void set_allocated_name(std::string* name);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_name();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_name(
std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
@ -758,15 +704,6 @@ class PROTOBUF_EXPORT Mixin PROTOBUF_FINAL :
std::string* mutable_root();
std::string* release_root();
void set_allocated_root(std::string* root);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_root();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_root(
std::string* root);
private:
const std::string& _internal_root() const;
void _internal_set_root(const std::string& value);
@ -857,25 +794,6 @@ inline void Api::set_allocated_name(std::string* name) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.name)
}
inline std::string* Api::unsafe_arena_release_name() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Api.name)
GOOGLE_DCHECK(GetArena() != nullptr);
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Api::unsafe_arena_set_allocated_name(
std::string* name) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (name != nullptr) {
} else {
}
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
name, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.name)
}
// repeated .google.protobuf.Method methods = 2;
inline int Api::_internal_methods_size() const {
@ -1013,25 +931,6 @@ inline void Api::set_allocated_version(std::string* version) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version)
}
inline std::string* Api::unsafe_arena_release_version() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Api.version)
GOOGLE_DCHECK(GetArena() != nullptr);
return version_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Api::unsafe_arena_set_allocated_version(
std::string* version) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (version != nullptr) {
} else {
}
version_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
version, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Api.version)
}
// .google.protobuf.SourceContext source_context = 5;
inline bool Api::_internal_has_source_context() const {
@ -1234,25 +1133,6 @@ inline void Method::set_allocated_name(std::string* name) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name)
}
inline std::string* Method::unsafe_arena_release_name() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Method.name)
GOOGLE_DCHECK(GetArena() != nullptr);
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Method::unsafe_arena_set_allocated_name(
std::string* name) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (name != nullptr) {
} else {
}
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
name, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Method.name)
}
// string request_type_url = 2;
inline void Method::clear_request_type_url() {
@ -1315,25 +1195,6 @@ inline void Method::set_allocated_request_type_url(std::string* request_type_url
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url)
}
inline std::string* Method::unsafe_arena_release_request_type_url() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Method.request_type_url)
GOOGLE_DCHECK(GetArena() != nullptr);
return request_type_url_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Method::unsafe_arena_set_allocated_request_type_url(
std::string* request_type_url) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (request_type_url != nullptr) {
} else {
}
request_type_url_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
request_type_url, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Method.request_type_url)
}
// bool request_streaming = 3;
inline void Method::clear_request_streaming() {
@ -1416,25 +1277,6 @@ inline void Method::set_allocated_response_type_url(std::string* response_type_u
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url)
}
inline std::string* Method::unsafe_arena_release_response_type_url() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Method.response_type_url)
GOOGLE_DCHECK(GetArena() != nullptr);
return response_type_url_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Method::unsafe_arena_set_allocated_response_type_url(
std::string* response_type_url) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (response_type_url != nullptr) {
} else {
}
response_type_url_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
response_type_url, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Method.response_type_url)
}
// bool response_streaming = 5;
inline void Method::clear_response_streaming() {
@ -1577,25 +1419,6 @@ inline void Mixin::set_allocated_name(std::string* name) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name)
}
inline std::string* Mixin::unsafe_arena_release_name() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Mixin.name)
GOOGLE_DCHECK(GetArena() != nullptr);
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Mixin::unsafe_arena_set_allocated_name(
std::string* name) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (name != nullptr) {
} else {
}
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
name, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Mixin.name)
}
// string root = 2;
inline void Mixin::clear_root() {
@ -1658,25 +1481,6 @@ inline void Mixin::set_allocated_root(std::string* root) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.root)
}
inline std::string* Mixin::unsafe_arena_release_root() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Mixin.root)
GOOGLE_DCHECK(GetArena() != nullptr);
return root_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Mixin::unsafe_arena_set_allocated_root(
std::string* root) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (root != nullptr) {
} else {
}
root_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
root, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Mixin.root)
}
#ifdef __GNUC__
#pragma GCC diagnostic pop

View File

@ -858,23 +858,6 @@ TEST(ArenaTest, ReleaseLastRepeatedField) {
}
}
TEST(ArenaTest, UnsafeArenaReleaseAdd) {
// Use unsafe_arena_release() and unsafe_arena_set_allocated() to transfer an
// arena-allocated string from one message to another.
const char kContent[] = "Test content";
Arena arena;
TestAllTypes* message1 = Arena::CreateMessage<TestAllTypes>(&arena);
TestAllTypes* message2 = Arena::CreateMessage<TestAllTypes>(&arena);
std::string* arena_string = Arena::Create<std::string>(&arena);
*arena_string = kContent;
message1->unsafe_arena_set_allocated_optional_string(arena_string);
message2->unsafe_arena_set_allocated_optional_string(
message1->unsafe_arena_release_optional_string());
EXPECT_EQ(kContent, message2->optional_string());
}
TEST(ArenaTest, UnsafeArenaAddAllocated) {
Arena arena;
TestAllTypes* message = Arena::CreateMessage<TestAllTypes>(&arena);
@ -885,43 +868,20 @@ TEST(ArenaTest, UnsafeArenaAddAllocated) {
}
}
TEST(ArenaTest, UnsafeArenaRelease) {
Arena arena;
TestAllTypes* message = Arena::CreateMessage<TestAllTypes>(&arena);
std::string* s = new std::string("test string");
message->unsafe_arena_set_allocated_optional_string(s);
EXPECT_TRUE(message->has_optional_string());
EXPECT_EQ("test string", message->optional_string());
s = message->unsafe_arena_release_optional_string();
EXPECT_FALSE(message->has_optional_string());
delete s;
s = new std::string("test string");
message->unsafe_arena_set_allocated_oneof_string(s);
EXPECT_TRUE(message->has_oneof_string());
EXPECT_EQ("test string", message->oneof_string());
s = message->unsafe_arena_release_oneof_string();
EXPECT_FALSE(message->has_oneof_string());
delete s;
}
TEST(ArenaTest, OneofMerge) {
Arena arena;
TestAllTypes* message0 = Arena::CreateMessage<TestAllTypes>(&arena);
TestAllTypes* message1 = Arena::CreateMessage<TestAllTypes>(&arena);
message0->unsafe_arena_set_allocated_oneof_string(new std::string("x"));
message0->set_oneof_string("x");
ASSERT_TRUE(message0->has_oneof_string());
message1->unsafe_arena_set_allocated_oneof_string(new std::string("y"));
message1->set_oneof_string("y");
ASSERT_TRUE(message1->has_oneof_string());
EXPECT_EQ("x", message0->oneof_string());
EXPECT_EQ("y", message1->oneof_string());
message0->MergeFrom(*message1);
EXPECT_EQ("y", message0->oneof_string());
EXPECT_EQ("y", message1->oneof_string());
delete message0->unsafe_arena_release_oneof_string();
delete message1->unsafe_arena_release_oneof_string();
}
TEST(ArenaTest, ArenaOneofReflection) {
@ -1345,19 +1305,6 @@ TEST(ArenaTest, AddCleanup) {
}
}
TEST(ArenaTest, UnsafeSetAllocatedOnArena) {
Arena arena;
TestAllTypes* message = Arena::CreateMessage<TestAllTypes>(&arena);
EXPECT_FALSE(message->has_optional_string());
std::string owned_string = "test with long enough content to heap-allocate";
message->unsafe_arena_set_allocated_optional_string(&owned_string);
EXPECT_TRUE(message->has_optional_string());
message->unsafe_arena_set_allocated_optional_string(NULL);
EXPECT_FALSE(message->has_optional_string());
}
// A helper utility class to only contain static hook functions, some
// counters to be used to verify the counters have been called and a cookie
// value to be verified.

View File

@ -110,7 +110,7 @@ class PROTOC_EXPORT CodeGenerator {
// Implement this to indicate what features this code generator supports.
// This should be a bitwise OR of features from the Features enum in
// plugin.proto.
virtual uint64 GetSupportedFeatures() const { return 0; }
virtual uint64_t GetSupportedFeatures() const { return 0; }
// This is no longer used, but this class is part of the opensource protobuf
// library, so it has to remain to keep vtables the same for the current

View File

@ -84,7 +84,7 @@ class PROTOC_EXPORT CppGenerator : public CodeGenerator {
GeneratorContext* generator_context,
std::string* error) const override;
uint64 GetSupportedFeatures() const override {
uint64_t GetSupportedFeatures() const override {
// We don't fully support this yet, but this is needed to unblock the tests,
// and we will have full support before the experimental flag is removed.
return FEATURE_PROTO3_OPTIONAL;

View File

@ -179,23 +179,6 @@ void StringFieldGenerator::GenerateAccessorDeclarations(
"$deprecated_attr$void ${1$set_allocated_$name$$}$(std::string* "
"$name$);\n",
descriptor_);
if (options_.opensource_runtime) {
if (SupportsArenas(descriptor_)) {
format(
"$GOOGLE_PROTOBUF$_RUNTIME_DEPRECATED(\"The unsafe_arena_ accessors "
"for\"\n"
"\" string fields are deprecated and will be removed in a\"\n"
"\" future release.\")\n"
"std::string* ${1$unsafe_arena_release_$name$$}$();\n"
"$GOOGLE_PROTOBUF$_RUNTIME_DEPRECATED(\"The unsafe_arena_ accessors "
"for\"\n"
"\" string fields are deprecated and will be removed in a\"\n"
"\" future release.\")\n"
"void ${1$unsafe_arena_set_allocated_$name$$}$(\n"
" std::string* $name$);\n",
descriptor_);
}
}
format(
"private:\n"
"const std::string& _internal_$name$() const;\n"
@ -307,32 +290,6 @@ void StringFieldGenerator::GenerateInlineAccessorDefinitions(
" GetArena());\n"
" // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
"}\n");
if (options_.opensource_runtime) {
format(
"inline std::string* $classname$::unsafe_arena_release_$name$() {\n"
"$annotate_accessor$"
" // "
"@@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n"
" $DCHK$(GetArena() != nullptr);\n"
" $clear_hasbit$\n"
" return $name$_.UnsafeArenaRelease($default_variable$,\n"
" GetArena());\n"
"}\n"
"inline void $classname$::unsafe_arena_set_allocated_$name$(\n"
"$annotate_accessor$"
" std::string* $name$) {\n"
" $DCHK$(GetArena() != nullptr);\n"
" if ($name$ != nullptr) {\n"
" $set_hasbit$\n"
" } else {\n"
" $clear_hasbit$\n"
" }\n"
" $name$_.UnsafeArenaSetAllocated($default_variable$,\n"
" $name$, GetArena());\n"
" // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
"$full_name$)\n"
"}\n");
}
} else {
// No-arena case.
format(
@ -761,38 +718,6 @@ void StringOneofFieldGenerator::GenerateInlineAccessorDefinitions(
" }\n"
" // @@protoc_insertion_point(field_set_allocated:$full_name$)\n"
"}\n");
if (options_.opensource_runtime) {
format(
"inline std::string* $classname$::unsafe_arena_release_$name$() {\n"
"$annotate_accessor$"
" // "
"@@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n"
" $DCHK$(GetArena() != nullptr);\n"
" if (_internal_has_$name$()) {\n"
" clear_has_$oneof_name$();\n"
" return $field_member$.UnsafeArenaRelease(\n"
" $default_variable$, GetArena());\n"
" } else {\n"
" return nullptr;\n"
" }\n"
"}\n"
"inline void $classname$::unsafe_arena_set_allocated_$name$("
"std::string* $name$) {\n"
"$annotate_accessor$"
" $DCHK$(GetArena() != nullptr);\n"
" if (!_internal_has_$name$()) {\n"
" $field_member$.UnsafeSetDefault($default_variable$);\n"
" }\n"
" clear_$oneof_name$();\n"
" if ($name$) {\n"
" set_has_$name$();\n"
" $field_member$.UnsafeArenaSetAllocated($default_variable$, "
"$name$, GetArena());\n"
" }\n"
" // @@protoc_insertion_point(field_unsafe_arena_set_allocated:"
"$full_name$)\n"
"}\n");
}
} else {
// No-arena case.
format(

View File

@ -58,7 +58,7 @@ namespace java {
JavaGenerator::JavaGenerator() {}
JavaGenerator::~JavaGenerator() {}
uint64 JavaGenerator::GetSupportedFeatures() const {
uint64_t JavaGenerator::GetSupportedFeatures() const {
return CodeGenerator::Feature::FEATURE_PROTO3_OPTIONAL;
}

View File

@ -60,7 +60,7 @@ class PROTOC_EXPORT JavaGenerator : public CodeGenerator {
bool Generate(const FileDescriptor* file, const std::string& parameter,
GeneratorContext* context, std::string* error) const override;
uint64 GetSupportedFeatures() const override;
uint64_t GetSupportedFeatures() const override;
private:
GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JavaGenerator);

View File

@ -87,7 +87,7 @@ MockCodeGenerator::MockCodeGenerator(const std::string& name) : name_(name) {}
MockCodeGenerator::~MockCodeGenerator() {}
uint64 MockCodeGenerator::GetSupportedFeatures() const {
uint64_t MockCodeGenerator::GetSupportedFeatures() const {
uint64 all_features = CodeGenerator::FEATURE_PROTO3_OPTIONAL;
return all_features & ~suppressed_features_;
}

View File

@ -109,7 +109,7 @@ class MockCodeGenerator : public CodeGenerator {
bool Generate(const FileDescriptor* file, const std::string& parameter,
GeneratorContext* context, std::string* error) const override;
uint64 GetSupportedFeatures() const override;
uint64_t GetSupportedFeatures() const override;
void SuppressFeatures(uint64 features);
private:

View File

@ -251,15 +251,6 @@ class PROTOC_EXPORT Version PROTOBUF_FINAL :
std::string* mutable_suffix();
std::string* release_suffix();
void set_allocated_suffix(std::string* suffix);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_suffix();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_suffix(
std::string* suffix);
private:
const std::string& _internal_suffix() const;
void _internal_set_suffix(const std::string& value);
@ -503,15 +494,6 @@ class PROTOC_EXPORT CodeGeneratorRequest PROTOBUF_FINAL :
std::string* mutable_parameter();
std::string* release_parameter();
void set_allocated_parameter(std::string* parameter);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_parameter();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_parameter(
std::string* parameter);
private:
const std::string& _internal_parameter() const;
void _internal_set_parameter(const std::string& value);
@ -691,15 +673,6 @@ class PROTOC_EXPORT CodeGeneratorResponse_File PROTOBUF_FINAL :
std::string* mutable_name();
std::string* release_name();
void set_allocated_name(std::string* name);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_name();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_name(
std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
@ -720,15 +693,6 @@ class PROTOC_EXPORT CodeGeneratorResponse_File PROTOBUF_FINAL :
std::string* mutable_insertion_point();
std::string* release_insertion_point();
void set_allocated_insertion_point(std::string* insertion_point);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_insertion_point();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_insertion_point(
std::string* insertion_point);
private:
const std::string& _internal_insertion_point() const;
void _internal_set_insertion_point(const std::string& value);
@ -749,15 +713,6 @@ class PROTOC_EXPORT CodeGeneratorResponse_File PROTOBUF_FINAL :
std::string* mutable_content();
std::string* release_content();
void set_allocated_content(std::string* content);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_content();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_content(
std::string* content);
private:
const std::string& _internal_content() const;
void _internal_set_content(const std::string& value);
@ -968,15 +923,6 @@ class PROTOC_EXPORT CodeGeneratorResponse PROTOBUF_FINAL :
std::string* mutable_error();
std::string* release_error();
void set_allocated_error(std::string* error);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_error();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_error(
std::string* error);
private:
const std::string& _internal_error() const;
void _internal_set_error(const std::string& value);
@ -1178,25 +1124,6 @@ inline void Version::set_allocated_suffix(std::string* suffix) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.Version.suffix)
}
inline std::string* Version::unsafe_arena_release_suffix() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.compiler.Version.suffix)
GOOGLE_DCHECK(GetArena() != nullptr);
_has_bits_[0] &= ~0x00000001u;
return suffix_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Version::unsafe_arena_set_allocated_suffix(
std::string* suffix) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (suffix != nullptr) {
_has_bits_[0] |= 0x00000001u;
} else {
_has_bits_[0] &= ~0x00000001u;
}
suffix_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
suffix, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.compiler.Version.suffix)
}
// -------------------------------------------------------------------
@ -1349,25 +1276,6 @@ inline void CodeGeneratorRequest::set_allocated_parameter(std::string* parameter
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorRequest.parameter)
}
inline std::string* CodeGeneratorRequest::unsafe_arena_release_parameter() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.compiler.CodeGeneratorRequest.parameter)
GOOGLE_DCHECK(GetArena() != nullptr);
_has_bits_[0] &= ~0x00000001u;
return parameter_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void CodeGeneratorRequest::unsafe_arena_set_allocated_parameter(
std::string* parameter) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (parameter != nullptr) {
_has_bits_[0] |= 0x00000001u;
} else {
_has_bits_[0] &= ~0x00000001u;
}
parameter_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
parameter, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.compiler.CodeGeneratorRequest.parameter)
}
// repeated .google.protobuf.FileDescriptorProto proto_file = 15;
inline int CodeGeneratorRequest::_internal_proto_file_size() const {
@ -1565,25 +1473,6 @@ inline void CodeGeneratorResponse_File::set_allocated_name(std::string* name) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.name)
}
inline std::string* CodeGeneratorResponse_File::unsafe_arena_release_name() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.compiler.CodeGeneratorResponse.File.name)
GOOGLE_DCHECK(GetArena() != nullptr);
_has_bits_[0] &= ~0x00000001u;
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void CodeGeneratorResponse_File::unsafe_arena_set_allocated_name(
std::string* name) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (name != nullptr) {
_has_bits_[0] |= 0x00000001u;
} else {
_has_bits_[0] &= ~0x00000001u;
}
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
name, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.name)
}
// optional string insertion_point = 2;
inline bool CodeGeneratorResponse_File::_internal_has_insertion_point() const {
@ -1658,25 +1547,6 @@ inline void CodeGeneratorResponse_File::set_allocated_insertion_point(std::strin
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
}
inline std::string* CodeGeneratorResponse_File::unsafe_arena_release_insertion_point() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
GOOGLE_DCHECK(GetArena() != nullptr);
_has_bits_[0] &= ~0x00000002u;
return insertion_point_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void CodeGeneratorResponse_File::unsafe_arena_set_allocated_insertion_point(
std::string* insertion_point) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (insertion_point != nullptr) {
_has_bits_[0] |= 0x00000002u;
} else {
_has_bits_[0] &= ~0x00000002u;
}
insertion_point_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
insertion_point, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point)
}
// optional string content = 15;
inline bool CodeGeneratorResponse_File::_internal_has_content() const {
@ -1751,25 +1621,6 @@ inline void CodeGeneratorResponse_File::set_allocated_content(std::string* conte
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.content)
}
inline std::string* CodeGeneratorResponse_File::unsafe_arena_release_content() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.compiler.CodeGeneratorResponse.File.content)
GOOGLE_DCHECK(GetArena() != nullptr);
_has_bits_[0] &= ~0x00000004u;
return content_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void CodeGeneratorResponse_File::unsafe_arena_set_allocated_content(
std::string* content) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (content != nullptr) {
_has_bits_[0] |= 0x00000004u;
} else {
_has_bits_[0] &= ~0x00000004u;
}
content_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
content, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.content)
}
// -------------------------------------------------------------------
@ -1848,25 +1699,6 @@ inline void CodeGeneratorResponse::set_allocated_error(std::string* error) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.error)
}
inline std::string* CodeGeneratorResponse::unsafe_arena_release_error() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.compiler.CodeGeneratorResponse.error)
GOOGLE_DCHECK(GetArena() != nullptr);
_has_bits_[0] &= ~0x00000001u;
return error_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void CodeGeneratorResponse::unsafe_arena_set_allocated_error(
std::string* error) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (error != nullptr) {
_has_bits_[0] |= 0x00000001u;
} else {
_has_bits_[0] &= ~0x00000001u;
}
error_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
error, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.error)
}
// optional uint64 supported_features = 2;
inline bool CodeGeneratorResponse::_internal_has_supported_features() const {

View File

@ -301,7 +301,7 @@ Generator::Generator() : file_(nullptr) {}
Generator::~Generator() {}
uint64 Generator::GetSupportedFeatures() const {
uint64_t Generator::GetSupportedFeatures() const {
return CodeGenerator::Feature::FEATURE_PROTO3_OPTIONAL;
}

View File

@ -73,7 +73,7 @@ class PROTOC_EXPORT Generator : public CodeGenerator {
GeneratorContext* generator_context,
std::string* error) const override;
uint64 GetSupportedFeatures() const override;
uint64_t GetSupportedFeatures() const override;
private:
void PrintImports() const;

View File

@ -434,14 +434,14 @@ struct PointerStringPairHash {
const Symbol kNullSymbol;
typedef HASH_MAP<const char*, Symbol, HASH_FXN<const char*>, streq>
typedef HASH_MAP<StringPiece, Symbol, HASH_FXN<StringPiece>>
SymbolsByNameMap;
typedef HASH_MAP<PointerStringPair, Symbol, PointerStringPairHash>
SymbolsByParentMap;
typedef HASH_MAP<const char*, const FileDescriptor*, HASH_FXN<const char*>,
streq>
typedef HASH_MAP<StringPiece, const FileDescriptor*,
HASH_FXN<StringPiece>>
FilesByNameMap;
typedef HASH_MAP<PointerStringPair, const FieldDescriptor*,
@ -576,16 +576,16 @@ class DescriptorPool::Tables {
// Find symbols. This returns a null Symbol (symbol.IsNull() is true)
// if not found.
inline Symbol FindSymbol(const std::string& key) const;
inline Symbol FindSymbol(StringPiece key) const;
// This implements the body of DescriptorPool::Find*ByName(). It should
// really be a private method of DescriptorPool, but that would require
// declaring Symbol in descriptor.h, which would drag all kinds of other
// stuff into the header. Yay C++.
Symbol FindByNameHelper(const DescriptorPool* pool, const std::string& name);
Symbol FindByNameHelper(const DescriptorPool* pool, StringPiece name);
// These return nullptr if not found.
inline const FileDescriptor* FindFile(const std::string& key) const;
inline const FileDescriptor* FindFile(StringPiece key) const;
inline const FieldDescriptor* FindExtension(const Descriptor* extendee,
int number) const;
inline void FindAllExtensions(const Descriptor* extendee,
@ -619,7 +619,7 @@ class DescriptorPool::Tables {
// Allocate a string which will be destroyed when the pool is destroyed.
// The string is initialized to the given value for convenience.
std::string* AllocateString(const std::string& value);
std::string* AllocateString(StringPiece value);
// Allocate empty string which will be destroyed when the pool is destroyed.
std::string* AllocateEmptyString();
@ -715,9 +715,9 @@ class FileDescriptorTables {
inline const FieldDescriptor* FindFieldByNumber(const Descriptor* parent,
int number) const;
inline const FieldDescriptor* FindFieldByLowercaseName(
const void* parent, const std::string& lowercase_name) const;
const void* parent, StringPiece lowercase_name) const;
inline const FieldDescriptor* FindFieldByCamelcaseName(
const void* parent, const std::string& camelcase_name) const;
const void* parent, StringPiece camelcase_name) const;
inline const EnumValueDescriptor* FindEnumValueByNumber(
const EnumDescriptor* parent, int number) const;
// This creates a new EnumValueDescriptor if not found, in a thread-safe way.
@ -884,8 +884,8 @@ void DescriptorPool::Tables::RollbackToLastCheckpoint() {
// -------------------------------------------------------------------
inline Symbol DescriptorPool::Tables::FindSymbol(const std::string& key) const {
const Symbol* result = FindOrNull(symbols_by_name_, key.c_str());
inline Symbol DescriptorPool::Tables::FindSymbol(StringPiece key) const {
const Symbol* result = FindOrNull(symbols_by_name_, key);
if (result == nullptr) {
return kNullSymbol;
} else {
@ -912,7 +912,7 @@ inline Symbol FileDescriptorTables::FindNestedSymbolOfType(
}
Symbol DescriptorPool::Tables::FindByNameHelper(const DescriptorPool* pool,
const std::string& name) {
StringPiece name) {
if (pool->mutex_ != nullptr) {
// Fast path: the Symbol is already cached. This is just a hash lookup.
ReaderMutexLock lock(pool->mutex_);
@ -944,8 +944,8 @@ Symbol DescriptorPool::Tables::FindByNameHelper(const DescriptorPool* pool,
}
inline const FileDescriptor* DescriptorPool::Tables::FindFile(
const std::string& key) const {
return FindPtrOrNull(files_by_name_, key.c_str());
StringPiece key) const {
return FindPtrOrNull(files_by_name_, key);
}
inline const FieldDescriptor* FileDescriptorTables::FindFieldByNumber(
@ -982,12 +982,12 @@ void FileDescriptorTables::FieldsByLowercaseNamesLazyInitInternal() const {
}
inline const FieldDescriptor* FileDescriptorTables::FindFieldByLowercaseName(
const void* parent, const std::string& lowercase_name) const {
const void* parent, StringPiece lowercase_name) const {
internal::call_once(
fields_by_lowercase_name_once_,
&FileDescriptorTables::FieldsByLowercaseNamesLazyInitStatic, this);
return FindPtrOrNull(fields_by_lowercase_name_,
PointerStringPair(parent, lowercase_name.c_str()));
PointerStringPair(parent, lowercase_name));
}
void FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic(
@ -1006,12 +1006,12 @@ void FileDescriptorTables::FieldsByCamelcaseNamesLazyInitInternal() const {
}
inline const FieldDescriptor* FileDescriptorTables::FindFieldByCamelcaseName(
const void* parent, const std::string& camelcase_name) const {
const void* parent, StringPiece camelcase_name) const {
internal::call_once(
fields_by_camelcase_name_once_,
FileDescriptorTables::FieldsByCamelcaseNamesLazyInitStatic, this);
return FindPtrOrNull(fields_by_camelcase_name_,
PointerStringPair(parent, camelcase_name.c_str()));
PointerStringPair(parent, camelcase_name));
}
inline const EnumValueDescriptor* FileDescriptorTables::FindEnumValueByNumber(
@ -1181,7 +1181,7 @@ Type* DescriptorPool::Tables::AllocateArray(int count) {
return reinterpret_cast<Type*>(AllocateBytes(sizeof(Type) * count));
}
std::string* DescriptorPool::Tables::AllocateString(const std::string& value) {
std::string* DescriptorPool::Tables::AllocateString(StringPiece value) {
std::string* result = new std::string(value);
strings_.emplace_back(result);
return result;
@ -1293,16 +1293,16 @@ void DescriptorPool::InternalDontEnforceDependencies() {
enforce_dependencies_ = false;
}
void DescriptorPool::AddUnusedImportTrackFile(const std::string& file_name,
void DescriptorPool::AddUnusedImportTrackFile(ConstStringParam file_name,
bool is_error) {
unused_import_track_files_[file_name] = is_error;
unused_import_track_files_[std::string(file_name)] = is_error;
}
void DescriptorPool::ClearUnusedImportTrackFiles() {
unused_import_track_files_.clear();
}
bool DescriptorPool::InternalIsFileLoaded(const std::string& filename) const {
bool DescriptorPool::InternalIsFileLoaded(ConstStringParam filename) const {
MutexLockMaybe lock(mutex_);
return tables_->FindFile(filename) != nullptr;
}
@ -1379,7 +1379,7 @@ void DescriptorPool::InternalAddGeneratedFile(
// there's nothing more important to do (read: never).
const FileDescriptor* DescriptorPool::FindFileByName(
const std::string& name) const {
ConstStringParam name) const {
MutexLockMaybe lock(mutex_);
if (fallback_database_ != nullptr) {
tables_->known_bad_symbols_.clear();
@ -1399,7 +1399,7 @@ const FileDescriptor* DescriptorPool::FindFileByName(
}
const FileDescriptor* DescriptorPool::FindFileContainingSymbol(
const std::string& symbol_name) const {
ConstStringParam symbol_name) const {
MutexLockMaybe lock(mutex_);
if (fallback_database_ != nullptr) {
tables_->known_bad_symbols_.clear();
@ -1420,13 +1420,13 @@ const FileDescriptor* DescriptorPool::FindFileContainingSymbol(
}
const Descriptor* DescriptorPool::FindMessageTypeByName(
const std::string& name) const {
ConstStringParam name) const {
Symbol result = tables_->FindByNameHelper(this, name);
return (result.type == Symbol::MESSAGE) ? result.descriptor : nullptr;
}
const FieldDescriptor* DescriptorPool::FindFieldByName(
const std::string& name) const {
ConstStringParam name) const {
Symbol result = tables_->FindByNameHelper(this, name);
if (result.type == Symbol::FIELD &&
!result.field_descriptor->is_extension()) {
@ -1437,7 +1437,7 @@ const FieldDescriptor* DescriptorPool::FindFieldByName(
}
const FieldDescriptor* DescriptorPool::FindExtensionByName(
const std::string& name) const {
ConstStringParam name) const {
Symbol result = tables_->FindByNameHelper(this, name);
if (result.type == Symbol::FIELD && result.field_descriptor->is_extension()) {
return result.field_descriptor;
@ -1447,32 +1447,32 @@ const FieldDescriptor* DescriptorPool::FindExtensionByName(
}
const OneofDescriptor* DescriptorPool::FindOneofByName(
const std::string& name) const {
ConstStringParam name) const {
Symbol result = tables_->FindByNameHelper(this, name);
return (result.type == Symbol::ONEOF) ? result.oneof_descriptor : nullptr;
}
const EnumDescriptor* DescriptorPool::FindEnumTypeByName(
const std::string& name) const {
ConstStringParam name) const {
Symbol result = tables_->FindByNameHelper(this, name);
return (result.type == Symbol::ENUM) ? result.enum_descriptor : nullptr;
}
const EnumValueDescriptor* DescriptorPool::FindEnumValueByName(
const std::string& name) const {
ConstStringParam name) const {
Symbol result = tables_->FindByNameHelper(this, name);
return (result.type == Symbol::ENUM_VALUE) ? result.enum_value_descriptor
: nullptr;
}
const ServiceDescriptor* DescriptorPool::FindServiceByName(
const std::string& name) const {
ConstStringParam name) const {
Symbol result = tables_->FindByNameHelper(this, name);
return (result.type == Symbol::SERVICE) ? result.service_descriptor : nullptr;
}
const MethodDescriptor* DescriptorPool::FindMethodByName(
const std::string& name) const {
ConstStringParam name) const {
Symbol result = tables_->FindByNameHelper(this, name);
return (result.type == Symbol::METHOD) ? result.method_descriptor : nullptr;
}
@ -1529,7 +1529,7 @@ const FieldDescriptor* DescriptorPool::InternalFindExtensionByNumberNoLock(
}
const FieldDescriptor* DescriptorPool::FindExtensionByPrintableName(
const Descriptor* extendee, const std::string& printable_name) const {
const Descriptor* extendee, ConstStringParam printable_name) const {
if (extendee->extension_range_count() == 0) return nullptr;
const FieldDescriptor* result = FindExtensionByName(printable_name);
if (result != nullptr && result->containing_type() == extendee) {
@ -1600,7 +1600,7 @@ const FieldDescriptor* Descriptor::FindFieldByNumber(int key) const {
}
const FieldDescriptor* Descriptor::FindFieldByLowercaseName(
const std::string& key) const {
ConstStringParam key) const {
const FieldDescriptor* result =
file()->tables_->FindFieldByLowercaseName(this, key);
if (result == nullptr || result->is_extension()) {
@ -1611,7 +1611,7 @@ const FieldDescriptor* Descriptor::FindFieldByLowercaseName(
}
const FieldDescriptor* Descriptor::FindFieldByCamelcaseName(
const std::string& key) const {
ConstStringParam key) const {
const FieldDescriptor* result =
file()->tables_->FindFieldByCamelcaseName(this, key);
if (result == nullptr || result->is_extension()) {
@ -1621,8 +1621,7 @@ const FieldDescriptor* Descriptor::FindFieldByCamelcaseName(
}
}
const FieldDescriptor* Descriptor::FindFieldByName(
const std::string& key) const {
const FieldDescriptor* Descriptor::FindFieldByName(ConstStringParam key) const {
Symbol result =
file()->tables_->FindNestedSymbolOfType(this, key, Symbol::FIELD);
if (!result.IsNull() && !result.field_descriptor->is_extension()) {
@ -1632,8 +1631,7 @@ const FieldDescriptor* Descriptor::FindFieldByName(
}
}
const OneofDescriptor* Descriptor::FindOneofByName(
const std::string& key) const {
const OneofDescriptor* Descriptor::FindOneofByName(ConstStringParam key) const {
Symbol result =
file()->tables_->FindNestedSymbolOfType(this, key, Symbol::ONEOF);
if (!result.IsNull()) {
@ -1644,7 +1642,7 @@ const OneofDescriptor* Descriptor::FindOneofByName(
}
const FieldDescriptor* Descriptor::FindExtensionByName(
const std::string& key) const {
ConstStringParam key) const {
Symbol result =
file()->tables_->FindNestedSymbolOfType(this, key, Symbol::FIELD);
if (!result.IsNull() && result.field_descriptor->is_extension()) {
@ -1655,7 +1653,7 @@ const FieldDescriptor* Descriptor::FindExtensionByName(
}
const FieldDescriptor* Descriptor::FindExtensionByLowercaseName(
const std::string& key) const {
ConstStringParam key) const {
const FieldDescriptor* result =
file()->tables_->FindFieldByLowercaseName(this, key);
if (result == nullptr || !result->is_extension()) {
@ -1666,7 +1664,7 @@ const FieldDescriptor* Descriptor::FindExtensionByLowercaseName(
}
const FieldDescriptor* Descriptor::FindExtensionByCamelcaseName(
const std::string& key) const {
ConstStringParam key) const {
const FieldDescriptor* result =
file()->tables_->FindFieldByCamelcaseName(this, key);
if (result == nullptr || !result->is_extension()) {
@ -1676,8 +1674,7 @@ const FieldDescriptor* Descriptor::FindExtensionByCamelcaseName(
}
}
const Descriptor* Descriptor::FindNestedTypeByName(
const std::string& key) const {
const Descriptor* Descriptor::FindNestedTypeByName(ConstStringParam key) const {
Symbol result =
file()->tables_->FindNestedSymbolOfType(this, key, Symbol::MESSAGE);
if (!result.IsNull()) {
@ -1688,7 +1685,7 @@ const Descriptor* Descriptor::FindNestedTypeByName(
}
const EnumDescriptor* Descriptor::FindEnumTypeByName(
const std::string& key) const {
ConstStringParam key) const {
Symbol result =
file()->tables_->FindNestedSymbolOfType(this, key, Symbol::ENUM);
if (!result.IsNull()) {
@ -1699,7 +1696,7 @@ const EnumDescriptor* Descriptor::FindEnumTypeByName(
}
const EnumValueDescriptor* Descriptor::FindEnumValueByName(
const std::string& key) const {
ConstStringParam key) const {
Symbol result =
file()->tables_->FindNestedSymbolOfType(this, key, Symbol::ENUM_VALUE);
if (!result.IsNull()) {
@ -1742,7 +1739,7 @@ const EnumValueDescriptor* EnumDescriptor::FindValueByNumberCreatingIfUnknown(
}
const MethodDescriptor* ServiceDescriptor::FindMethodByName(
const std::string& key) const {
ConstStringParam key) const {
Symbol result =
file()->tables_->FindNestedSymbolOfType(this, key, Symbol::METHOD);
if (!result.IsNull()) {
@ -1753,7 +1750,7 @@ const MethodDescriptor* ServiceDescriptor::FindMethodByName(
}
const Descriptor* FileDescriptor::FindMessageTypeByName(
const std::string& key) const {
ConstStringParam key) const {
Symbol result = tables_->FindNestedSymbolOfType(this, key, Symbol::MESSAGE);
if (!result.IsNull()) {
return result.descriptor;
@ -1763,7 +1760,7 @@ const Descriptor* FileDescriptor::FindMessageTypeByName(
}
const EnumDescriptor* FileDescriptor::FindEnumTypeByName(
const std::string& key) const {
ConstStringParam key) const {
Symbol result = tables_->FindNestedSymbolOfType(this, key, Symbol::ENUM);
if (!result.IsNull()) {
return result.enum_descriptor;
@ -1773,7 +1770,7 @@ const EnumDescriptor* FileDescriptor::FindEnumTypeByName(
}
const EnumValueDescriptor* FileDescriptor::FindEnumValueByName(
const std::string& key) const {
ConstStringParam key) const {
Symbol result =
tables_->FindNestedSymbolOfType(this, key, Symbol::ENUM_VALUE);
if (!result.IsNull()) {
@ -1784,7 +1781,7 @@ const EnumValueDescriptor* FileDescriptor::FindEnumValueByName(
}
const ServiceDescriptor* FileDescriptor::FindServiceByName(
const std::string& key) const {
ConstStringParam key) const {
Symbol result = tables_->FindNestedSymbolOfType(this, key, Symbol::SERVICE);
if (!result.IsNull()) {
return result.service_descriptor;
@ -1794,7 +1791,7 @@ const ServiceDescriptor* FileDescriptor::FindServiceByName(
}
const FieldDescriptor* FileDescriptor::FindExtensionByName(
const std::string& key) const {
ConstStringParam key) const {
Symbol result = tables_->FindNestedSymbolOfType(this, key, Symbol::FIELD);
if (!result.IsNull() && result.field_descriptor->is_extension()) {
return result.field_descriptor;
@ -1804,7 +1801,7 @@ const FieldDescriptor* FileDescriptor::FindExtensionByName(
}
const FieldDescriptor* FileDescriptor::FindExtensionByLowercaseName(
const std::string& key) const {
ConstStringParam key) const {
const FieldDescriptor* result = tables_->FindFieldByLowercaseName(this, key);
if (result == nullptr || !result->is_extension()) {
return nullptr;
@ -1814,7 +1811,7 @@ const FieldDescriptor* FileDescriptor::FindExtensionByLowercaseName(
}
const FieldDescriptor* FileDescriptor::FindExtensionByCamelcaseName(
const std::string& key) const {
ConstStringParam key) const {
const FieldDescriptor* result = tables_->FindFieldByCamelcaseName(this, key);
if (result == nullptr || !result->is_extension()) {
return nullptr;
@ -1871,22 +1868,23 @@ EnumDescriptor::FindReservedRangeContainingNumber(int number) const {
// -------------------------------------------------------------------
bool DescriptorPool::TryFindFileInFallbackDatabase(
const std::string& name) const {
StringPiece name) const {
if (fallback_database_ == nullptr) return false;
if (tables_->known_bad_files_.count(name) > 0) return false;
auto name_string = std::string(name);
if (tables_->known_bad_files_.count(name_string) > 0) return false;
FileDescriptorProto file_proto;
if (!fallback_database_->FindFileByName(name, &file_proto) ||
if (!fallback_database_->FindFileByName(name_string, &file_proto) ||
BuildFileFromDatabase(file_proto) == nullptr) {
tables_->known_bad_files_.insert(name);
tables_->known_bad_files_.insert(std::move(name_string));
return false;
}
return true;
}
bool DescriptorPool::IsSubSymbolOfBuiltType(const std::string& name) const {
std::string prefix = name;
bool DescriptorPool::IsSubSymbolOfBuiltType(StringPiece name) const {
auto prefix = std::string(name);
for (;;) {
std::string::size_type dot_pos = prefix.find_last_of('.');
if (dot_pos == std::string::npos) {
@ -1908,10 +1906,11 @@ bool DescriptorPool::IsSubSymbolOfBuiltType(const std::string& name) const {
}
bool DescriptorPool::TryFindSymbolInFallbackDatabase(
const std::string& name) const {
StringPiece name) const {
if (fallback_database_ == nullptr) return false;
if (tables_->known_bad_symbols_.count(name) > 0) return false;
auto name_string = std::string(name);
if (tables_->known_bad_symbols_.count(name_string) > 0) return false;
FileDescriptorProto file_proto;
if ( // We skip looking in the fallback database if the name is a sub-symbol
@ -1933,7 +1932,7 @@ bool DescriptorPool::TryFindSymbolInFallbackDatabase(
IsSubSymbolOfBuiltType(name)
// Look up file containing this symbol in fallback database.
|| !fallback_database_->FindFileContainingSymbol(name, &file_proto)
|| !fallback_database_->FindFileContainingSymbol(name_string, &file_proto)
// Check if we've already built this file. If so, it apparently doesn't
// contain the symbol we're looking for. Some DescriptorDatabases
@ -1942,7 +1941,7 @@ bool DescriptorPool::TryFindSymbolInFallbackDatabase(
// Build the file.
|| BuildFileFromDatabase(file_proto) == nullptr) {
tables_->known_bad_symbols_.insert(name);
tables_->known_bad_symbols_.insert(std::move(name_string));
return false;
}
@ -3864,7 +3863,7 @@ Symbol DescriptorBuilder::LookupSymbol(
return result;
}
static bool ValidateQualifiedName(const std::string& name) {
static bool ValidateQualifiedName(StringPiece name) {
bool last_was_period = false;
for (int i = 0; i < name.size(); i++) {
@ -3884,14 +3883,14 @@ static bool ValidateQualifiedName(const std::string& name) {
return !name.empty() && !last_was_period;
}
Symbol DescriptorPool::NewPlaceholder(const std::string& name,
Symbol DescriptorPool::NewPlaceholder(StringPiece name,
PlaceholderType placeholder_type) const {
MutexLockMaybe lock(mutex_);
return NewPlaceholderWithMutexHeld(name, placeholder_type);
}
Symbol DescriptorPool::NewPlaceholderWithMutexHeld(
const std::string& name, PlaceholderType placeholder_type) const {
StringPiece name, PlaceholderType placeholder_type) const {
if (mutex_) {
mutex_->AssertHeld();
}
@ -3989,13 +3988,13 @@ Symbol DescriptorPool::NewPlaceholderWithMutexHeld(
}
FileDescriptor* DescriptorPool::NewPlaceholderFile(
const std::string& name) const {
StringPiece name) const {
MutexLockMaybe lock(mutex_);
return NewPlaceholderFileWithMutexHeld(name);
}
FileDescriptor* DescriptorPool::NewPlaceholderFileWithMutexHeld(
const std::string& name) const {
StringPiece name) const {
if (mutex_) {
mutex_->AssertHeld();
}
@ -7269,9 +7268,9 @@ void DescriptorBuilder::LogUnusedDependency(const FileDescriptorProto& proto,
}
}
Symbol DescriptorPool::CrossLinkOnDemandHelper(const std::string& name,
Symbol DescriptorPool::CrossLinkOnDemandHelper(StringPiece name,
bool expecting_enum) const {
std::string lookup_name = name;
auto lookup_name = std::string(name);
if (!lookup_name.empty() && lookup_name[0] == '.') {
lookup_name = lookup_name.substr(1);
}
@ -7399,7 +7398,7 @@ void LazyDescriptor::Set(const Descriptor* descriptor) {
descriptor_ = descriptor;
}
void LazyDescriptor::SetLazy(const std::string& name,
void LazyDescriptor::SetLazy(StringPiece name,
const FileDescriptor* file) {
// verify Init() has been called and Set hasn't been called yet.
GOOGLE_CHECK(!descriptor_);

View File

@ -203,7 +203,7 @@ class PROTOBUF_EXPORT LazyDescriptor {
// build time if the symbol wasn't found and building of the file containing
// that type is delayed because lazily_build_dependencies_ is set on the pool.
// Should not be called after Set() has been called.
void SetLazy(const std::string& name, const FileDescriptor* file);
void SetLazy(StringPiece name, const FileDescriptor* file);
// Returns the current value of the descriptor, thread-safe. If SetLazy(...)
// has been called, will do a one-time cross link of the type specified,
@ -321,20 +321,20 @@ class PROTOBUF_EXPORT Descriptor {
// exists.
const FieldDescriptor* FindFieldByNumber(int number) const;
// Looks up a field by name. Returns nullptr if no such field exists.
const FieldDescriptor* FindFieldByName(const std::string& name) const;
const FieldDescriptor* FindFieldByName(ConstStringParam name) const;
// Looks up a field by lowercased name (as returned by lowercase_name()).
// This lookup may be ambiguous if multiple field names differ only by case,
// in which case the field returned is chosen arbitrarily from the matches.
const FieldDescriptor* FindFieldByLowercaseName(
const std::string& lowercase_name) const;
ConstStringParam lowercase_name) const;
// Looks up a field by camel-case name (as returned by camelcase_name()).
// This lookup may be ambiguous if multiple field names differ in a way that
// leads them to have identical camel-case names, in which case the field
// returned is chosen arbitrarily from the matches.
const FieldDescriptor* FindFieldByCamelcaseName(
const std::string& camelcase_name) const;
ConstStringParam camelcase_name) const;
// The number of oneofs in this message type.
int oneof_decl_count() const;
@ -347,7 +347,7 @@ class PROTOBUF_EXPORT Descriptor {
const OneofDescriptor* oneof_decl(int index) const;
// Looks up a oneof by name. Returns nullptr if no such oneof exists.
const OneofDescriptor* FindOneofByName(const std::string& name) const;
const OneofDescriptor* FindOneofByName(ConstStringParam name) const;
// Nested type stuff -----------------------------------------------
@ -359,7 +359,7 @@ class PROTOBUF_EXPORT Descriptor {
// Looks up a nested type by name. Returns nullptr if no such nested type
// exists.
const Descriptor* FindNestedTypeByName(const std::string& name) const;
const Descriptor* FindNestedTypeByName(ConstStringParam name) const;
// Enum stuff ------------------------------------------------------
@ -371,11 +371,11 @@ class PROTOBUF_EXPORT Descriptor {
// Looks up an enum type by name. Returns nullptr if no such enum type
// exists.
const EnumDescriptor* FindEnumTypeByName(const std::string& name) const;
const EnumDescriptor* FindEnumTypeByName(ConstStringParam name) const;
// Looks up an enum value by name, among all enum types in this message.
// Returns nullptr if no such value exists.
const EnumValueDescriptor* FindEnumValueByName(const std::string& name) const;
const EnumValueDescriptor* FindEnumValueByName(ConstStringParam name) const;
// Extensions ------------------------------------------------------
@ -439,17 +439,17 @@ class PROTOBUF_EXPORT Descriptor {
// Looks up a named extension (which extends some *other* message type)
// defined within this message type's scope.
const FieldDescriptor* FindExtensionByName(const std::string& name) const;
const FieldDescriptor* FindExtensionByName(ConstStringParam name) const;
// Similar to FindFieldByLowercaseName(), but finds extensions defined within
// this message type's scope.
const FieldDescriptor* FindExtensionByLowercaseName(
const std::string& name) const;
ConstStringParam name) const;
// Similar to FindFieldByCamelcaseName(), but finds extensions defined within
// this message type's scope.
const FieldDescriptor* FindExtensionByCamelcaseName(
const std::string& name) const;
ConstStringParam name) const;
// Reserved fields -------------------------------------------------
@ -479,7 +479,7 @@ class PROTOBUF_EXPORT Descriptor {
const std::string& reserved_name(int index) const;
// Returns true if the field name is reserved.
bool IsReservedName(const std::string& name) const;
bool IsReservedName(ConstStringParam name) const;
// Source Location ---------------------------------------------------
@ -1088,7 +1088,7 @@ class PROTOBUF_EXPORT EnumDescriptor {
const std::string& reserved_name(int index) const;
// Returns true if the field name is reserved.
bool IsReservedName(const std::string& name) const;
bool IsReservedName(ConstStringParam name) const;
// Source Location ---------------------------------------------------
@ -1267,7 +1267,7 @@ class PROTOBUF_EXPORT ServiceDescriptor {
const MethodDescriptor* method(int index) const;
// Look up a MethodDescriptor by name.
const MethodDescriptor* FindMethodByName(const std::string& name) const;
const MethodDescriptor* FindMethodByName(ConstStringParam name) const;
// See Descriptor::CopyTo().
void CopyTo(ServiceDescriptorProto* proto) const;
@ -1488,25 +1488,25 @@ class PROTOBUF_EXPORT FileDescriptor {
static const char* SyntaxName(Syntax syntax);
// Find a top-level message type by name. Returns nullptr if not found.
const Descriptor* FindMessageTypeByName(const std::string& name) const;
const Descriptor* FindMessageTypeByName(ConstStringParam name) const;
// Find a top-level enum type by name. Returns nullptr if not found.
const EnumDescriptor* FindEnumTypeByName(const std::string& name) const;
const EnumDescriptor* FindEnumTypeByName(ConstStringParam name) const;
// Find an enum value defined in any top-level enum by name. Returns nullptr
// if not found.
const EnumValueDescriptor* FindEnumValueByName(const std::string& name) const;
const EnumValueDescriptor* FindEnumValueByName(ConstStringParam name) const;
// Find a service definition by name. Returns nullptr if not found.
const ServiceDescriptor* FindServiceByName(const std::string& name) const;
const ServiceDescriptor* FindServiceByName(ConstStringParam name) const;
// Find a top-level extension definition by name. Returns nullptr if not
// found.
const FieldDescriptor* FindExtensionByName(const std::string& name) const;
const FieldDescriptor* FindExtensionByName(ConstStringParam name) const;
// Similar to FindExtensionByName(), but searches by lowercased-name. See
// Descriptor::FindFieldByLowercaseName().
const FieldDescriptor* FindExtensionByLowercaseName(
const std::string& name) const;
ConstStringParam name) const;
// Similar to FindExtensionByName(), but searches by camelcased-name. See
// Descriptor::FindFieldByCamelcaseName().
const FieldDescriptor* FindExtensionByCamelcaseName(
const std::string& name) const;
ConstStringParam name) const;
// See Descriptor::CopyTo().
// Notes:
@ -1669,28 +1669,28 @@ class PROTOBUF_EXPORT DescriptorPool {
// Find a FileDescriptor in the pool by file name. Returns nullptr if not
// found.
const FileDescriptor* FindFileByName(const std::string& name) const;
const FileDescriptor* FindFileByName(ConstStringParam name) const;
// Find the FileDescriptor in the pool which defines the given symbol.
// If any of the Find*ByName() methods below would succeed, then this is
// equivalent to calling that method and calling the result's file() method.
// Otherwise this returns nullptr.
const FileDescriptor* FindFileContainingSymbol(
const std::string& symbol_name) const;
ConstStringParam symbol_name) const;
// Looking up descriptors ------------------------------------------
// These find descriptors by fully-qualified name. These will find both
// top-level descriptors and nested descriptors. They return nullptr if not
// found.
const Descriptor* FindMessageTypeByName(const std::string& name) const;
const FieldDescriptor* FindFieldByName(const std::string& name) const;
const FieldDescriptor* FindExtensionByName(const std::string& name) const;
const OneofDescriptor* FindOneofByName(const std::string& name) const;
const EnumDescriptor* FindEnumTypeByName(const std::string& name) const;
const EnumValueDescriptor* FindEnumValueByName(const std::string& name) const;
const ServiceDescriptor* FindServiceByName(const std::string& name) const;
const MethodDescriptor* FindMethodByName(const std::string& name) const;
const Descriptor* FindMessageTypeByName(ConstStringParam name) const;
const FieldDescriptor* FindFieldByName(ConstStringParam name) const;
const FieldDescriptor* FindExtensionByName(ConstStringParam name) const;
const OneofDescriptor* FindOneofByName(ConstStringParam name) const;
const EnumDescriptor* FindEnumTypeByName(ConstStringParam name) const;
const EnumValueDescriptor* FindEnumValueByName(ConstStringParam name) const;
const ServiceDescriptor* FindServiceByName(ConstStringParam name) const;
const MethodDescriptor* FindMethodByName(ConstStringParam name) const;
// Finds an extension of the given type by number. The extendee must be
// a member of this DescriptorPool or one of its underlays.
@ -1703,7 +1703,7 @@ class PROTOBUF_EXPORT DescriptorPool {
// or one of its underlays. Returns nullptr if there is no known message
// extension with the given printable name.
const FieldDescriptor* FindExtensionByPrintableName(
const Descriptor* extendee, const std::string& printable_name) const;
const Descriptor* extendee, ConstStringParam printable_name) const;
// Finds extensions of extendee. The extensions will be appended to
// out in an undefined order. Only extensions defined directly in
@ -1876,11 +1876,11 @@ class PROTOBUF_EXPORT DescriptorPool {
// For internal (unit test) use only: Returns true if a FileDescriptor has
// been constructed for the given file, false otherwise. Useful for testing
// lazy descriptor initialization behavior.
bool InternalIsFileLoaded(const std::string& filename) const;
bool InternalIsFileLoaded(ConstStringParam filename) const;
// Add a file to unused_import_track_files_. DescriptorBuilder will log
// warnings or errors for those files if there is any unused import.
void AddUnusedImportTrackFile(const std::string& file_name,
void AddUnusedImportTrackFile(ConstStringParam file_name,
bool is_error = false);
void ClearUnusedImportTrackFiles();
@ -1899,14 +1899,14 @@ class PROTOBUF_EXPORT DescriptorPool {
// Return true if the given name is a sub-symbol of any non-package
// descriptor that already exists in the descriptor pool. (The full
// definition of such types is already known.)
bool IsSubSymbolOfBuiltType(const std::string& name) const;
bool IsSubSymbolOfBuiltType(StringPiece name) const;
// Tries to find something in the fallback database and link in the
// corresponding proto file. Returns true if successful, in which case
// the caller should search for the thing again. These are declared
// const because they are called by (semantically) const methods.
bool TryFindFileInFallbackDatabase(const std::string& name) const;
bool TryFindSymbolInFallbackDatabase(const std::string& name) const;
bool TryFindFileInFallbackDatabase(StringPiece name) const;
bool TryFindSymbolInFallbackDatabase(StringPiece name) const;
bool TryFindExtensionInFallbackDatabase(const Descriptor* containing_type,
int field_number) const;
@ -1927,13 +1927,12 @@ class PROTOBUF_EXPORT DescriptorPool {
// symbol is defined if necessary. Will create a placeholder if the type
// doesn't exist in the fallback database, or the file doesn't build
// successfully.
Symbol CrossLinkOnDemandHelper(const std::string& name,
Symbol CrossLinkOnDemandHelper(StringPiece name,
bool expecting_enum) const;
// Create a placeholder FileDescriptor of the specified name
FileDescriptor* NewPlaceholderFile(const std::string& name) const;
FileDescriptor* NewPlaceholderFileWithMutexHeld(
const std::string& name) const;
FileDescriptor* NewPlaceholderFile(StringPiece name) const;
FileDescriptor* NewPlaceholderFileWithMutexHeld(StringPiece name) const;
enum PlaceholderType {
PLACEHOLDER_MESSAGE,
@ -1941,9 +1940,9 @@ class PROTOBUF_EXPORT DescriptorPool {
PLACEHOLDER_EXTENDABLE_MESSAGE
};
// Create a placeholder Descriptor of the specified name
Symbol NewPlaceholder(const std::string& name,
Symbol NewPlaceholder(StringPiece name,
PlaceholderType placeholder_type) const;
Symbol NewPlaceholderWithMutexHeld(const std::string& name,
Symbol NewPlaceholderWithMutexHeld(StringPiece name,
PlaceholderType placeholder_type) const;
// If fallback_database_ is nullptr, this is nullptr. Otherwise, this is a
@ -2126,9 +2125,9 @@ inline bool Descriptor::IsReservedNumber(int number) const {
return FindReservedRangeContainingNumber(number) != nullptr;
}
inline bool Descriptor::IsReservedName(const std::string& name) const {
inline bool Descriptor::IsReservedName(ConstStringParam name) const {
for (int i = 0; i < reserved_name_count(); i++) {
if (name == reserved_name(i)) {
if (name == static_cast<ConstStringParam>(reserved_name(i))) {
return true;
}
}
@ -2145,9 +2144,9 @@ inline bool EnumDescriptor::IsReservedNumber(int number) const {
return FindReservedRangeContainingNumber(number) != nullptr;
}
inline bool EnumDescriptor::IsReservedName(const std::string& name) const {
inline bool EnumDescriptor::IsReservedName(ConstStringParam name) const {
for (int i = 0; i < reserved_name_count(); i++) {
if (name == reserved_name(i)) {
if (name == static_cast<ConstStringParam>(reserved_name(i))) {
return true;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -390,8 +390,6 @@ bool SimpleDescriptorDatabase::MaybeCopy(const FileDescriptorProto* file,
// -------------------------------------------------------------------
class EncodedDescriptorDatabase::DescriptorIndex {
using String = std::string;
public:
using Value = std::pair<const void*, int>;
// Helpers to recursively add particular descriptors and all their contents
@ -410,15 +408,13 @@ class EncodedDescriptorDatabase::DescriptorIndex {
private:
friend class EncodedDescriptorDatabase;
bool AddSymbol(StringPiece package, StringPiece symbol,
Value value);
bool AddSymbol(StringPiece symbol);
template <typename DescProto>
bool AddNestedExtensions(StringPiece filename,
const DescProto& message_type, Value value);
const DescProto& message_type);
template <typename FieldProto>
bool AddExtension(StringPiece filename, const FieldProto& field,
Value value);
bool AddExtension(StringPiece filename, const FieldProto& field);
// All the maps below have two representations:
// - a std::set<> where we insert initially.
@ -429,47 +425,80 @@ class EncodedDescriptorDatabase::DescriptorIndex {
void EnsureFlat();
using String = std::string;
String EncodeString(StringPiece str) const { return String(str); }
StringPiece DecodeString(const String& str, int) const { return str; }
struct EncodedEntry {
// Do not use `Value` here to avoid the padding of that object.
const void* data;
int size;
// Keep the package here instead of each SymbolEntry to save space.
String encoded_package;
Value value() const { return {data, size}; }
};
std::vector<EncodedEntry> all_values_;
struct FileEntry {
String name;
Value data;
int data_offset;
String encoded_name;
StringPiece name(const DescriptorIndex& index) const {
return index.DecodeString(encoded_name, data_offset);
}
};
struct FileCompare {
const DescriptorIndex& index;
bool operator()(const FileEntry& a, const FileEntry& b) const {
return a.name < b.name;
return a.name(index) < b.name(index);
}
bool operator()(const FileEntry& a, StringPiece b) const {
return a.name < b;
return a.name(index) < b;
}
bool operator()(StringPiece a, const FileEntry& b) const {
return a < b.name;
return a < b.name(index);
}
};
std::set<FileEntry, FileCompare> by_name_;
std::set<FileEntry, FileCompare> by_name_{FileCompare{*this}};
std::vector<FileEntry> by_name_flat_;
struct SymbolEntry {
String package;
String symbol;
Value data;
int data_offset;
String encoded_symbol;
std::string AsString() const {
return StrCat(package, package.empty() ? "" : ".", symbol);
StringPiece package(const DescriptorIndex& index) const {
return index.DecodeString(index.all_values_[data_offset].encoded_package,
data_offset);
}
StringPiece symbol(const DescriptorIndex& index) const {
return index.DecodeString(encoded_symbol, data_offset);
}
std::string AsString(const DescriptorIndex& index) const {
auto p = package(index);
return StrCat(p, p.empty() ? "" : ".", symbol(index));
}
};
struct SymbolCompare {
static std::string AsString(const SymbolEntry& entry) {
return entry.AsString();
const DescriptorIndex& index;
std::string AsString(const SymbolEntry& entry) const {
return entry.AsString(index);
}
static StringPiece AsString(StringPiece str) { return str; }
static std::pair<StringPiece, StringPiece> GetParts(
const SymbolEntry& entry) {
if (entry.package.empty()) return {entry.symbol, StringPiece{}};
return {entry.package, entry.symbol};
std::pair<StringPiece, StringPiece> GetParts(
const SymbolEntry& entry) const {
auto package = entry.package(index);
if (package.empty()) return {entry.symbol(index), StringPiece{}};
return {package, entry.symbol(index)};
}
static std::pair<StringPiece, StringPiece> GetParts(
StringPiece str) {
std::pair<StringPiece, StringPiece> GetParts(
StringPiece str) const {
return {str, {}};
}
@ -490,29 +519,35 @@ class EncodedDescriptorDatabase::DescriptorIndex {
return AsString(lhs) < AsString(rhs);
}
};
std::set<SymbolEntry, SymbolCompare> by_symbol_;
std::set<SymbolEntry, SymbolCompare> by_symbol_{SymbolCompare{*this}};
std::vector<SymbolEntry> by_symbol_flat_;
struct ExtensionEntry {
String extendee;
int data_offset;
String encoded_extendee;
StringPiece extendee(const DescriptorIndex& index) const {
return index.DecodeString(encoded_extendee, data_offset).substr(1);
}
int extension_number;
Value data;
};
struct ExtensionCompare {
const DescriptorIndex& index;
bool operator()(const ExtensionEntry& a, const ExtensionEntry& b) const {
return std::tie(a.extendee, a.extension_number) <
std::tie(b.extendee, b.extension_number);
return std::make_tuple(a.extendee(index), a.extension_number) <
std::make_tuple(b.extendee(index), b.extension_number);
}
bool operator()(const ExtensionEntry& a,
std::tuple<StringPiece, int> b) const {
return std::tie(a.extendee, a.extension_number) < b;
return std::make_tuple(a.extendee(index), a.extension_number) < b;
}
bool operator()(std::tuple<StringPiece, int> a,
const ExtensionEntry& b) const {
return a < std::tie(b.extendee, b.extension_number);
return a < std::make_tuple(b.extendee(index), b.extension_number);
}
};
std::set<ExtensionEntry, ExtensionCompare> by_extension_;
std::set<ExtensionEntry, ExtensionCompare> by_extension_{
ExtensionCompare{*this}};
std::vector<ExtensionEntry> by_extension_flat_;
};
@ -591,40 +626,51 @@ bool EncodedDescriptorDatabase::FindAllExtensionNumbers(
template <typename FileProto>
bool EncodedDescriptorDatabase::DescriptorIndex::AddFile(const FileProto& file,
Value value) {
if (!InsertIfNotPresent(&by_name_, FileEntry{file.name(), value}) ||
// We push `value` into the array first. This is important because the AddXXX
// functions below will expect it to be there.
all_values_.push_back({value.first, value.second});
if (!ValidateSymbolName(file.package())) {
GOOGLE_LOG(ERROR) << "Invalid package name: " << file.package();
return false;
}
all_values_.back().encoded_package = EncodeString(file.package());
if (!InsertIfNotPresent(
&by_name_, FileEntry{static_cast<int>(all_values_.size() - 1),
EncodeString(file.name())}) ||
std::binary_search(by_name_flat_.begin(), by_name_flat_.end(),
file.name(), by_name_.key_comp())) {
GOOGLE_LOG(ERROR) << "File already exists in database: " << file.name();
return false;
}
StringPiece package = file.package();
for (const auto& message_type : file.message_type()) {
if (!AddSymbol(package, message_type.name(), value)) return false;
if (!AddNestedExtensions(file.name(), message_type, value)) return false;
if (!AddSymbol(message_type.name())) return false;
if (!AddNestedExtensions(file.name(), message_type)) return false;
}
for (const auto& enum_type : file.enum_type()) {
if (!AddSymbol(package, enum_type.name(), value)) return false;
if (!AddSymbol(enum_type.name())) return false;
}
for (const auto& extension : file.extension()) {
if (!AddSymbol(package, extension.name(), value)) return false;
if (!AddExtension(file.name(), extension, value)) return false;
if (!AddSymbol(extension.name())) return false;
if (!AddExtension(file.name(), extension)) return false;
}
for (const auto& service : file.service()) {
if (!AddSymbol(package, service.name(), value)) return false;
if (!AddSymbol(service.name())) return false;
}
return true;
}
template <typename Iter, typename Iter2>
template <typename Iter, typename Iter2, typename Index>
static bool CheckForMutualSubsymbols(StringPiece symbol_name, Iter* iter,
Iter2 end) {
Iter2 end, const Index& index) {
if (*iter != end) {
if (IsSubSymbol((*iter)->AsString(), symbol_name)) {
if (IsSubSymbol((*iter)->AsString(index), symbol_name)) {
GOOGLE_LOG(ERROR) << "Symbol name \"" << symbol_name
<< "\" conflicts with the existing symbol \""
<< (*iter)->AsString() << "\".";
<< (*iter)->AsString(index) << "\".";
return false;
}
@ -635,10 +681,10 @@ static bool CheckForMutualSubsymbols(StringPiece symbol_name, Iter* iter,
// to increment it.
++*iter;
if (*iter != end && IsSubSymbol(symbol_name, (*iter)->AsString())) {
if (*iter != end && IsSubSymbol(symbol_name, (*iter)->AsString(index))) {
GOOGLE_LOG(ERROR) << "Symbol name \"" << symbol_name
<< "\" conflicts with the existing symbol \""
<< (*iter)->AsString() << "\".";
<< (*iter)->AsString(index) << "\".";
return false;
}
}
@ -646,22 +692,24 @@ static bool CheckForMutualSubsymbols(StringPiece symbol_name, Iter* iter,
}
bool EncodedDescriptorDatabase::DescriptorIndex::AddSymbol(
StringPiece package, StringPiece symbol, Value value) {
SymbolEntry entry = {String(package), String(symbol), value};
std::string entry_as_string = entry.AsString();
StringPiece symbol) {
SymbolEntry entry = {static_cast<int>(all_values_.size() - 1),
EncodeString(symbol)};
std::string entry_as_string = entry.AsString(*this);
// We need to make sure not to violate our map invariant.
// If the symbol name is invalid it could break our lookup algorithm (which
// relies on the fact that '.' sorts before all other characters that are
// valid in symbol names).
if (!ValidateSymbolName(package) || !ValidateSymbolName(symbol)) {
if (!ValidateSymbolName(symbol)) {
GOOGLE_LOG(ERROR) << "Invalid symbol name: " << entry_as_string;
return false;
}
auto iter = FindLastLessOrEqual(&by_symbol_, entry);
if (!CheckForMutualSubsymbols(entry_as_string, &iter, by_symbol_.end())) {
if (!CheckForMutualSubsymbols(entry_as_string, &iter, by_symbol_.end(),
*this)) {
return false;
}
@ -669,7 +717,7 @@ bool EncodedDescriptorDatabase::DescriptorIndex::AddSymbol(
auto flat_iter =
FindLastLessOrEqual(&by_symbol_flat_, entry, by_symbol_.key_comp());
if (!CheckForMutualSubsymbols(entry_as_string, &flat_iter,
by_symbol_flat_.end())) {
by_symbol_flat_.end(), *this)) {
return false;
}
@ -684,25 +732,26 @@ bool EncodedDescriptorDatabase::DescriptorIndex::AddSymbol(
template <typename DescProto>
bool EncodedDescriptorDatabase::DescriptorIndex::AddNestedExtensions(
StringPiece filename, const DescProto& message_type, Value value) {
StringPiece filename, const DescProto& message_type) {
for (const auto& nested_type : message_type.nested_type()) {
if (!AddNestedExtensions(filename, nested_type, value)) return false;
if (!AddNestedExtensions(filename, nested_type)) return false;
}
for (const auto& extension : message_type.extension()) {
if (!AddExtension(filename, extension, value)) return false;
if (!AddExtension(filename, extension)) return false;
}
return true;
}
template <typename FieldProto>
bool EncodedDescriptorDatabase::DescriptorIndex::AddExtension(
StringPiece filename, const FieldProto& field, Value value) {
StringPiece filename, const FieldProto& field) {
if (!field.extendee().empty() && field.extendee()[0] == '.') {
// The extension is fully-qualified. We can use it as a lookup key in
// the by_symbol_ table.
if (!InsertIfNotPresent(&by_extension_,
ExtensionEntry{field.extendee().substr(1),
field.number(), value}) ||
if (!InsertIfNotPresent(
&by_extension_,
ExtensionEntry{static_cast<int>(all_values_.size() - 1),
EncodeString(field.extendee()), field.number()}) ||
std::binary_search(
by_extension_flat_.begin(), by_extension_flat_.end(),
std::make_pair(field.extendee().substr(1), field.number()),
@ -733,8 +782,9 @@ EncodedDescriptorDatabase::DescriptorIndex::FindSymbolOnlyFlat(
auto iter =
FindLastLessOrEqual(&by_symbol_flat_, name, by_symbol_.key_comp());
return iter != by_symbol_flat_.end() && IsSubSymbol(iter->AsString(), name)
? iter->data
return iter != by_symbol_flat_.end() &&
IsSubSymbol(iter->AsString(*this), name)
? all_values_[iter->data_offset].value()
: Value();
}
@ -746,10 +796,11 @@ EncodedDescriptorDatabase::DescriptorIndex::FindExtension(
auto it = std::lower_bound(
by_extension_flat_.begin(), by_extension_flat_.end(),
std::make_tuple(containing_type, field_number), by_extension_.key_comp());
return it == by_extension_flat_.end() || it->extendee != containing_type ||
return it == by_extension_flat_.end() ||
it->extendee(*this) != containing_type ||
it->extension_number != field_number
? std::make_pair(nullptr, 0)
: it->data;
: all_values_[it->data_offset].value();
}
template <typename T, typename Less>
@ -763,6 +814,7 @@ static void MergeIntoFlat(std::set<T, Less>* s, std::vector<T>* flat) {
}
void EncodedDescriptorDatabase::DescriptorIndex::EnsureFlat() {
all_values_.shrink_to_fit();
// Merge each of the sets into their flat counterpart.
MergeIntoFlat(&by_name_, &by_name_flat_);
MergeIntoFlat(&by_symbol_, &by_symbol_flat_);
@ -777,7 +829,8 @@ bool EncodedDescriptorDatabase::DescriptorIndex::FindAllExtensionNumbers(
auto it = std::lower_bound(
by_extension_flat_.begin(), by_extension_flat_.end(),
std::make_tuple(containing_type, 0), by_extension_.key_comp());
for (; it != by_extension_flat_.end() && it->extendee == containing_type;
for (;
it != by_extension_flat_.end() && it->extendee(*this) == containing_type;
++it) {
output->push_back(it->extension_number);
success = true;
@ -791,11 +844,11 @@ void EncodedDescriptorDatabase::DescriptorIndex::FindAllFileNames(
output->resize(by_name_.size() + by_name_flat_.size());
int i = 0;
for (const auto& entry : by_name_) {
(*output)[i] = std::string(entry.name);
(*output)[i] = std::string(entry.name(*this));
i++;
}
for (const auto& entry : by_name_flat_) {
(*output)[i] = std::string(entry.name);
(*output)[i] = std::string(entry.name(*this));
i++;
}
}
@ -807,9 +860,9 @@ EncodedDescriptorDatabase::DescriptorIndex::FindFile(
auto it = std::lower_bound(by_name_flat_.begin(), by_name_flat_.end(),
filename, by_name_.key_comp());
return it == by_name_flat_.end() || it->name != filename
return it == by_name_flat_.end() || it->name(*this) != filename
? std::make_pair(nullptr, 0)
: it->data;
: all_values_[it->data_offset].value();
}

View File

@ -72,10 +72,10 @@ namespace internal {
// an enum name of the given type, returning true and filling in value on
// success, or returning false and leaving value unchanged on failure.
PROTOBUF_EXPORT bool ParseNamedEnum(const EnumDescriptor* descriptor,
StringPiece name, int* value);
ConstStringParam name, int* value);
template <typename EnumType>
bool ParseNamedEnum(const EnumDescriptor* descriptor, StringPiece name,
bool ParseNamedEnum(const EnumDescriptor* descriptor, ConstStringParam name,
EnumType* value) {
int tmp;
if (!ParseNamedEnum(descriptor, name, &tmp)) return false;

View File

@ -82,7 +82,7 @@ bool IsMapFieldInApi(const FieldDescriptor* field) { return field->is_map(); }
namespace internal {
bool ParseNamedEnum(const EnumDescriptor* descriptor, StringPiece name,
bool ParseNamedEnum(const EnumDescriptor* descriptor, ConstStringParam name,
int* value) {
const EnumValueDescriptor* d = descriptor->FindValueByName(name);
if (d == nullptr) return false;

View File

@ -343,8 +343,8 @@ class Map {
}
~Map() {
clear();
if (arena_ == nullptr) {
clear();
delete elements_;
}
}
@ -1218,7 +1218,7 @@ class Map {
first = erase(first);
}
}
void clear() { erase(begin(), end()); }
void clear() { elements_->clear(); }
// Assign
Map& operator=(const Map& other) {

View File

@ -171,7 +171,7 @@ namespace {
#define HASH_MAP std::unordered_map
#define HASH_FXN hash
#define STR_HASH_FXN hash<const char*>
class GeneratedMessageFactory : public MessageFactory {
@ -186,8 +186,8 @@ class GeneratedMessageFactory : public MessageFactory {
private:
// Only written at static init time, so does not require locking.
HASH_MAP<const char*, const google::protobuf::internal::DescriptorTable*,
HASH_FXN<const char*>, streq>
HASH_MAP<const char*, const google::protobuf::internal::DescriptorTable*, STR_HASH_FXN,
streq>
file_map_;
internal::WrappedMutex mutex_;

View File

@ -744,11 +744,9 @@ PROTOBUF_EXPORT PROTOBUF_MUST_USE_RESULT const char* PackedEnumParser(
void* object, const char* ptr, ParseContext* ctx);
template <typename T>
PROTOBUF_EXPORT_TEMPLATE_DEFINE
PROTOBUF_MUST_USE_RESULT const
char* PackedEnumParser(void* object, const char* ptr, ParseContext* ctx,
bool (*is_valid)(int), InternalMetadata* metadata,
int field_num) {
PROTOBUF_MUST_USE_RESULT const char* PackedEnumParser(
void* object, const char* ptr, ParseContext* ctx, bool (*is_valid)(int),
InternalMetadata* metadata, int field_num) {
return ctx->ReadPackedVarint(
ptr, [object, is_valid, metadata, field_num](uint64 val) {
if (is_valid(val)) {
@ -760,12 +758,10 @@ PROTOBUF_MUST_USE_RESULT const
}
template <typename T>
PROTOBUF_EXPORT_TEMPLATE_DEFINE
PROTOBUF_MUST_USE_RESULT const
char* PackedEnumParserArg(void* object, const char* ptr, ParseContext* ctx,
bool (*is_valid)(const void*, int),
const void* data, InternalMetadata* metadata,
int field_num) {
PROTOBUF_MUST_USE_RESULT const char* PackedEnumParserArg(
void* object, const char* ptr, ParseContext* ctx,
bool (*is_valid)(const void*, int), const void* data,
InternalMetadata* metadata, int field_num) {
return ctx->ReadPackedVarint(
ptr, [object, is_valid, data, metadata, field_num](uint64 val) {
if (is_valid(data, val)) {

View File

@ -356,42 +356,42 @@
#endif
#if defined(PROTOBUF_USE_DLLS)
#if defined(_MSC_VER)
#ifdef LIBPROTOBUF_EXPORTS
#define PROTOBUF_EXPORT __declspec(dllexport)
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllexport)
#else
#define PROTOBUF_EXPORT __declspec(dllimport)
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllimport)
#endif
#ifdef LIBPROTOC_EXPORTS
#define PROTOC_EXPORT __declspec(dllexport)
#else
#define PROTOC_EXPORT __declspec(dllimport)
#endif
#else // defined(_MSC_VER)
#ifdef LIBPROTOBUF_EXPORTS
#define PROTOBUF_EXPORT __attribute__((visibility("default")))
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE __attribute__((visibility("default")))
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE
#else
#define PROTOBUF_EXPORT
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE
#endif
#ifdef LIBPROTOC_EXPORTS
#define PROTOC_EXPORT __attribute__((visibility("default")))
#else
#define PROTOC_EXPORT
#endif
#endif
#if defined(_MSC_VER)
#ifdef LIBPROTOBUF_EXPORTS
#define PROTOBUF_EXPORT __declspec(dllexport)
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllexport)
#else
#define PROTOBUF_EXPORT __declspec(dllimport)
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE __declspec(dllimport)
#endif
#ifdef LIBPROTOC_EXPORTS
#define PROTOC_EXPORT __declspec(dllexport)
#else
#define PROTOC_EXPORT __declspec(dllimport)
#endif
#else // defined(_MSC_VER)
#ifdef LIBPROTOBUF_EXPORTS
#define PROTOBUF_EXPORT __attribute__((visibility("default")))
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE __attribute__((visibility("default")))
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE
#else
#define PROTOBUF_EXPORT
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE
#endif
#ifdef LIBPROTOC_EXPORTS
#define PROTOC_EXPORT __attribute__((visibility("default")))
#else
#define PROTOC_EXPORT
#endif
#endif
#else // defined(PROTOBUF_USE_DLLS)
#define PROTOBUF_EXPORT
#define PROTOC_EXPORT
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE
#define PROTOBUF_EXPORT
#define PROTOC_EXPORT
#define PROTOBUF_EXPORT_TEMPLATE_DECLARE
#define PROTOBUF_EXPORT_TEMPLATE_DEFINE
#endif
// Windows declares several inconvenient macro names. We #undef them and then
@ -521,4 +521,6 @@
// ownership of arena. However, we cannot do that for nested messages. In order
// to tell how many usages of nested messages affected by message owned arena,
// we need to simulate the arena ownership.
#define PROTOBUF_MESSAGE_OWNED_ARENA_EXPERIMENT
// This experiment is purely for the purpose of gathering data. All code guarded
// by this flag is supposed to be removed after this experiment.
// #define PROTOBUF_MESSAGE_OWNED_ARENA_EXPERIMENT

View File

@ -191,15 +191,6 @@ class PROTOBUF_EXPORT SourceContext PROTOBUF_FINAL :
std::string* mutable_file_name();
std::string* release_file_name();
void set_allocated_file_name(std::string* file_name);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_file_name();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_file_name(
std::string* file_name);
private:
const std::string& _internal_file_name() const;
void _internal_set_file_name(const std::string& value);
@ -289,25 +280,6 @@ inline void SourceContext::set_allocated_file_name(std::string* file_name) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceContext.file_name)
}
inline std::string* SourceContext::unsafe_arena_release_file_name() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.SourceContext.file_name)
GOOGLE_DCHECK(GetArena() != nullptr);
return file_name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void SourceContext::unsafe_arena_set_allocated_file_name(
std::string* file_name) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (file_name != nullptr) {
} else {
}
file_name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
file_name, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.SourceContext.file_name)
}
#ifdef __GNUC__
#pragma GCC diagnostic pop

View File

@ -456,15 +456,6 @@ class PROTOBUF_EXPORT Value PROTOBUF_FINAL :
std::string* mutable_string_value();
std::string* release_string_value();
void set_allocated_string_value(std::string* string_value);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_string_value();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_string_value(
std::string* string_value);
private:
const std::string& _internal_string_value() const;
void _internal_set_string_value(const std::string& value);
@ -918,29 +909,6 @@ inline void Value::set_allocated_string_value(std::string* string_value) {
}
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.string_value)
}
inline std::string* Value::unsafe_arena_release_string_value() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.string_value)
GOOGLE_DCHECK(GetArena() != nullptr);
if (_internal_has_string_value()) {
clear_has_kind();
return kind_.string_value_.UnsafeArenaRelease(
&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena());
} else {
return nullptr;
}
}
inline void Value::unsafe_arena_set_allocated_string_value(std::string* string_value) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (!_internal_has_string_value()) {
kind_.string_value_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited());
}
clear_kind();
if (string_value) {
set_has_string_value();
kind_.string_value_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), string_value, GetArena());
}
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.string_value)
}
// bool bool_value = 4;
inline bool Value::_internal_has_bool_value() const {

View File

@ -43,9 +43,10 @@
#include <string>
#include <vector>
#include <google/protobuf/stubs/port.h>
#include <google/protobuf/stubs/macros.h>
#include <google/protobuf/stubs/platform_macros.h>
#include <google/protobuf/stubs/port.h>
#include <google/protobuf/stubs/stringpiece.h>
#ifndef PROTOBUF_USE_EXCEPTIONS
#if defined(_MSC_VER) && defined(_CPPUNWIND)
@ -129,12 +130,12 @@ namespace internal {
// structurally_valid.cc.
PROTOBUF_EXPORT bool IsStructurallyValidUTF8(const char* buf, int len);
inline bool IsStructurallyValidUTF8(const std::string& str) {
inline bool IsStructurallyValidUTF8(StringPiece str) {
return IsStructurallyValidUTF8(str.data(), static_cast<int>(str.length()));
}
// Returns initial number of bytes of structurally valid UTF-8.
PROTOBUF_EXPORT int UTF8SpnStructurallyValid(const StringPiece& str);
PROTOBUF_EXPORT int UTF8SpnStructurallyValid(StringPiece str);
// Coerce UTF-8 byte string in src_str to be
// a structurally-valid equal-length string by selectively
@ -148,8 +149,7 @@ PROTOBUF_EXPORT int UTF8SpnStructurallyValid(const StringPiece& str);
//
// Optimized for: all structurally valid and no byte copying is done.
//
PROTOBUF_EXPORT char* UTF8CoerceToStructurallyValid(const StringPiece& str,
char* dst,
PROTOBUF_EXPORT char* UTF8CoerceToStructurallyValid(StringPiece str, char* dst,
char replace_char);
} // namespace internal

View File

@ -33,9 +33,8 @@
#ifndef GOOGLE_PROTOBUF_STUBS_HASH_H__
#define GOOGLE_PROTOBUF_STUBS_HASH_H__
#include <string.h>
#include <google/protobuf/stubs/common.h>
#include <cstring>
#include <string>
#include <unordered_map>
#include <unordered_set>
@ -78,14 +77,14 @@ struct hash<bool> {
};
template <>
struct hash<string> {
inline size_t operator()(const string& key) const {
struct hash<std::string> {
inline size_t operator()(const std::string& key) const {
return hash<const char*>()(key.c_str());
}
static const size_t bucket_size = 4;
static const size_t min_buckets = 8;
inline bool operator()(const string& a, const string& b) const {
inline bool operator()(const std::string& a, const std::string& b) const {
return a < b;
}
};

View File

@ -64,11 +64,11 @@ StringPiece::StringPiece(StringPiece x,
GOOGLE_DCHECK_GE(len, 0);
}
void StringPiece::CopyToString(string* target) const {
void StringPiece::CopyToString(std::string* target) const {
target->assign(ptr_, length_);
}
void StringPiece::AppendToString(string* target) const {
void StringPiece::AppendToString(std::string* target) const {
target->append(ptr_, length_);
}

View File

@ -148,7 +148,6 @@
#include <limits>
#include <string>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/hash.h>
#include <google/protobuf/port_def.inc>
@ -165,7 +164,7 @@ namespace protobuf {
// is 32 bits in LP32, 64 bits in LP64, 64 bits in LLP64
// future changes intended: http://go/64BitStringPiece
//
typedef string::difference_type stringpiece_ssize_type;
typedef std::string::difference_type stringpiece_ssize_type;
// STRINGPIECE_CHECK_SIZE protects us from 32-bit overflows.
// TODO(mec): delete this after stringpiece_ssize_type goes 64 bit.
@ -302,25 +301,21 @@ class PROTOBUF_EXPORT StringPiece {
return 0;
}
string as_string() const {
return ToString();
}
std::string as_string() const { return ToString(); }
// We also define ToString() here, since many other string-like
// interfaces name the routine that converts to a C++ string
// "ToString", and it's confusing to have the method that does that
// for a StringPiece be called "as_string()". We also leave the
// "as_string()" method defined here for existing code.
string ToString() const {
if (ptr_ == nullptr) return string();
return string(data(), static_cast<size_type>(size()));
std::string ToString() const {
if (ptr_ == nullptr) return "";
return std::string(data(), static_cast<size_type>(size()));
}
operator string() const {
return ToString();
}
explicit operator std::string() const { return ToString(); }
void CopyToString(string* target) const;
void AppendToString(string* target) const;
void CopyToString(std::string* target) const;
void AppendToString(std::string* target) const;
bool starts_with(StringPiece x) const {
return (length_ >= x.length_) &&
@ -466,7 +461,7 @@ struct StringPiecePod {
return std::string(data_, static_cast<size_t>(size_));
}
operator string() const { return ToString(); }
explicit operator std::string() const { return ToString(); }
private:
const char* data_;

View File

@ -561,7 +561,7 @@ bool IsStructurallyValidUTF8(const char* buf, int len) {
return (bytes_consumed == len);
}
int UTF8SpnStructurallyValid(const StringPiece& str) {
int UTF8SpnStructurallyValid(StringPiece str) {
if (!module_initialized_) return str.size();
int bytes_consumed = 0;
@ -582,8 +582,7 @@ int UTF8SpnStructurallyValid(const StringPiece& str) {
//
// Fast case: all is structurally valid and no byte copying is done.
//
char* UTF8CoerceToStructurallyValid(const StringPiece& src_str,
char* idst,
char* UTF8CoerceToStructurallyValid(StringPiece src_str, char* idst,
const char replace_char) {
const char* isrc = src_str.data();
const int len = src_str.length();

View File

@ -176,10 +176,8 @@ string StringReplace(const string& s, const string& oldsub,
// the characters in the string, not the entire string as a single delimiter.
// ----------------------------------------------------------------------
template <typename ITR>
static inline
void SplitStringToIteratorUsing(const string& full,
const char* delim,
ITR& result) {
static inline void SplitStringToIteratorUsing(StringPiece full,
const char *delim, ITR &result) {
// Optimize the common case where delim is a single character.
if (delim[0] != '\0' && delim[1] == '\0') {
char c = delim[0];
@ -191,7 +189,7 @@ void SplitStringToIteratorUsing(const string& full,
} else {
const char* start = p;
while (++p != end && *p != c);
*result++ = string(start, p - start);
*result++ = std::string(start, p - start);
}
}
return;
@ -202,17 +200,17 @@ void SplitStringToIteratorUsing(const string& full,
while (begin_index != string::npos) {
end_index = full.find_first_of(delim, begin_index);
if (end_index == string::npos) {
*result++ = full.substr(begin_index);
*result++ = std::string(full.substr(begin_index));
return;
}
*result++ = full.substr(begin_index, (end_index - begin_index));
*result++ =
std::string(full.substr(begin_index, (end_index - begin_index)));
begin_index = full.find_first_not_of(delim, end_index);
}
}
void SplitStringUsing(const string& full,
const char* delim,
std::vector<string>* result) {
void SplitStringUsing(StringPiece full, const char *delim,
std::vector<string> *result) {
std::back_insert_iterator< std::vector<string> > it(*result);
SplitStringToIteratorUsing(full, delim, it);
}
@ -228,29 +226,28 @@ void SplitStringUsing(const string& full,
//
// If "pieces" is negative for some reason, it returns the whole string
// ----------------------------------------------------------------------
template <typename StringType, typename ITR>
static inline
void SplitStringToIteratorAllowEmpty(const StringType& full,
const char* delim,
int pieces,
ITR& result) {
template <typename ITR>
static inline void SplitStringToIteratorAllowEmpty(StringPiece full,
const char *delim,
int pieces, ITR &result) {
string::size_type begin_index, end_index;
begin_index = 0;
for (int i = 0; (i < pieces-1) || (pieces == 0); i++) {
end_index = full.find_first_of(delim, begin_index);
if (end_index == string::npos) {
*result++ = full.substr(begin_index);
*result++ = std::string(full.substr(begin_index));
return;
}
*result++ = full.substr(begin_index, (end_index - begin_index));
*result++ =
std::string(full.substr(begin_index, (end_index - begin_index)));
begin_index = end_index + 1;
}
*result++ = full.substr(begin_index);
*result++ = std::string(full.substr(begin_index));
}
void SplitStringAllowEmpty(const string& full, const char* delim,
std::vector<string>* result) {
void SplitStringAllowEmpty(StringPiece full, const char *delim,
std::vector<string> *result) {
std::back_insert_iterator<std::vector<string> > it(*result);
SplitStringToIteratorAllowEmpty(full, delim, 0, it);
}

View File

@ -113,12 +113,6 @@ inline int hex_digit_to_int(char c) {
// prefix string if the prefix matches, otherwise the original
// string.
// ----------------------------------------------------------------------
inline bool HasPrefixString(const string& str,
const string& prefix) {
return str.size() >= prefix.size() &&
str.compare(0, prefix.size(), prefix) == 0;
}
inline bool HasPrefixString(StringPiece str, StringPiece prefix) {
return str.size() >= prefix.size() &&
memcmp(str.data(), prefix.data(), prefix.size()) == 0;
@ -140,10 +134,10 @@ inline string StripPrefixString(const string& str, const string& prefix) {
// suffix string if the suffix matches, otherwise the original
// string.
// ----------------------------------------------------------------------
inline bool HasSuffixString(const string& str,
const string& suffix) {
inline bool HasSuffixString(StringPiece str, StringPiece suffix) {
return str.size() >= suffix.size() &&
str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0;
memcmp(str.data() + str.size() - suffix.size(), suffix.data(),
suffix.size()) == 0;
}
inline string StripSuffixString(const string& str, const string& suffix) {
@ -219,7 +213,7 @@ PROTOBUF_EXPORT string StringReplace(const string& s, const string& oldsub,
// to 'result'. If there are consecutive delimiters, this function skips
// over all of them.
// ----------------------------------------------------------------------
PROTOBUF_EXPORT void SplitStringUsing(const string& full, const char* delim,
PROTOBUF_EXPORT void SplitStringUsing(StringPiece full, const char* delim,
std::vector<string>* res);
// Split a string using one or more byte delimiters, presented
@ -230,16 +224,15 @@ PROTOBUF_EXPORT void SplitStringUsing(const string& full, const char* delim,
//
// If "full" is the empty string, yields an empty string as the only value.
// ----------------------------------------------------------------------
PROTOBUF_EXPORT void SplitStringAllowEmpty(const string& full,
const char* delim,
PROTOBUF_EXPORT void SplitStringAllowEmpty(StringPiece full, const char* delim,
std::vector<string>* result);
// ----------------------------------------------------------------------
// Split()
// Split a string using a character delimiter.
// ----------------------------------------------------------------------
inline std::vector<string> Split(
const string& full, const char* delim, bool skip_empty = true) {
inline std::vector<string> Split(StringPiece full, const char* delim,
bool skip_empty = true) {
std::vector<string> result;
if (skip_empty) {
SplitStringUsing(full, delim, &result);

View File

@ -369,15 +369,6 @@ class PROTOBUF_EXPORT Type PROTOBUF_FINAL :
std::string* mutable_name();
std::string* release_name();
void set_allocated_name(std::string* name);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_name();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_name(
std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
@ -679,15 +670,6 @@ class PROTOBUF_EXPORT Field PROTOBUF_FINAL :
std::string* mutable_name();
std::string* release_name();
void set_allocated_name(std::string* name);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_name();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_name(
std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
@ -704,15 +686,6 @@ class PROTOBUF_EXPORT Field PROTOBUF_FINAL :
std::string* mutable_type_url();
std::string* release_type_url();
void set_allocated_type_url(std::string* type_url);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_type_url();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_type_url(
std::string* type_url);
private:
const std::string& _internal_type_url() const;
void _internal_set_type_url(const std::string& value);
@ -729,15 +702,6 @@ class PROTOBUF_EXPORT Field PROTOBUF_FINAL :
std::string* mutable_json_name();
std::string* release_json_name();
void set_allocated_json_name(std::string* json_name);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_json_name();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_json_name(
std::string* json_name);
private:
const std::string& _internal_json_name() const;
void _internal_set_json_name(const std::string& value);
@ -754,15 +718,6 @@ class PROTOBUF_EXPORT Field PROTOBUF_FINAL :
std::string* mutable_default_value();
std::string* release_default_value();
void set_allocated_default_value(std::string* default_value);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_default_value();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_default_value(
std::string* default_value);
private:
const std::string& _internal_default_value() const;
void _internal_set_default_value(const std::string& value);
@ -1001,15 +956,6 @@ class PROTOBUF_EXPORT Enum PROTOBUF_FINAL :
std::string* mutable_name();
std::string* release_name();
void set_allocated_name(std::string* name);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_name();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_name(
std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
@ -1205,15 +1151,6 @@ class PROTOBUF_EXPORT EnumValue PROTOBUF_FINAL :
std::string* mutable_name();
std::string* release_name();
void set_allocated_name(std::string* name);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_name();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_name(
std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
@ -1370,15 +1307,6 @@ class PROTOBUF_EXPORT Option PROTOBUF_FINAL :
std::string* mutable_name();
std::string* release_name();
void set_allocated_name(std::string* name);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_name();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_name(
std::string* name);
private:
const std::string& _internal_name() const;
void _internal_set_name(const std::string& value);
@ -1487,25 +1415,6 @@ inline void Type::set_allocated_name(std::string* name) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Type.name)
}
inline std::string* Type::unsafe_arena_release_name() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Type.name)
GOOGLE_DCHECK(GetArena() != nullptr);
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Type::unsafe_arena_set_allocated_name(
std::string* name) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (name != nullptr) {
} else {
}
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
name, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Type.name)
}
// repeated .google.protobuf.Field fields = 2;
inline int Type::_internal_fields_size() const {
@ -1881,25 +1790,6 @@ inline void Field::set_allocated_name(std::string* name) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Field.name)
}
inline std::string* Field::unsafe_arena_release_name() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.name)
GOOGLE_DCHECK(GetArena() != nullptr);
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Field::unsafe_arena_set_allocated_name(
std::string* name) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (name != nullptr) {
} else {
}
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
name, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Field.name)
}
// string type_url = 6;
inline void Field::clear_type_url() {
@ -1962,25 +1852,6 @@ inline void Field::set_allocated_type_url(std::string* type_url) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Field.type_url)
}
inline std::string* Field::unsafe_arena_release_type_url() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.type_url)
GOOGLE_DCHECK(GetArena() != nullptr);
return type_url_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Field::unsafe_arena_set_allocated_type_url(
std::string* type_url) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (type_url != nullptr) {
} else {
}
type_url_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
type_url, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Field.type_url)
}
// int32 oneof_index = 7;
inline void Field::clear_oneof_index() {
@ -2122,25 +1993,6 @@ inline void Field::set_allocated_json_name(std::string* json_name) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Field.json_name)
}
inline std::string* Field::unsafe_arena_release_json_name() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.json_name)
GOOGLE_DCHECK(GetArena() != nullptr);
return json_name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Field::unsafe_arena_set_allocated_json_name(
std::string* json_name) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (json_name != nullptr) {
} else {
}
json_name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
json_name, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Field.json_name)
}
// string default_value = 11;
inline void Field::clear_default_value() {
@ -2203,25 +2055,6 @@ inline void Field::set_allocated_default_value(std::string* default_value) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Field.default_value)
}
inline std::string* Field::unsafe_arena_release_default_value() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Field.default_value)
GOOGLE_DCHECK(GetArena() != nullptr);
return default_value_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Field::unsafe_arena_set_allocated_default_value(
std::string* default_value) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (default_value != nullptr) {
} else {
}
default_value_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
default_value, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Field.default_value)
}
// -------------------------------------------------------------------
@ -2288,25 +2121,6 @@ inline void Enum::set_allocated_name(std::string* name) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Enum.name)
}
inline std::string* Enum::unsafe_arena_release_name() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Enum.name)
GOOGLE_DCHECK(GetArena() != nullptr);
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Enum::unsafe_arena_set_allocated_name(
std::string* name) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (name != nullptr) {
} else {
}
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
name, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Enum.name)
}
// repeated .google.protobuf.EnumValue enumvalue = 2;
inline int Enum::_internal_enumvalue_size() const {
@ -2548,25 +2362,6 @@ inline void EnumValue::set_allocated_name(std::string* name) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.EnumValue.name)
}
inline std::string* EnumValue::unsafe_arena_release_name() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.EnumValue.name)
GOOGLE_DCHECK(GetArena() != nullptr);
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void EnumValue::unsafe_arena_set_allocated_name(
std::string* name) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (name != nullptr) {
} else {
}
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
name, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.EnumValue.name)
}
// int32 number = 2;
inline void EnumValue::clear_number() {
@ -2692,25 +2487,6 @@ inline void Option::set_allocated_name(std::string* name) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.Option.name)
}
inline std::string* Option::unsafe_arena_release_name() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Option.name)
GOOGLE_DCHECK(GetArena() != nullptr);
return name_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void Option::unsafe_arena_set_allocated_name(
std::string* name) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (name != nullptr) {
} else {
}
name_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
name, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Option.name)
}
// .google.protobuf.Any value = 2;
inline bool Option::_internal_has_value() const {

View File

@ -106,7 +106,7 @@ class PROTOBUF_EXPORT FieldMaskUtil {
template <typename T>
static void AddPathToFieldMask(StringPiece path, FieldMask* mask) {
GOOGLE_CHECK(IsValidPath<T>(path)) << path;
mask->add_paths(path);
mask->add_paths(std::string(path));
}
// Creates a FieldMask with all fields of type T. This FieldMask only

View File

@ -60,6 +60,7 @@ namespace protobuf {
namespace util {
namespace converter {
using testing::Eq;
using testing::IsEmpty;
using testing::NanSensitiveDoubleEq;
using testing::NanSensitiveFloatEq;
@ -100,7 +101,7 @@ class ExpectingObjectWriter : public ObjectWriter {
virtual ObjectWriter* StartObject(StringPiece name) {
(name.empty() ? EXPECT_CALL(*mock_, StartObject(IsEmpty()))
: EXPECT_CALL(*mock_, StartObject(StrEq(std::string(name)))))
: EXPECT_CALL(*mock_, StartObject(Eq(std::string(name)))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
return this;
@ -115,7 +116,7 @@ class ExpectingObjectWriter : public ObjectWriter {
virtual ObjectWriter* StartList(StringPiece name) {
(name.empty() ? EXPECT_CALL(*mock_, StartList(IsEmpty()))
: EXPECT_CALL(*mock_, StartList(StrEq(std::string(name)))))
: EXPECT_CALL(*mock_, StartList(Eq(std::string(name)))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
return this;
@ -131,8 +132,8 @@ class ExpectingObjectWriter : public ObjectWriter {
virtual ObjectWriter* RenderBool(StringPiece name, bool value) {
(name.empty()
? EXPECT_CALL(*mock_, RenderBool(IsEmpty(), TypedEq<bool>(value)))
: EXPECT_CALL(*mock_, RenderBool(StrEq(std::string(name)),
TypedEq<bool>(value))))
: EXPECT_CALL(*mock_,
RenderBool(Eq(std::string(name)), TypedEq<bool>(value))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
return this;
@ -141,7 +142,7 @@ class ExpectingObjectWriter : public ObjectWriter {
virtual ObjectWriter* RenderInt32(StringPiece name, int32 value) {
(name.empty()
? EXPECT_CALL(*mock_, RenderInt32(IsEmpty(), TypedEq<int32>(value)))
: EXPECT_CALL(*mock_, RenderInt32(StrEq(std::string(name)),
: EXPECT_CALL(*mock_, RenderInt32(Eq(std::string(name)),
TypedEq<int32>(value))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
@ -151,7 +152,7 @@ class ExpectingObjectWriter : public ObjectWriter {
virtual ObjectWriter* RenderUint32(StringPiece name, uint32 value) {
(name.empty()
? EXPECT_CALL(*mock_, RenderUint32(IsEmpty(), TypedEq<uint32>(value)))
: EXPECT_CALL(*mock_, RenderUint32(StrEq(std::string(name)),
: EXPECT_CALL(*mock_, RenderUint32(Eq(std::string(name)),
TypedEq<uint32>(value))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
@ -161,7 +162,7 @@ class ExpectingObjectWriter : public ObjectWriter {
virtual ObjectWriter* RenderInt64(StringPiece name, int64 value) {
(name.empty()
? EXPECT_CALL(*mock_, RenderInt64(IsEmpty(), TypedEq<int64>(value)))
: EXPECT_CALL(*mock_, RenderInt64(StrEq(std::string(name)),
: EXPECT_CALL(*mock_, RenderInt64(Eq(std::string(name)),
TypedEq<int64>(value))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
@ -171,7 +172,7 @@ class ExpectingObjectWriter : public ObjectWriter {
virtual ObjectWriter* RenderUint64(StringPiece name, uint64 value) {
(name.empty()
? EXPECT_CALL(*mock_, RenderUint64(IsEmpty(), TypedEq<uint64>(value)))
: EXPECT_CALL(*mock_, RenderUint64(StrEq(std::string(name)),
: EXPECT_CALL(*mock_, RenderUint64(Eq(std::string(name)),
TypedEq<uint64>(value))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
@ -182,7 +183,7 @@ class ExpectingObjectWriter : public ObjectWriter {
(name.empty()
? EXPECT_CALL(*mock_,
RenderDouble(IsEmpty(), NanSensitiveDoubleEq(value)))
: EXPECT_CALL(*mock_, RenderDouble(StrEq(std::string(name)),
: EXPECT_CALL(*mock_, RenderDouble(Eq(std::string(name)),
NanSensitiveDoubleEq(value))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
@ -193,7 +194,7 @@ class ExpectingObjectWriter : public ObjectWriter {
(name.empty()
? EXPECT_CALL(*mock_,
RenderFloat(IsEmpty(), NanSensitiveFloatEq(value)))
: EXPECT_CALL(*mock_, RenderFloat(StrEq(std::string(name)),
: EXPECT_CALL(*mock_, RenderFloat(Eq(std::string(name)),
NanSensitiveFloatEq(value))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
@ -205,7 +206,7 @@ class ExpectingObjectWriter : public ObjectWriter {
(name.empty() ? EXPECT_CALL(*mock_, RenderString(IsEmpty(),
TypedEq<StringPiece>(
std::string(value))))
: EXPECT_CALL(*mock_, RenderString(StrEq(std::string(name)),
: EXPECT_CALL(*mock_, RenderString(Eq(std::string(name)),
TypedEq<StringPiece>(
std::string(value)))))
.WillOnce(Return(mock_))
@ -217,7 +218,7 @@ class ExpectingObjectWriter : public ObjectWriter {
? EXPECT_CALL(*mock_, RenderBytes(IsEmpty(), TypedEq<StringPiece>(
value.ToString())))
: EXPECT_CALL(*mock_,
RenderBytes(StrEq(name.ToString()),
RenderBytes(Eq(std::string(name)),
TypedEq<StringPiece>(value.ToString()))))
.WillOnce(Return(mock_))
.RetiresOnSaturation();
@ -226,7 +227,7 @@ class ExpectingObjectWriter : public ObjectWriter {
virtual ObjectWriter* RenderNull(StringPiece name) {
(name.empty() ? EXPECT_CALL(*mock_, RenderNull(IsEmpty()))
: EXPECT_CALL(*mock_, RenderNull(StrEq(std::string(name))))
: EXPECT_CALL(*mock_, RenderNull(Eq(std::string(name))))
.WillOnce(Return(mock_))
.RetiresOnSaturation());
return this;

View File

@ -1182,15 +1182,6 @@ class PROTOBUF_EXPORT StringValue PROTOBUF_FINAL :
std::string* mutable_value();
std::string* release_value();
void set_allocated_value(std::string* value);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_value();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_value(
std::string* value);
private:
const std::string& _internal_value() const;
void _internal_set_value(const std::string& value);
@ -1335,15 +1326,6 @@ class PROTOBUF_EXPORT BytesValue PROTOBUF_FINAL :
std::string* mutable_value();
std::string* release_value();
void set_allocated_value(std::string* value);
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
std::string* unsafe_arena_release_value();
GOOGLE_PROTOBUF_RUNTIME_DEPRECATED("The unsafe_arena_ accessors for"
" string fields are deprecated and will be removed in a"
" future release.")
void unsafe_arena_set_allocated_value(
std::string* value);
private:
const std::string& _internal_value() const;
void _internal_set_value(const std::string& value);
@ -1601,25 +1583,6 @@ inline void StringValue::set_allocated_value(std::string* value) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.StringValue.value)
}
inline std::string* StringValue::unsafe_arena_release_value() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.StringValue.value)
GOOGLE_DCHECK(GetArena() != nullptr);
return value_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void StringValue::unsafe_arena_set_allocated_value(
std::string* value) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (value != nullptr) {
} else {
}
value_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
value, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.StringValue.value)
}
// -------------------------------------------------------------------
@ -1686,25 +1649,6 @@ inline void BytesValue::set_allocated_value(std::string* value) {
GetArena());
// @@protoc_insertion_point(field_set_allocated:google.protobuf.BytesValue.value)
}
inline std::string* BytesValue::unsafe_arena_release_value() {
// @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.BytesValue.value)
GOOGLE_DCHECK(GetArena() != nullptr);
return value_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
GetArena());
}
inline void BytesValue::unsafe_arena_set_allocated_value(
std::string* value) {
GOOGLE_DCHECK(GetArena() != nullptr);
if (value != nullptr) {
} else {
}
value_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(),
value, GetArena());
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.BytesValue.value)
}
#ifdef __GNUC__
#pragma GCC diagnostic pop