Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
protobuf-c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
protobuf-c
Commits
ef868b71
Unverified
Commit
ef868b71
authored
Oct 18, 2019
by
Robert Edmonds
Committed by
GitHub
Oct 18, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #400 from protobuf-c/ilya-zigzag
protobuf-c.c: Make zigzag encoding more compact
parents
ff04761e
66e8aa5e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
16 deletions
+10
-16
protobuf-c/protobuf-c.c
protobuf-c/protobuf-c.c
+10
-16
No files found.
protobuf-c/protobuf-c.c
View file @
ef868b71
...
...
@@ -312,10 +312,9 @@ int32_size(int32_t v)
static
inline
uint32_t
zigzag32
(
int32_t
v
)
{
if
(
v
<
0
)
return
(
-
(
uint32_t
)
v
)
*
2
-
1
;
else
return
(
uint32_t
)(
v
)
*
2
;
// Note: the right-shift must be arithmetic
// Note: left shift must be unsigned because of overflow
return
((
uint32_t
)(
v
)
<<
1
)
^
(
uint32_t
)(
v
>>
31
);
}
/**
...
...
@@ -377,10 +376,9 @@ uint64_size(uint64_t v)
static
inline
uint64_t
zigzag64
(
int64_t
v
)
{
if
(
v
<
0
)
return
(
-
(
uint64_t
)
v
)
*
2
-
1
;
else
return
(
uint64_t
)(
v
)
*
2
;
// Note: the right-shift must be arithmetic
// Note: left shift must be unsigned because of overflow
return
((
uint64_t
)(
v
)
<<
1
)
^
(
uint64_t
)(
v
>>
63
);
}
/**
...
...
@@ -2423,10 +2421,8 @@ parse_int32(unsigned len, const uint8_t *data)
static
inline
int32_t
unzigzag32
(
uint32_t
v
)
{
if
(
v
&
1
)
return
-
(
v
>>
1
)
-
1
;
else
return
v
>>
1
;
// Note: Using unsigned types prevents undefined behavior
return
(
int32_t
)((
v
>>
1
)
^
(
~
(
v
&
1
)
+
1
));
}
static
inline
uint32_t
...
...
@@ -2467,10 +2463,8 @@ parse_uint64(unsigned len, const uint8_t *data)
static
inline
int64_t
unzigzag64
(
uint64_t
v
)
{
if
(
v
&
1
)
return
-
(
v
>>
1
)
-
1
;
else
return
v
>>
1
;
// Note: Using unsigned types prevents undefined behavior
return
(
int64_t
)((
v
>>
1
)
^
(
~
(
v
&
1
)
+
1
));
}
static
inline
uint64_t
...
...
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