Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
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
fmt
Commits
3017fc6f
Commit
3017fc6f
authored
Feb 17, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve 32-bit integer formatting performance by parameterizing FormatDecimal on integer type.
parent
6f6fe519
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
31 deletions
+22
-31
format.cc
format.cc
+0
-29
format.h
format.h
+22
-2
No files found.
format.cc
View file @
3017fc6f
...
...
@@ -169,29 +169,6 @@ typename fmt::BasicWriter<Char>::CharPtr
return
content
;
}
template
<
typename
Char
>
void
fmt
::
internal
::
FormatDecimal
(
Char
*
buffer
,
uint64_t
value
,
unsigned
num_digits
)
{
--
num_digits
;
while
(
value
>=
100
)
{
// Integer division is slow so do it for a group of two digits instead
// of for every digit. The idea comes from the talk by Alexandrescu
// "Three Optimization Tips for C++". See speed-test for a comparison.
unsigned
index
=
(
value
%
100
)
*
2
;
value
/=
100
;
buffer
[
num_digits
]
=
internal
::
DIGITS
[
index
+
1
];
buffer
[
num_digits
-
1
]
=
internal
::
DIGITS
[
index
];
num_digits
-=
2
;
}
if
(
value
<
10
)
{
*
buffer
=
static_cast
<
char
>
(
'0'
+
value
);
return
;
}
unsigned
index
=
static_cast
<
unsigned
>
(
value
*
2
);
buffer
[
1
]
=
internal
::
DIGITS
[
index
+
1
];
buffer
[
0
]
=
internal
::
DIGITS
[
index
];
}
template
<
typename
Char
>
typename
fmt
::
BasicWriter
<
Char
>::
CharPtr
fmt
::
BasicWriter
<
Char
>::
PrepareFilledBuffer
(
...
...
@@ -700,9 +677,6 @@ template fmt::BasicWriter<char>::CharPtr
fmt
::
BasicWriter
<
char
>::
FillPadding
(
CharPtr
buffer
,
unsigned
total_size
,
std
::
size_t
content_size
,
wchar_t
fill
);
template
void
fmt
::
internal
::
FormatDecimal
<
char
>(
char
*
buffer
,
uint64_t
value
,
unsigned
num_digits
);
template
fmt
::
BasicWriter
<
char
>
::
CharPtr
fmt
::
BasicWriter
<
char
>::
PrepareFilledBuffer
(
unsigned
size
,
const
AlignSpec
&
spec
,
char
sign
);
...
...
@@ -732,9 +706,6 @@ template fmt::BasicWriter<wchar_t>::CharPtr
fmt
::
BasicWriter
<
wchar_t
>::
FillPadding
(
CharPtr
buffer
,
unsigned
total_size
,
std
::
size_t
content_size
,
wchar_t
fill
);
template
void
fmt
::
internal
::
FormatDecimal
<
wchar_t
>(
wchar_t
*
buffer
,
uint64_t
value
,
unsigned
num_digits
);
template
fmt
::
BasicWriter
<
wchar_t
>
::
CharPtr
fmt
::
BasicWriter
<
wchar_t
>::
PrepareFilledBuffer
(
unsigned
size
,
const
AlignSpec
&
spec
,
char
sign
);
...
...
format.h
View file @
3017fc6f
...
...
@@ -276,8 +276,28 @@ extern const char DIGITS[];
template
<
typename
Char
>
class
FormatterProxy
;
template
<
typename
Char
>
void
FormatDecimal
(
Char
*
buffer
,
uint64_t
value
,
unsigned
num_digits
);
// Formats a decimal unsigned integer value writing into buffer.
template
<
typename
UInt
,
typename
Char
>
void
FormatDecimal
(
Char
*
buffer
,
UInt
value
,
unsigned
num_digits
)
{
--
num_digits
;
while
(
value
>=
100
)
{
// Integer division is slow so do it for a group of two digits instead
// of for every digit. The idea comes from the talk by Alexandrescu
// "Three Optimization Tips for C++". See speed-test for a comparison.
unsigned
index
=
(
value
%
100
)
*
2
;
value
/=
100
;
buffer
[
num_digits
]
=
internal
::
DIGITS
[
index
+
1
];
buffer
[
num_digits
-
1
]
=
internal
::
DIGITS
[
index
];
num_digits
-=
2
;
}
if
(
value
<
10
)
{
*
buffer
=
static_cast
<
char
>
(
'0'
+
value
);
return
;
}
unsigned
index
=
static_cast
<
unsigned
>
(
value
*
2
);
buffer
[
1
]
=
internal
::
DIGITS
[
index
+
1
];
buffer
[
0
]
=
internal
::
DIGITS
[
index
];
}
}
/**
...
...
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