diff --git a/doc/api.rst b/doc/api.rst index f79e1688..2899e880 100644 --- a/doc/api.rst +++ b/doc/api.rst @@ -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; + fmt::basic_memory_buffer; 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, custom_allocator>; - custom_string format(custom_allocator alloc, fmt::string_view format_str, - fmt::format_args args) { + custom_string vformat(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); diff --git a/include/fmt/format.cc b/include/fmt/format.cc index edecd87d..0e7abb23 100644 --- a/include/fmt/format.cc +++ b/include/fmt/format.cc @@ -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() <= internal::INLINE_BUFFER_SIZE - error_code_size) { + if (message.size() <= inline_buffer_size - error_code_size) { w.write(message); w.write(SEP); } w.write(ERROR_STR); w.write(error_code); - assert(out.size() <= internal::INLINE_BUFFER_SIZE); + assert(out.size() <= inline_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(internal::INLINE_BUFFER_SIZE); + buf.resize(inline_buffer_size); for (;;) { char *system_message = &buf[0]; int result = safe_strerror(error_code, system_message, buf.size()); diff --git a/include/fmt/format.h b/include/fmt/format.h index 32652a67..d85d7f7b 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -335,10 +335,6 @@ FMT_CONSTEXPR typename std::make_unsigned::type to_unsigned(Int value) { return static_cast::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 @@ -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 > class basic_memory_buffer: private Allocator, public internal::basic_buffer { private: diff --git a/test/format-impl-test.cc b/test/format-impl-test.cc index f5f29f50..c234c1b4 100644 --- a/test/format-impl-test.cc +++ b/test/format-impl-test.cc @@ -94,7 +94,7 @@ TEST(FormatTest, FormatErrorCode) { { fmt::memory_buffer buffer; std::string prefix( - fmt::internal::INLINE_BUFFER_SIZE - msg.size() - sep.size() + 1, 'x'); + fmt::inline_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::internal::INLINE_BUFFER_SIZE - msg.size() - sep.size(), 'x'); + fmt::inline_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::internal::INLINE_BUFFER_SIZE; + std::size_t size = fmt::inline_buffer_size; EXPECT_EQ(size, buffer.size()); buffer.resize(0); // Test with a message that doesn't fit into the buffer. diff --git a/test/format-test.cc b/test/format-test.cc index 19b57d62..fcf2322f 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -192,11 +192,11 @@ TEST(WriterTest, WriteDoubleWithFilledBuffer) { memory_buffer buf; fmt::writer writer(buf); // Fill the buffer. - for (int i = 0; i < fmt::internal::INLINE_BUFFER_SIZE; ++i) + for (int i = 0; i < fmt::inline_buffer_size; ++i) writer.write(' '); writer.write(1.2); fmt::string_view sv(buf.data(), buf.size()); - sv.remove_prefix(fmt::internal::INLINE_BUFFER_SIZE); + sv.remove_prefix(fmt::inline_buffer_size); EXPECT_EQ("1.2", sv); } diff --git a/test/util-test.cc b/test/util-test.cc index 474fe144..97dabfbb 100644 --- a/test/util-test.cc +++ b/test/util-test.cc @@ -341,7 +341,7 @@ TEST(MemoryBufferTest, Allocator) { { basic_memory_buffer buffer2((TestAllocator(&alloc))); EXPECT_EQ(&alloc, buffer2.get_allocator().get()); - std::size_t size = 2 * fmt::internal::INLINE_BUFFER_SIZE; + std::size_t size = 2 * fmt::inline_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 > TestAllocator; StrictMock< MockAllocator > alloc; basic_memory_buffer buffer((TestAllocator(&alloc))); - std::size_t size = 2 * fmt::internal::INLINE_BUFFER_SIZE; + std::size_t size = 2 * fmt::inline_buffer_size; std::vector mem(size); { EXPECT_CALL(alloc, allocate(size)).WillOnce(Return(&mem[0]));