Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
37c7426b
Commit
37c7426b
authored
Feb 13, 2014
by
xiaofeng@google.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace kEmptyString wth OnceInit initialized string*
parent
f0b6a5cf
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
43 additions
and
30 deletions
+43
-30
cpp_string_field.cc
src/google/protobuf/compiler/cpp/cpp_string_field.cc
+1
-1
plugin.pb.cc
src/google/protobuf/compiler/plugin.pb.cc
+15
-15
plugin.pb.h
src/google/protobuf/compiler/plugin.pb.h
+0
-0
descriptor.cc
src/google/protobuf/descriptor.cc
+3
-5
descriptor.pb.cc
src/google/protobuf/descriptor.pb.cc
+0
-0
descriptor.pb.h
src/google/protobuf/descriptor.pb.h
+0
-0
generated_message_reflection.cc
src/google/protobuf/generated_message_reflection.cc
+5
-5
generated_message_util.cc
src/google/protobuf/generated_message_util.cc
+6
-1
generated_message_util.h
src/google/protobuf/generated_message_util.h
+12
-2
repeated_field.h
src/google/protobuf/repeated_field.h
+1
-1
No files found.
src/google/protobuf/compiler/cpp/cpp_string_field.cc
View file @
37c7426b
...
...
@@ -53,7 +53,7 @@ void SetStringVariables(const FieldDescriptor* descriptor,
(
*
variables
)[
"default_length"
]
=
SimpleItoa
(
descriptor
->
default_value_string
().
length
());
(
*
variables
)[
"default_variable"
]
=
descriptor
->
default_value_string
().
empty
()
?
"&::google::protobuf::internal::
kEmptyString
"
?
"&::google::protobuf::internal::
GetEmptyString()
"
:
"_default_"
+
FieldName
(
descriptor
)
+
"_"
;
(
*
variables
)[
"pointer_type"
]
=
descriptor
->
type
()
==
FieldDescriptor
::
TYPE_BYTES
?
"void"
:
"char"
;
...
...
src/google/protobuf/compiler/plugin.pb.cc
View file @
37c7426b
...
...
@@ -184,7 +184,7 @@ CodeGeneratorRequest::CodeGeneratorRequest(const CodeGeneratorRequest& from)
void
CodeGeneratorRequest
::
SharedCtor
()
{
_cached_size_
=
0
;
parameter_
=
const_cast
<
::
std
::
string
*>
(
&::
google
::
protobuf
::
internal
::
kEmptyString
);
parameter_
=
const_cast
<
::
std
::
string
*>
(
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
);
::
memset
(
_has_bits_
,
0
,
sizeof
(
_has_bits_
));
}
...
...
@@ -193,7 +193,7 @@ CodeGeneratorRequest::~CodeGeneratorRequest() {
}
void
CodeGeneratorRequest
::
SharedDtor
()
{
if
(
parameter_
!=
&::
google
::
protobuf
::
internal
::
kEmptyString
)
{
if
(
parameter_
!=
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
)
{
delete
parameter_
;
}
if
(
this
!=
default_instance_
)
{
...
...
@@ -224,7 +224,7 @@ CodeGeneratorRequest* CodeGeneratorRequest::New() const {
void
CodeGeneratorRequest
::
Clear
()
{
if
(
_has_bits_
[
1
/
32
]
&
(
0xffu
<<
(
1
%
32
)))
{
if
(
has_parameter
())
{
if
(
parameter_
!=
&::
google
::
protobuf
::
internal
::
kEmptyString
)
{
if
(
parameter_
!=
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
)
{
parameter_
->
clear
();
}
}
...
...
@@ -501,9 +501,9 @@ CodeGeneratorResponse_File::CodeGeneratorResponse_File(const CodeGeneratorRespon
void
CodeGeneratorResponse_File
::
SharedCtor
()
{
_cached_size_
=
0
;
name_
=
const_cast
<
::
std
::
string
*>
(
&::
google
::
protobuf
::
internal
::
kEmptyString
);
insertion_point_
=
const_cast
<
::
std
::
string
*>
(
&::
google
::
protobuf
::
internal
::
kEmptyString
);
content_
=
const_cast
<
::
std
::
string
*>
(
&::
google
::
protobuf
::
internal
::
kEmptyString
);
name_
=
const_cast
<
::
std
::
string
*>
(
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
);
insertion_point_
=
const_cast
<
::
std
::
string
*>
(
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
);
content_
=
const_cast
<
::
std
::
string
*>
(
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
);
::
memset
(
_has_bits_
,
0
,
sizeof
(
_has_bits_
));
}
...
...
@@ -512,13 +512,13 @@ CodeGeneratorResponse_File::~CodeGeneratorResponse_File() {
}
void
CodeGeneratorResponse_File
::
SharedDtor
()
{
if
(
name_
!=
&::
google
::
protobuf
::
internal
::
kEmptyString
)
{
if
(
name_
!=
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
)
{
delete
name_
;
}
if
(
insertion_point_
!=
&::
google
::
protobuf
::
internal
::
kEmptyString
)
{
if
(
insertion_point_
!=
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
)
{
delete
insertion_point_
;
}
if
(
content_
!=
&::
google
::
protobuf
::
internal
::
kEmptyString
)
{
if
(
content_
!=
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
)
{
delete
content_
;
}
if
(
this
!=
default_instance_
)
{
...
...
@@ -549,17 +549,17 @@ CodeGeneratorResponse_File* CodeGeneratorResponse_File::New() const {
void
CodeGeneratorResponse_File
::
Clear
()
{
if
(
_has_bits_
[
0
/
32
]
&
(
0xffu
<<
(
0
%
32
)))
{
if
(
has_name
())
{
if
(
name_
!=
&::
google
::
protobuf
::
internal
::
kEmptyString
)
{
if
(
name_
!=
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
)
{
name_
->
clear
();
}
}
if
(
has_insertion_point
())
{
if
(
insertion_point_
!=
&::
google
::
protobuf
::
internal
::
kEmptyString
)
{
if
(
insertion_point_
!=
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
)
{
insertion_point_
->
clear
();
}
}
if
(
has_content
())
{
if
(
content_
!=
&::
google
::
protobuf
::
internal
::
kEmptyString
)
{
if
(
content_
!=
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
)
{
content_
->
clear
();
}
}
...
...
@@ -839,7 +839,7 @@ CodeGeneratorResponse::CodeGeneratorResponse(const CodeGeneratorResponse& from)
void
CodeGeneratorResponse
::
SharedCtor
()
{
_cached_size_
=
0
;
error_
=
const_cast
<
::
std
::
string
*>
(
&::
google
::
protobuf
::
internal
::
kEmptyString
);
error_
=
const_cast
<
::
std
::
string
*>
(
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
);
::
memset
(
_has_bits_
,
0
,
sizeof
(
_has_bits_
));
}
...
...
@@ -848,7 +848,7 @@ CodeGeneratorResponse::~CodeGeneratorResponse() {
}
void
CodeGeneratorResponse
::
SharedDtor
()
{
if
(
error_
!=
&::
google
::
protobuf
::
internal
::
kEmptyString
)
{
if
(
error_
!=
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
)
{
delete
error_
;
}
if
(
this
!=
default_instance_
)
{
...
...
@@ -879,7 +879,7 @@ CodeGeneratorResponse* CodeGeneratorResponse::New() const {
void
CodeGeneratorResponse
::
Clear
()
{
if
(
_has_bits_
[
0
/
32
]
&
(
0xffu
<<
(
0
%
32
)))
{
if
(
has_error
())
{
if
(
error_
!=
&::
google
::
protobuf
::
internal
::
kEmptyString
)
{
if
(
error_
!=
&::
google
::
protobuf
::
internal
::
GetEmptyString
()
)
{
error_
->
clear
();
}
}
...
...
src/google/protobuf/compiler/plugin.pb.h
View file @
37c7426b
This diff is collapsed.
Click to expand it.
src/google/protobuf/descriptor.cc
View file @
37c7426b
...
...
@@ -139,8 +139,6 @@ const int FieldDescriptor::kLastReservedNumber;
namespace
{
const
string
kEmptyString
;
string
ToCamelCase
(
const
string
&
input
)
{
bool
capitalize_next
=
false
;
string
result
;
...
...
@@ -2757,7 +2755,7 @@ Symbol DescriptorBuilder::NewPlaceholder(const string& name,
placeholder_name
=
tables_
->
AllocateString
(
placeholder_full_name
->
substr
(
dotpos
+
1
));
}
else
{
placeholder_package
=
&
kEmptyString
;
placeholder_package
=
&
::
google
::
protobuf
::
internal
::
GetEmptyString
()
;
placeholder_name
=
placeholder_full_name
;
}
...
...
@@ -2843,7 +2841,7 @@ const FileDescriptor* DescriptorBuilder::NewPlaceholderFile(
memset
(
placeholder
,
0
,
sizeof
(
*
placeholder
));
placeholder
->
name_
=
tables_
->
AllocateString
(
name
);
placeholder
->
package_
=
&
kEmptyString
;
placeholder
->
package_
=
&
::
google
::
protobuf
::
internal
::
GetEmptyString
()
;
placeholder
->
pool_
=
pool_
;
placeholder
->
options_
=
&
FileOptions
::
default_instance
();
placeholder
->
tables_
=
&
FileDescriptorTables
::
kEmpty
;
...
...
@@ -3485,7 +3483,7 @@ void DescriptorBuilder::BuildFieldOrExtension(const FieldDescriptorProto& proto,
result
->
default_value_enum_
=
NULL
;
break
;
case
FieldDescriptor
:
:
CPPTYPE_STRING
:
result
->
default_value_string_
=
&
kEmptyString
;
result
->
default_value_string_
=
&
::
google
::
protobuf
::
internal
::
GetEmptyString
()
;
break
;
case
FieldDescriptor
:
:
CPPTYPE_MESSAGE
:
break
;
...
...
src/google/protobuf/descriptor.pb.cc
View file @
37c7426b
This diff is collapsed.
Click to expand it.
src/google/protobuf/descriptor.pb.h
View file @
37c7426b
This diff is collapsed.
Click to expand it.
src/google/protobuf/generated_message_reflection.cc
View file @
37c7426b
...
...
@@ -68,7 +68,7 @@ bool ParseNamedEnum(const EnumDescriptor* descriptor,
const
string
&
NameOfEnum
(
const
EnumDescriptor
*
descriptor
,
int
value
)
{
const
EnumValueDescriptor
*
d
=
descriptor
->
FindValueByNumber
(
value
);
return
(
d
==
NULL
?
kEmptyString
:
d
->
name
());
return
(
d
==
NULL
?
GetEmptyString
()
:
d
->
name
());
}
// ===================================================================
...
...
@@ -771,7 +771,7 @@ string GeneratedMessageReflection::GetString(
}
GOOGLE_LOG
(
FATAL
)
<<
"Can't get here."
;
return
kEmptyString
;
// Make compiler happy.
return
GetEmptyString
()
;
// Make compiler happy.
}
}
...
...
@@ -790,7 +790,7 @@ const string& GeneratedMessageReflection::GetStringReference(
}
GOOGLE_LOG
(
FATAL
)
<<
"Can't get here."
;
return
kEmptyString
;
// Make compiler happy.
return
GetEmptyString
()
;
// Make compiler happy.
}
}
...
...
@@ -832,7 +832,7 @@ string GeneratedMessageReflection::GetRepeatedString(
}
GOOGLE_LOG
(
FATAL
)
<<
"Can't get here."
;
return
kEmptyString
;
// Make compiler happy.
return
GetEmptyString
()
;
// Make compiler happy.
}
}
...
...
@@ -850,7 +850,7 @@ const string& GeneratedMessageReflection::GetRepeatedStringReference(
}
GOOGLE_LOG
(
FATAL
)
<<
"Can't get here."
;
return
kEmptyString
;
// Make compiler happy.
return
GetEmptyString
()
;
// Make compiler happy.
}
}
...
...
src/google/protobuf/generated_message_util.cc
View file @
37c7426b
...
...
@@ -47,7 +47,12 @@ double NaN() {
return
std
::
numeric_limits
<
double
>::
quiet_NaN
();
}
const
::
std
::
string
kEmptyString
;
const
::
std
::
string
*
empty_string_
;
ProtobufOnceType
empty_string_once_init_
;
void
InitEmptyString
()
{
empty_string_
=
new
std
::
string
;
}
}
// namespace internal
}
// namespace protobuf
...
...
src/google/protobuf/generated_message_util.h
View file @
37c7426b
...
...
@@ -41,6 +41,7 @@
#include <string>
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/once.h>
namespace
google
{
namespace
protobuf
{
namespace
internal
{
...
...
@@ -59,8 +60,17 @@ namespace internal {
LIBPROTOBUF_EXPORT
double
Infinity
();
LIBPROTOBUF_EXPORT
double
NaN
();
// Constant used for empty default strings.
LIBPROTOBUF_EXPORT
extern
const
::
std
::
string
kEmptyString
;
// Default empty string object. Don't use the pointer directly. Instead, call
// GetEmptyString() to get the reference.
LIBPROTOBUF_EXPORT
extern
const
::
std
::
string
*
empty_string_
;
LIBPROTOBUF_EXPORT
extern
ProtobufOnceType
empty_string_once_init_
;
LIBPROTOBUF_EXPORT
void
InitEmptyString
();
LIBPROTOBUF_EXPORT
inline
const
::
std
::
string
&
GetEmptyString
()
{
GoogleOnceInit
(
&
empty_string_once_init_
,
&
InitEmptyString
);
return
*
empty_string_
;
}
// Defined in generated_message_reflection.cc -- not actually part of the lite
// library.
...
...
src/google/protobuf/repeated_field.h
View file @
37c7426b
...
...
@@ -383,7 +383,7 @@ class LIBPROTOBUF_EXPORT StringTypeHandlerBase {
static
void
Clear
(
string
*
value
)
{
value
->
clear
();
}
static
void
Merge
(
const
string
&
from
,
string
*
to
)
{
*
to
=
from
;
}
static
const
Type
&
default_instance
()
{
return
::
google
::
protobuf
::
internal
::
kEmptyString
;
return
::
google
::
protobuf
::
internal
::
GetEmptyString
()
;
}
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment