Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
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
spdlog
Commits
0f919304
Commit
0f919304
authored
May 10, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stack_buf improvement after code revie
parent
fdaafdf6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
34 deletions
+47
-34
example.cpp
example/example.cpp
+2
-2
fast_oss.h
include/c11log/details/fast_oss.h
+3
-2
stack_buf.h
include/c11log/details/stack_buf.h
+42
-30
No files found.
example/example.cpp
View file @
0f919304
...
...
@@ -14,9 +14,9 @@ using namespace std::chrono;
using
namespace
c11log
;
using
namespace
utils
;
int
main
(
int
argc
,
char
*
argv
[])
{
details
::
stack_buf
<
12
>
a
;
const
unsigned
int
howmany
=
argc
<=
1
?
1000000
:
atoi
(
argv
[
1
]);
...
...
@@ -33,7 +33,7 @@ int main(int argc, char* argv[])
auto
start
=
system_clock
::
now
();
for
(
unsigned
int
i
=
1
;
i
<=
howmany
;
++
i
)
my_logger
.
info
(
"Hello logger: msg #"
)
<<
i
;
my_logger
.
info
(
)
<<
"Hello logger: msg #"
<<
i
;
//as->shutdown(std::chrono::milliseconds(15000));
auto
delta
=
system_clock
::
now
()
-
start
;
...
...
include/c11log/details/fast_oss.h
View file @
0f919304
...
...
@@ -14,6 +14,7 @@ class stack_devicebuf :public std::streambuf
{
public
:
using
Base
=
std
::
streambuf
;
using
stackbuf
=
stack_buf
<
192
>
;
stack_devicebuf
()
=
default
;
~
stack_devicebuf
()
=
default
;
stack_devicebuf
&
operator
=
(
const
stack_devicebuf
&
)
=
delete
;
...
...
@@ -28,7 +29,7 @@ public:
other
.
clear
();
}
bufpair_t
buf
()
const
stackbuf
::
bufpair_t
buf
()
const
{
return
_stackbuf
.
get
();
}
...
...
@@ -61,7 +62,7 @@ protected:
return
ch
;
}
private
:
stack
_buf
<
128
>
_stackbuf
;
stack
buf
_stackbuf
;
};
class
fast_oss
:
public
std
::
ostream
...
...
include/c11log/details/stack_buf.h
View file @
0f919304
...
...
@@ -3,7 +3,6 @@
#include <array>
#include <vector>
#include <algorithm>
#include <cstring>
// Fast memory storage on the stack when possible or in std::vector
namespace
c11log
...
...
@@ -11,40 +10,32 @@ namespace c11log
namespace
details
{
using
bufpair_t
=
std
::
pair
<
const
char
*
,
std
::
size_t
>
;
template
<
std
::
size_t
STACK_SIZE
=
128
>
template
<
unsigned
short
STACK_SIZE
=
128
>
class
stack_buf
{
public
:
stack_buf
()
:
_v
(),
_stack_array
(),
_stack_size
(
0
)
{}
~
stack_buf
()
{};
using
bufpair_t
=
std
::
pair
<
const
char
*
,
std
::
size_t
>
;
using
iterator
=
char
const
*
;
static
constexpr
unsigned
short
stack_size
=
STACK_SIZE
;
stack_buf
()
:
_v
(),
_stack_size
(
0
)
{}
~
stack_buf
()
=
default
;
stack_buf
&
operator
=
(
const
stack_buf
&
other
)
=
delete
;
stack_buf
(
const
stack_buf
&
other
)
{
_stack_size
=
other
.
_stack_size
;
if
(
!
other
.
_v
.
empty
())
_v
=
other
.
_v
;
else
if
(
_stack_size
)
std
::
copy
(
other
.
_stack_array
.
begin
(),
other
.
_stack_array
.
begin
()
+
_stack_size
,
_stack_array
.
begin
());
}
stack_buf
(
const
stack_buf
&
other
)
:
stack_buf
(
other
,
false
)
{}
stack_buf
(
stack_buf
&&
other
)
stack_buf
(
stack_buf
&&
other
)
:
stack_buf
(
other
,
true
)
{
_stack_size
=
other
.
_stack_size
;
if
(
!
other
.
_v
.
empty
())
_v
=
std
::
move
(
other
.
_v
);
else
if
(
_stack_size
)
std
::
copy
(
other
.
_stack_array
.
begin
(),
other
.
_stack_array
.
begin
()
+
_stack_size
,
_stack_array
.
begin
());
other
.
clear
();
}
void
append
(
const
char
*
buf
,
std
::
size_t
buf_size
)
{
//If we are aleady using _v, forget about the stack
if
(
!
_v
.
empty
())
if
(
vector_used
())
{
_v
.
insert
(
_v
.
end
(),
buf
,
buf
+
buf_size
);
}
...
...
@@ -60,17 +51,12 @@ public:
else
{
_v
.
reserve
(
_stack_size
+
buf_size
);
if
(
_stack_size
)
_v
.
insert
(
_v
.
end
(),
_stack_array
.
begin
(),
_stack_array
.
begin
()
+
_stack_size
);
_v
.
insert
(
_v
.
end
(),
buf
,
buf
+
buf_size
);
}
}
}
void
append
(
const
bufpair_t
&
buf
)
{
append
(
buf
.
first
,
buf
.
second
);
}
void
clear
()
{
...
...
@@ -80,21 +66,47 @@ public:
bufpair_t
get
()
const
{
if
(
!
_v
.
empty
())
if
(
vector_used
())
return
bufpair_t
(
_v
.
data
(),
_v
.
size
());
else
return
bufpair_t
(
_stack_array
.
data
(),
_stack_size
);
}
iterator
begin
()
const
{
return
get
().
first
;
}
iterator
end
()
const
{
bufpair_t
bpair
=
get
();
return
bpair
.
first
+
bpair
.
second
;
}
std
::
size_t
size
()
const
{
if
(
!
_v
.
empty
())
return
_v
.
size
();
else
return
_stack_size
;
return
get
().
second
;
}
private
:
template
<
class
T1
>
stack_buf
(
T1
&&
other
,
bool
is_rval
)
{
_stack_size
=
other
.
_stack_size
;
if
(
other
.
vector_used
())
{
_v
=
is_rval
?
std
::
move
(
other
.
_v
)
:
other
.
_v
;
//_v = std::forward<T1>(other)._v;
}
else
std
::
copy_n
(
other
.
_stack_array
.
begin
(),
other
.
_stack_size
,
_stack_array
.
begin
());
}
bool
vector_used
()
const
{
return
!
(
_v
.
empty
());
}
std
::
vector
<
char
>
_v
;
std
::
array
<
char
,
STACK_SIZE
>
_stack_array
;
std
::
size_t
_stack_size
;
...
...
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