Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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
cpp-libs
Actor Framework
Commits
cd85d1d6
Commit
cd85d1d6
authored
Jul 07, 2017
by
Etienne Baratte
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Serialize vector<bool> efficiently
parent
eba3a1da
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
16 deletions
+28
-16
libcaf_core/caf/data_processor.hpp
libcaf_core/caf/data_processor.hpp
+28
-16
No files found.
libcaf_core/caf/data_processor.hpp
View file @
cd85d1d6
...
...
@@ -226,26 +226,38 @@ public:
return
convert_apply
(
dref
(),
x
,
tmp
,
assign
);
}
// no better way around this abomination
error
consume_range
(
std
::
vector
<
bool
>&
xs
)
{
auto
i
=
xs
.
begin
();
auto
e
=
xs
.
end
();
using
proxy_iterator
=
decltype
(
i
);
// Special case to avoid using 1 byte per bool
error
apply
(
std
::
vector
<
bool
>&
x
)
{
uint64_t
len
=
x
.
size
();
auto
err
=
begin_sequence
(
len
);
if
(
err
||
len
==
0
)
return
err
;
struct
{
void
operator
()(
proxy_iterator
&
lhs
,
bool
&
rhs
)
const
{
*
lhs
=
rhs
;
size_t
len
;
void
operator
()(
std
::
vector
<
bool
>&
lhs
,
std
::
vector
<
uint8_t
>&
rhs
)
const
{
lhs
.
resize
(
len
,
false
);
size_t
cpt
=
0
;
for
(
auto
v
:
rhs
)
{
for
(
int
k
=
0
;
k
<
8
;
++
k
)
{
lhs
[
cpt
]
=
((
v
&
(
1
<<
k
))
!=
0
);
if
(
++
cpt
>=
len
)
return
;
}
void
operator
()(
bool
&
lhs
,
proxy_iterator
&
rhs
)
const
{
lhs
=
*
rhs
;
}
}
assign
;
bool
tmp
;
for
(;
i
!=
e
;
++
i
)
{
auto
err
=
convert_apply
(
dref
(),
i
,
tmp
,
assign
);
if
(
err
)
return
err
;
}
return
none
;
void
operator
()(
std
::
vector
<
uint8_t
>&
lhs
,
std
::
vector
<
bool
>&
rhs
)
const
{
size_t
k
=
0
;
lhs
.
resize
((
rhs
.
size
()
-
1
)
/
8
+
1
,
0
);
for
(
bool
b
:
rhs
)
{
if
(
b
)
lhs
[
k
/
8
]
|=
(
1
<<
(
k
%
8
));
++
k
;
}
}
}
assign
;
assign
.
len
=
len
;
std
::
vector
<
uint8_t
>
tmp
;
return
convert_apply
(
dref
(),
x
,
tmp
,
assign
);
}
template
<
class
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