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
311251eb
Commit
311251eb
authored
Nov 29, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Complete header-only configuration support
parent
c2a6903e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
19 deletions
+31
-19
format.cc
format.cc
+9
-3
format.h
format.h
+22
-16
No files found.
format.cc
View file @
311251eb
...
@@ -391,7 +391,8 @@ int fmt::internal::CharTraits<wchar_t>::format_float(
...
@@ -391,7 +391,8 @@ int fmt::internal::CharTraits<wchar_t>::format_float(
swprintf
(
buffer
,
size
,
format
,
width
,
precision
,
value
);
swprintf
(
buffer
,
size
,
format
,
width
,
precision
,
value
);
}
}
const
char
fmt
::
internal
::
DIGITS
[]
=
template
<
typename
T
>
const
char
fmt
::
internal
::
BasicData
<
T
>::
DIGITS
[]
=
"0001020304050607080910111213141516171819"
"0001020304050607080910111213141516171819"
"2021222324252627282930313233343536373839"
"2021222324252627282930313233343536373839"
"4041424344454647484950515253545556575859"
"4041424344454647484950515253545556575859"
...
@@ -409,8 +410,13 @@ const char fmt::internal::DIGITS[] =
...
@@ -409,8 +410,13 @@ const char fmt::internal::DIGITS[] =
factor * 100000000, \
factor * 100000000, \
factor * 1000000000
factor * 1000000000
const
uint32_t
fmt
::
internal
::
POWERS_OF_10_32
[]
=
{
0
,
FMT_POWERS_OF_10
(
1
)};
template
<
typename
T
>
const
uint64_t
fmt
::
internal
::
POWERS_OF_10_64
[]
=
{
const
uint32_t
fmt
::
internal
::
BasicData
<
T
>::
POWERS_OF_10_32
[]
=
{
0
,
FMT_POWERS_OF_10
(
1
)
};
template
<
typename
T
>
const
uint64_t
fmt
::
internal
::
BasicData
<
T
>::
POWERS_OF_10_64
[]
=
{
0
,
0
,
FMT_POWERS_OF_10
(
1
),
FMT_POWERS_OF_10
(
1
),
FMT_POWERS_OF_10
(
ULongLong
(
1000000000
)),
FMT_POWERS_OF_10
(
ULongLong
(
1000000000
)),
...
...
format.h
View file @
311251eb
...
@@ -510,8 +510,16 @@ FMT_SPECIALIZE_MAKE_UNSIGNED(LongLong, ULongLong);
...
@@ -510,8 +510,16 @@ FMT_SPECIALIZE_MAKE_UNSIGNED(LongLong, ULongLong);
void
report_unknown_type
(
char
code
,
const
char
*
type
);
void
report_unknown_type
(
char
code
,
const
char
*
type
);
extern
const
uint32_t
POWERS_OF_10_32
[];
// Static data is placed in this class template to allow header-only
extern
const
uint64_t
POWERS_OF_10_64
[];
// configuration.
template
<
typename
T
=
void
>
struct
BasicData
{
static
const
uint32_t
POWERS_OF_10_32
[];
static
const
uint64_t
POWERS_OF_10_64
[];
static
const
char
DIGITS
[];
};
typedef
BasicData
<>
Data
;
#if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll)
#if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clzll)
// Returns the number of decimal digits in n. Leading zeros are not counted
// Returns the number of decimal digits in n. Leading zeros are not counted
...
@@ -520,13 +528,13 @@ inline unsigned count_digits(uint64_t n) {
...
@@ -520,13 +528,13 @@ inline unsigned count_digits(uint64_t n) {
// Based on http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
// Based on http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
// and the benchmark https://github.com/localvoid/cxx-benchmark-count-digits.
// and the benchmark https://github.com/localvoid/cxx-benchmark-count-digits.
unsigned
t
=
(
64
-
__builtin_clzll
(
n
|
1
))
*
1233
>>
12
;
unsigned
t
=
(
64
-
__builtin_clzll
(
n
|
1
))
*
1233
>>
12
;
return
t
-
(
n
<
POWERS_OF_10_64
[
t
])
+
1
;
return
t
-
(
n
<
Data
::
POWERS_OF_10_64
[
t
])
+
1
;
}
}
# if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz)
# if FMT_GCC_VERSION >= 400 || FMT_HAS_BUILTIN(__builtin_clz)
// Optional version of count_digits for better performance on 32-bit platforms.
// Optional version of count_digits for better performance on 32-bit platforms.
inline
unsigned
count_digits
(
uint32_t
n
)
{
inline
unsigned
count_digits
(
uint32_t
n
)
{
uint32_t
t
=
(
32
-
__builtin_clz
(
n
|
1
))
*
1233
>>
12
;
uint32_t
t
=
(
32
-
__builtin_clz
(
n
|
1
))
*
1233
>>
12
;
return
t
-
(
n
<
POWERS_OF_10_32
[
t
])
+
1
;
return
t
-
(
n
<
Data
::
POWERS_OF_10_32
[
t
])
+
1
;
}
}
# endif
# endif
#else
#else
...
@@ -547,8 +555,6 @@ inline unsigned count_digits(uint64_t n) {
...
@@ -547,8 +555,6 @@ inline unsigned count_digits(uint64_t n) {
}
}
#endif
#endif
extern
const
char
DIGITS
[];
// Formats a decimal unsigned integer value writing into buffer.
// Formats a decimal unsigned integer value writing into buffer.
template
<
typename
UInt
,
typename
Char
>
template
<
typename
UInt
,
typename
Char
>
inline
void
format_decimal
(
Char
*
buffer
,
UInt
value
,
unsigned
num_digits
)
{
inline
void
format_decimal
(
Char
*
buffer
,
UInt
value
,
unsigned
num_digits
)
{
...
@@ -559,8 +565,8 @@ inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) {
...
@@ -559,8 +565,8 @@ inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) {
// "Three Optimization Tips for C++". See speed-test for a comparison.
// "Three Optimization Tips for C++". See speed-test for a comparison.
unsigned
index
=
(
value
%
100
)
*
2
;
unsigned
index
=
(
value
%
100
)
*
2
;
value
/=
100
;
value
/=
100
;
buffer
[
num_digits
]
=
DIGITS
[
index
+
1
];
buffer
[
num_digits
]
=
D
ata
::
D
IGITS
[
index
+
1
];
buffer
[
num_digits
-
1
]
=
DIGITS
[
index
];
buffer
[
num_digits
-
1
]
=
D
ata
::
D
IGITS
[
index
];
num_digits
-=
2
;
num_digits
-=
2
;
}
}
if
(
value
<
10
)
{
if
(
value
<
10
)
{
...
@@ -568,8 +574,8 @@ inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) {
...
@@ -568,8 +574,8 @@ inline void format_decimal(Char *buffer, UInt value, unsigned num_digits) {
return
;
return
;
}
}
unsigned
index
=
static_cast
<
unsigned
>
(
value
*
2
);
unsigned
index
=
static_cast
<
unsigned
>
(
value
*
2
);
buffer
[
1
]
=
DIGITS
[
index
+
1
];
buffer
[
1
]
=
D
ata
::
D
IGITS
[
index
+
1
];
buffer
[
0
]
=
DIGITS
[
index
];
buffer
[
0
]
=
D
ata
::
D
IGITS
[
index
];
}
}
#ifdef _WIN32
#ifdef _WIN32
...
@@ -2222,16 +2228,16 @@ class FormatInt {
...
@@ -2222,16 +2228,16 @@ class FormatInt {
// "Three Optimization Tips for C++". See speed-test for a comparison.
// "Three Optimization Tips for C++". See speed-test for a comparison.
unsigned
index
=
(
value
%
100
)
*
2
;
unsigned
index
=
(
value
%
100
)
*
2
;
value
/=
100
;
value
/=
100
;
*--
buffer_end
=
internal
::
DIGITS
[
index
+
1
];
*--
buffer_end
=
internal
::
D
ata
::
D
IGITS
[
index
+
1
];
*--
buffer_end
=
internal
::
DIGITS
[
index
];
*--
buffer_end
=
internal
::
D
ata
::
D
IGITS
[
index
];
}
}
if
(
value
<
10
)
{
if
(
value
<
10
)
{
*--
buffer_end
=
static_cast
<
char
>
(
'0'
+
value
);
*--
buffer_end
=
static_cast
<
char
>
(
'0'
+
value
);
return
buffer_end
;
return
buffer_end
;
}
}
unsigned
index
=
static_cast
<
unsigned
>
(
value
*
2
);
unsigned
index
=
static_cast
<
unsigned
>
(
value
*
2
);
*--
buffer_end
=
internal
::
DIGITS
[
index
+
1
];
*--
buffer_end
=
internal
::
D
ata
::
D
IGITS
[
index
+
1
];
*--
buffer_end
=
internal
::
DIGITS
[
index
];
*--
buffer_end
=
internal
::
D
ata
::
D
IGITS
[
index
];
return
buffer_end
;
return
buffer_end
;
}
}
...
@@ -2295,8 +2301,8 @@ inline void format_decimal(char *&buffer, T value) {
...
@@ -2295,8 +2301,8 @@ inline void format_decimal(char *&buffer, T value) {
return
;
return
;
}
}
unsigned
index
=
static_cast
<
unsigned
>
(
abs_value
*
2
);
unsigned
index
=
static_cast
<
unsigned
>
(
abs_value
*
2
);
*
buffer
++
=
internal
::
DIGITS
[
index
];
*
buffer
++
=
internal
::
D
ata
::
D
IGITS
[
index
];
*
buffer
++
=
internal
::
DIGITS
[
index
+
1
];
*
buffer
++
=
internal
::
D
ata
::
D
IGITS
[
index
+
1
];
return
;
return
;
}
}
unsigned
num_digits
=
internal
::
count_digits
(
abs_value
);
unsigned
num_digits
=
internal
::
count_digits
(
abs_value
);
...
...
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