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
f1ede638
Commit
f1ede638
authored
Mar 04, 2018
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make inline_buffer_size public and update docs
parent
995b63ad
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
20 additions
and
20 deletions
+20
-20
doc/api.rst
doc/api.rst
+3
-3
include/fmt/format.cc
include/fmt/format.cc
+5
-5
include/fmt/format.h
include/fmt/format.h
+5
-5
test/format-impl-test.cc
test/format-impl-test.cc
+3
-3
test/format-test.cc
test/format-test.cc
+2
-2
test/util-test.cc
test/util-test.cc
+2
-2
No files found.
doc/api.rst
View file @
f1ede638
...
...
@@ -253,7 +253,7 @@ A custom allocator class can be specified as a template argument to
:class:`fmt::basic_memory_buffer`::
using custom_memory_buffer =
fmt::basic_memory_buffer<char, custom_allocator>;
fmt::basic_memory_buffer<char,
fmt::inline_buffer_size,
custom_allocator>;
It is also possible to write a formatting function that uses a custom
allocator::
...
...
@@ -261,8 +261,8 @@ allocator::
using custom_string =
std::basic_string<char, std::char_traits<char>, custom_allocator>;
custom_string format(custom_allocator alloc, fmt::string_view format_str,
fmt::format_args args) {
custom_string
v
format(custom_allocator alloc, fmt::string_view format_str,
fmt::format_args args) {
custom_memory_buffer buf(alloc);
fmt::vformat_to(buf, format_str, args);
return custom_string(buf.data(), buf.size(), alloc);
...
...
include/fmt/format.cc
View file @
f1ede638
...
...
@@ -166,7 +166,7 @@ int safe_strerror(
void
format_error_code
(
internal
::
buffer
&
out
,
int
error_code
,
string_view
message
)
FMT_NOEXCEPT
{
// Report error code making sure that the output fits into
//
INLINE_BUFFER_SIZE
to avoid dynamic memory allocation and potential
//
inline_buffer_size
to avoid dynamic memory allocation and potential
// bad_alloc.
out
.
resize
(
0
);
static
const
char
SEP
[]
=
": "
;
...
...
@@ -181,13 +181,13 @@ void format_error_code(internal::buffer &out, int error_code,
}
error_code_size
+=
internal
::
count_digits
(
abs_value
);
writer
w
(
out
);
if
(
message
.
size
()
<=
in
ternal
::
INLINE_BUFFER_SIZE
-
error_code_size
)
{
if
(
message
.
size
()
<=
in
line_buffer_size
-
error_code_size
)
{
w
.
write
(
message
);
w
.
write
(
SEP
);
}
w
.
write
(
ERROR_STR
);
w
.
write
(
error_code
);
assert
(
out
.
size
()
<=
in
ternal
::
INLINE_BUFFER_SIZE
);
assert
(
out
.
size
()
<=
in
line_buffer_size
);
}
void
report_error
(
FormatFunc
func
,
int
error_code
,
...
...
@@ -332,7 +332,7 @@ FMT_FUNC void internal::format_windows_error(
internal
::
buffer
&
out
,
int
error_code
,
string_view
message
)
FMT_NOEXCEPT
{
FMT_TRY
{
wmemory_buffer
buf
;
buf
.
resize
(
INLINE_BUFFER_SIZE
);
buf
.
resize
(
inline_buffer_size
);
for
(;;)
{
wchar_t
*
system_message
=
&
buf
[
0
];
int
result
=
FormatMessageW
(
...
...
@@ -364,7 +364,7 @@ FMT_FUNC void format_system_error(
internal
::
buffer
&
out
,
int
error_code
,
string_view
message
)
FMT_NOEXCEPT
{
FMT_TRY
{
memory_buffer
buf
;
buf
.
resize
(
in
ternal
::
INLINE_BUFFER_SIZE
);
buf
.
resize
(
in
line_buffer_size
);
for
(;;)
{
char
*
system_message
=
&
buf
[
0
];
int
result
=
safe_strerror
(
error_code
,
system_message
,
buf
.
size
());
...
...
include/fmt/format.h
View file @
f1ede638
...
...
@@ -335,10 +335,6 @@ FMT_CONSTEXPR typename std::make_unsigned<Int>::type to_unsigned(Int value) {
return
static_cast
<
typename
std
::
make_unsigned
<
Int
>::
type
>
(
value
);
}
// The number of characters to store in the basic_memory_buffer object itself
// to avoid dynamic memory allocation.
enum
{
INLINE_BUFFER_SIZE
=
500
};
#if FMT_SECURE_SCL
// Use checked iterator to avoid warnings on MSVC.
template
<
typename
T
>
...
...
@@ -371,6 +367,10 @@ class locale_provider {
virtual
fmt
::
locale
locale
();
};
// The number of characters to store in the basic_memory_buffer object itself
// to avoid dynamic memory allocation.
enum
{
inline_buffer_size
=
500
};
/**
\rst
A dynamically growing memory buffer for trivially copyable/constructible types
...
...
@@ -400,7 +400,7 @@ class locale_provider {
The output can be converted to an ``std::string`` with ``to_string(out)``.
\endrst
*/
template
<
typename
T
,
std
::
size_t
SIZE
=
in
ternal
::
INLINE_BUFFER_SIZE
,
template
<
typename
T
,
std
::
size_t
SIZE
=
in
line_buffer_size
,
typename
Allocator
=
std
::
allocator
<
T
>
>
class
basic_memory_buffer
:
private
Allocator
,
public
internal
::
basic_buffer
<
T
>
{
private:
...
...
test/format-impl-test.cc
View file @
f1ede638
...
...
@@ -94,7 +94,7 @@ TEST(FormatTest, FormatErrorCode) {
{
fmt
::
memory_buffer
buffer
;
std
::
string
prefix
(
fmt
::
in
ternal
::
INLINE_BUFFER_SIZE
-
msg
.
size
()
-
sep
.
size
()
+
1
,
'x'
);
fmt
::
in
line_buffer_size
-
msg
.
size
()
-
sep
.
size
()
+
1
,
'x'
);
fmt
::
format_error_code
(
buffer
,
42
,
prefix
);
EXPECT_EQ
(
msg
,
to_string
(
buffer
));
}
...
...
@@ -104,10 +104,10 @@ TEST(FormatTest, FormatErrorCode) {
msg
=
fmt
::
format
(
"error {}"
,
codes
[
i
]);
fmt
::
memory_buffer
buffer
;
std
::
string
prefix
(
fmt
::
in
ternal
::
INLINE_BUFFER_SIZE
-
msg
.
size
()
-
sep
.
size
(),
'x'
);
fmt
::
in
line_buffer_size
-
msg
.
size
()
-
sep
.
size
(),
'x'
);
fmt
::
format_error_code
(
buffer
,
codes
[
i
],
prefix
);
EXPECT_EQ
(
prefix
+
sep
+
msg
,
to_string
(
buffer
));
std
::
size_t
size
=
fmt
::
in
ternal
::
INLINE_BUFFER_SIZE
;
std
::
size_t
size
=
fmt
::
in
line_buffer_size
;
EXPECT_EQ
(
size
,
buffer
.
size
());
buffer
.
resize
(
0
);
// Test with a message that doesn't fit into the buffer.
...
...
test/format-test.cc
View file @
f1ede638
...
...
@@ -192,11 +192,11 @@ TEST(WriterTest, WriteDoubleWithFilledBuffer) {
memory_buffer
buf
;
fmt
::
writer
writer
(
buf
);
// Fill the buffer.
for
(
int
i
=
0
;
i
<
fmt
::
in
ternal
::
INLINE_BUFFER_SIZE
;
++
i
)
for
(
int
i
=
0
;
i
<
fmt
::
in
line_buffer_size
;
++
i
)
writer
.
write
(
' '
);
writer
.
write
(
1.2
);
fmt
::
string_view
sv
(
buf
.
data
(),
buf
.
size
());
sv
.
remove_prefix
(
fmt
::
in
ternal
::
INLINE_BUFFER_SIZE
);
sv
.
remove_prefix
(
fmt
::
in
line_buffer_size
);
EXPECT_EQ
(
"1.2"
,
sv
);
}
...
...
test/util-test.cc
View file @
f1ede638
...
...
@@ -341,7 +341,7 @@ TEST(MemoryBufferTest, Allocator) {
{
basic_memory_buffer
<
char
,
10
,
TestAllocator
>
buffer2
((
TestAllocator
(
&
alloc
)));
EXPECT_EQ
(
&
alloc
,
buffer2
.
get_allocator
().
get
());
std
::
size_t
size
=
2
*
fmt
::
in
ternal
::
INLINE_BUFFER_SIZE
;
std
::
size_t
size
=
2
*
fmt
::
in
line_buffer_size
;
EXPECT_CALL
(
alloc
,
allocate
(
size
)).
WillOnce
(
Return
(
&
mem
));
buffer2
.
reserve
(
size
);
EXPECT_CALL
(
alloc
,
deallocate
(
&
mem
,
size
));
...
...
@@ -352,7 +352,7 @@ TEST(MemoryBufferTest, ExceptionInDeallocate) {
typedef
AllocatorRef
<
MockAllocator
<
char
>
>
TestAllocator
;
StrictMock
<
MockAllocator
<
char
>
>
alloc
;
basic_memory_buffer
<
char
,
10
,
TestAllocator
>
buffer
((
TestAllocator
(
&
alloc
)));
std
::
size_t
size
=
2
*
fmt
::
in
ternal
::
INLINE_BUFFER_SIZE
;
std
::
size_t
size
=
2
*
fmt
::
in
line_buffer_size
;
std
::
vector
<
char
>
mem
(
size
);
{
EXPECT_CALL
(
alloc
,
allocate
(
size
)).
WillOnce
(
Return
(
&
mem
[
0
]));
...
...
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