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
e8efdef8
Commit
e8efdef8
authored
Oct 17, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid extra copy
parent
98f1c1fe
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
15 deletions
+14
-15
include/fmt/format-inl.h
include/fmt/format-inl.h
+8
-4
include/fmt/format.h
include/fmt/format.h
+4
-10
test/format-impl-test.cc
test/format-impl-test.cc
+2
-1
No files found.
include/fmt/format-inl.h
View file @
e8efdef8
...
@@ -667,14 +667,16 @@ FMT_FUNC void format_float(char *buffer, size_t &size, int exp,
...
@@ -667,14 +667,16 @@ FMT_FUNC void format_float(char *buffer, size_t &size, int exp,
template
<
typename
Double
>
template
<
typename
Double
>
FMT_FUNC
typename
std
::
enable_if
<
sizeof
(
Double
)
==
sizeof
(
uint64_t
),
bool
>::
type
FMT_FUNC
typename
std
::
enable_if
<
sizeof
(
Double
)
==
sizeof
(
uint64_t
),
bool
>::
type
grisu2_format
(
Double
value
,
char
*
buffer
,
size_t
&
size
,
grisu2_format
(
Double
value
,
buffer
&
buf
,
grisu2_specs
specs
)
{
grisu2_specs
specs
)
{
FMT_ASSERT
(
value
>=
0
,
"value is negative"
);
FMT_ASSERT
(
value
>=
0
,
"value is negative"
);
char
*
buffer
=
buf
.
data
();
if
(
value
==
0
)
{
if
(
value
==
0
)
{
gen_digits_params
params
(
specs
,
1
);
gen_digits_params
params
(
specs
,
1
);
*
buffer
=
'0'
;
*
buffer
=
'0'
;
size
=
1
;
size
_t
size
=
1
;
format_float
(
buffer
,
size
,
0
,
params
);
format_float
(
buffer
,
size
,
0
,
params
);
FMT_ASSERT
(
buf
.
capacity
()
>=
size
,
""
);
buf
.
resize
(
size
);
return
true
;
return
true
;
}
}
...
@@ -705,12 +707,14 @@ FMT_FUNC typename std::enable_if<sizeof(Double) == sizeof(uint64_t), bool>::type
...
@@ -705,12 +707,14 @@ FMT_FUNC typename std::enable_if<sizeof(Double) == sizeof(uint64_t), bool>::type
// lo (p2 in Grisu) contains the least significants digits of scaled_upper.
// lo (p2 in Grisu) contains the least significants digits of scaled_upper.
// lo = supper % one.
// lo = supper % one.
uint64_t
lo
=
upper
.
f
&
(
one
.
f
-
1
);
uint64_t
lo
=
upper
.
f
&
(
one
.
f
-
1
);
size
=
0
;
size
_t
size
=
0
;
if
(
!
grisu2_gen_digits
(
buffer
,
size
,
hi
,
lo
,
exp
,
delta
,
one
,
diff
,
if
(
!
grisu2_gen_digits
(
buffer
,
size
,
hi
,
lo
,
exp
,
delta
,
one
,
diff
,
params
.
max_digits
))
{
params
.
max_digits
))
{
return
false
;
return
false
;
}
}
format_float
(
buffer
,
size
,
cached_exp
+
exp
,
params
);
format_float
(
buffer
,
size
,
cached_exp
+
exp
,
params
);
FMT_ASSERT
(
buf
.
capacity
()
>=
size
,
""
);
buf
.
resize
(
size
);
return
true
;
return
true
;
}
}
}
// namespace internal
}
// namespace internal
...
...
include/fmt/format.h
View file @
e8efdef8
...
@@ -299,10 +299,10 @@ struct grisu2_specs {
...
@@ -299,10 +299,10 @@ struct grisu2_specs {
// https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf
// https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf
template
<
typename
Double
>
template
<
typename
Double
>
FMT_API
typename
std
::
enable_if
<
sizeof
(
Double
)
==
sizeof
(
uint64_t
),
bool
>::
type
FMT_API
typename
std
::
enable_if
<
sizeof
(
Double
)
==
sizeof
(
uint64_t
),
bool
>::
type
grisu2_format
(
Double
value
,
char
*
buffer
,
size_t
&
size
,
grisu2_specs
);
grisu2_format
(
Double
value
,
buffer
&
buf
,
grisu2_specs
);
template
<
typename
Double
>
template
<
typename
Double
>
inline
typename
std
::
enable_if
<
sizeof
(
Double
)
!=
sizeof
(
uint64_t
),
bool
>::
type
inline
typename
std
::
enable_if
<
sizeof
(
Double
)
!=
sizeof
(
uint64_t
),
bool
>::
type
grisu2_format
(
Double
,
char
*
,
size_t
&
,
grisu2_specs
)
{
return
false
;
}
grisu2_format
(
Double
,
buffer
&
,
grisu2_specs
)
{
return
false
;
}
template
<
typename
Allocator
>
template
<
typename
Allocator
>
typename
Allocator
::
value_type
*
allocate
(
Allocator
&
alloc
,
std
::
size_t
n
)
{
typename
Allocator
::
value_type
*
allocate
(
Allocator
&
alloc
,
std
::
size_t
n
)
{
...
@@ -2862,22 +2862,16 @@ void basic_writer<Range>::write_double(T value, const format_specs &spec) {
...
@@ -2862,22 +2862,16 @@ void basic_writer<Range>::write_double(T value, const format_specs &spec) {
bool
use_grisu
=
internal
::
use_grisu
()
&&
sizeof
(
T
)
<=
sizeof
(
double
)
&&
bool
use_grisu
=
internal
::
use_grisu
()
&&
sizeof
(
T
)
<=
sizeof
(
double
)
&&
type
!=
'a'
&&
type
!=
'A'
;
type
!=
'a'
&&
type
!=
'A'
;
if
(
use_grisu
)
{
if
(
use_grisu
)
{
char
buf
[
100
];
// TODO: correct buffer size
size_t
size
=
0
;
auto
gs
=
internal
::
grisu2_specs
();
auto
gs
=
internal
::
grisu2_specs
();
gs
.
type
=
type
;
gs
.
type
=
type
;
gs
.
precision
=
spec
.
precision
();
gs
.
precision
=
spec
.
precision
();
gs
.
flags
=
spec
.
flags_
;
gs
.
flags
=
spec
.
flags_
;
use_grisu
=
internal
::
grisu2_format
(
use_grisu
=
internal
::
grisu2_format
(
static_cast
<
double
>
(
value
),
buffer
,
gs
);
static_cast
<
double
>
(
value
),
buf
,
size
,
gs
);
if
(
use_grisu
)
{
FMT_ASSERT
(
size
<=
100
,
"buffer overflow"
);
buffer
.
append
(
buf
,
buf
+
size
);
// TODO: avoid extra copy
}
}
}
if
(
!
use_grisu
)
{
if
(
!
use_grisu
)
{
format_specs
normalized_spec
(
spec
);
format_specs
normalized_spec
(
spec
);
normalized_spec
.
type_
=
handler
.
type
;
normalized_spec
.
type_
=
handler
.
type
;
buffer
.
clear
();
write_double_sprintf
(
value
,
normalized_spec
,
buffer
);
write_double_sprintf
(
value
,
normalized_spec
,
buffer
);
}
}
size_t
n
=
buffer
.
size
();
size_t
n
=
buffer
.
size
();
...
...
test/format-impl-test.cc
View file @
e8efdef8
...
@@ -104,7 +104,8 @@ TEST(FPTest, GetCachedPower) {
...
@@ -104,7 +104,8 @@ TEST(FPTest, GetCachedPower) {
TEST
(
FPTest
,
Grisu2FormatCompilesWithNonIEEEDouble
)
{
TEST
(
FPTest
,
Grisu2FormatCompilesWithNonIEEEDouble
)
{
size_t
size
=
0
;
size_t
size
=
0
;
grisu2_format
(
4.2
f
,
FMT_NULL
,
size
,
fmt
::
internal
::
grisu2_specs
());
fmt
::
memory_buffer
buf
;
grisu2_format
(
4.2
f
,
buf
,
fmt
::
internal
::
grisu2_specs
());
}
}
template
<
typename
T
>
template
<
typename
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