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
a426833d
Unverified
Commit
a426833d
authored
Dec 08, 2017
by
Adam Cozzette
Committed by
GitHub
Dec 08, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4000 from Kwizatz/master
Using binary one's complement to negate an unsigned int
parents
9b09a2af
24493eef
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
2 deletions
+2
-2
wire_format_lite.h
src/google/protobuf/wire_format_lite.h
+2
-2
No files found.
src/google/protobuf/wire_format_lite.h
View file @
a426833d
...
@@ -860,7 +860,7 @@ inline uint32 WireFormatLite::ZigZagEncode32(int32 n) {
...
@@ -860,7 +860,7 @@ inline uint32 WireFormatLite::ZigZagEncode32(int32 n) {
inline
int32
WireFormatLite
::
ZigZagDecode32
(
uint32
n
)
{
inline
int32
WireFormatLite
::
ZigZagDecode32
(
uint32
n
)
{
// Note: Using unsigned types prevent undefined behavior
// Note: Using unsigned types prevent undefined behavior
return
static_cast
<
int32
>
((
n
>>
1
)
^
-
(
n
&
1
));
return
static_cast
<
int32
>
((
n
>>
1
)
^
(
~
(
n
&
1
)
+
1
));
}
}
inline
uint64
WireFormatLite
::
ZigZagEncode64
(
int64
n
)
{
inline
uint64
WireFormatLite
::
ZigZagEncode64
(
int64
n
)
{
...
@@ -871,7 +871,7 @@ inline uint64 WireFormatLite::ZigZagEncode64(int64 n) {
...
@@ -871,7 +871,7 @@ inline uint64 WireFormatLite::ZigZagEncode64(int64 n) {
inline
int64
WireFormatLite
::
ZigZagDecode64
(
uint64
n
)
{
inline
int64
WireFormatLite
::
ZigZagDecode64
(
uint64
n
)
{
// Note: Using unsigned types prevent undefined behavior
// Note: Using unsigned types prevent undefined behavior
return
static_cast
<
int64
>
((
n
>>
1
)
^
-
(
n
&
1
));
return
static_cast
<
int64
>
((
n
>>
1
)
^
(
~
(
n
&
1
)
+
1
));
}
}
// String is for UTF-8 text only, but, even so, ReadString() can simply
// String is for UTF-8 text only, but, even so, ReadString() can simply
...
...
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