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
793d16d5
Commit
793d16d5
authored
Oct 14, 2014
by
gabi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added fast_istr for fast int_to_string
parent
8139d011
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
104 additions
and
0 deletions
+104
-0
fast_istostr.h
include/c11log/details/fast_istostr.h
+104
-0
No files found.
include/c11log/details/fast_istostr.h
0 → 100644
View file @
793d16d5
#pragma once
#include <string>
//Fast to int to string
//Source: http://stackoverflow.com/a/4351484/192001
//Modified version to pad zeros according to min_size
namespace
c11log
{
namespace
details
{
const
char
digit_pairs
[
201
]
=
{
"00010203040506070809"
"10111213141516171819"
"20212223242526272829"
"30313233343536373839"
"40414243444546474849"
"50515253545556575859"
"60616263646566676869"
"70717273747576777879"
"80818283848586878889"
"90919293949596979899"
};
inline
std
::
string
&
fast_itostr
(
int
n
,
std
::
string
&
s
,
int
padding
)
{
if
(
n
==
0
)
{
s
=
"0"
;
return
s
;
}
int
sign
=
-
(
n
<
0
);
unsigned
int
val
=
(
n
^
sign
)
-
sign
;
int
size
;
if
(
val
>=
10000
)
{
if
(
val
>=
10000000
)
{
if
(
val
>=
1000000000
)
size
=
10
;
else
if
(
val
>=
100000000
)
size
=
9
;
else
size
=
8
;
}
else
{
if
(
val
>=
1000000
)
size
=
7
;
else
if
(
val
>=
100000
)
size
=
6
;
else
size
=
5
;
}
}
else
{
if
(
val
>=
100
)
{
if
(
val
>=
1000
)
size
=
4
;
else
size
=
3
;
}
else
{
if
(
val
>=
10
)
size
=
2
;
else
size
=
1
;
}
}
size
-=
sign
;
if
(
size
<
padding
)
size
=
padding
;
s
.
resize
(
size
);
char
*
c
=
&
s
[
0
];
if
(
sign
)
*
c
=
'-'
;
c
+=
size
-
1
;
while
(
val
>=
100
)
{
int
pos
=
val
%
100
;
val
/=
100
;
*
(
short
*
)(
c
-
1
)
=
*
(
short
*
)(
digit_pairs
+
2
*
pos
);
c
-=
2
;
}
while
(
val
>
0
)
{
*
c
--
=
'0'
+
(
val
%
10
);
val
/=
10
;
}
while
(
c
>=
s
.
data
())
*
c
--
=
'0'
;
return
s
;
}
}
}
\ No newline at end of file
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