Skip to content

CXX-3173 Make make_unique.hpp an internal header #1265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Changes prior to 3.9.0 are documented as [release notes on GitHub](https://githu
- Use `bsoncxx::stdx::optional<T>` instead of `mongocxx::stdx::optional<T>`.
- Use `bsoncxx::stdx::string_view` instead of `mongocxx::stdx::string_view`.
- Inline namespace macros for bsoncxx and mongocxx namespace: `*_INLINE_NAMESPACE_*`.
- The `<bsoncxx/stdx/make_unique.hpp>` header.
- The `<bsoncxx/types/value.hpp>` header.
- The `<bsoncxx/util/functor.hpp>` header.
- The `<mongocxx/options/create_collection.hpp>` header.
Expand Down
53 changes: 26 additions & 27 deletions benchmark/benchmark_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@

#include "benchmark_runner.hpp"

#include <chrono>
#include <cstdint>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <memory>
#include <sstream>

#include "bson/bson_encoding.hpp"
#include "multi_doc/bulk_insert.hpp"
#include "multi_doc/find_many.hpp"
Expand All @@ -34,55 +26,62 @@
#include "single_doc/find_one_by_id.hpp"
#include "single_doc/insert_one.hpp"
#include "single_doc/run_command.hpp"

#include <chrono>
#include <cstdint>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <memory>
#include <sstream>

#include <bsoncxx/builder/basic/array.hpp>
#include <bsoncxx/builder/basic/document.hpp>
#include <bsoncxx/builder/basic/kvp.hpp>
#include <bsoncxx/builder/basic/sub_document.hpp>
#include <bsoncxx/json.hpp>
#include <bsoncxx/stdx/make_unique.hpp>
#include <bsoncxx/types.hpp>

namespace benchmark {

// The task sizes and iteration numbers come from the Driver Perfomance Benchmarking Reference Doc.
benchmark_runner::benchmark_runner(std::set<benchmark_type> types) : _types{types} {
using bsoncxx::stdx::make_unique;

// Bson microbenchmarks
_microbenches.push_back(
make_unique<bson_encoding>("TestFlatEncoding", 75.31, "extended_bson/flat_bson.json"));
std::make_unique<bson_encoding>("TestFlatEncoding", 75.31, "extended_bson/flat_bson.json"));
_microbenches.push_back(
make_unique<bson_encoding>("TestDeepEncoding", 19.64, "extended_bson/deep_bson.json"));
std::make_unique<bson_encoding>("TestDeepEncoding", 19.64, "extended_bson/deep_bson.json"));
_microbenches.push_back(
make_unique<bson_encoding>("TestFullEncoding", 57.34, "extended_bson/full_bson.json"));
std::make_unique<bson_encoding>("TestFullEncoding", 57.34, "extended_bson/full_bson.json"));
// TODO CXX-1241: Add bson_decoding equivalents.

// Single doc microbenchmarks
_microbenches.push_back(make_unique<run_command>());
_microbenches.push_back(make_unique<find_one_by_id>("single_and_multi_document/tweet.json"));
_microbenches.push_back(make_unique<insert_one>(
_microbenches.push_back(std::make_unique<run_command>());
_microbenches.push_back(
std::make_unique<find_one_by_id>("single_and_multi_document/tweet.json"));
_microbenches.push_back(std::make_unique<insert_one>(
"TestSmallDocInsertOne", 2.75, iterations, "single_and_multi_document/small_doc.json"));
_microbenches.push_back(make_unique<insert_one>(
_microbenches.push_back(std::make_unique<insert_one>(
"TestLargeDocInsertOne", 27.31, 10, "single_and_multi_document/large_doc.json"));

// Multi doc microbenchmarks
_microbenches.push_back(make_unique<find_many>("single_and_multi_document/tweet.json"));
_microbenches.push_back(make_unique<bulk_insert>(
_microbenches.push_back(std::make_unique<find_many>("single_and_multi_document/tweet.json"));
_microbenches.push_back(std::make_unique<bulk_insert>(
"TestSmallDocBulkInsert", 2.75, iterations, "single_and_multi_document/small_doc.json"));
_microbenches.push_back(make_unique<bulk_insert>(
_microbenches.push_back(std::make_unique<bulk_insert>(
"TestLargeDocBulkInsert", 27.31, 10, "single_and_multi_document/large_doc.json"));
// CXX-2794: Disable GridFS benchmarks due to long runtime
// _microbenches.push_back(
// make_unique<gridfs_upload>("single_and_multi_document/gridfs_large.bin"));
// std::make_unique<gridfs_upload>("single_and_multi_document/gridfs_large.bin"));
// _microbenches.push_back(
// make_unique<gridfs_download>("single_and_multi_document/gridfs_large.bin"));
// std::make_unique<gridfs_download>("single_and_multi_document/gridfs_large.bin"));

// Parallel microbenchmarks
_microbenches.push_back(make_unique<json_multi_import>("parallel/ldjson_multi"));
_microbenches.push_back(make_unique<json_multi_export>("parallel/ldjson_multi"));
_microbenches.push_back(std::make_unique<json_multi_import>("parallel/ldjson_multi"));
_microbenches.push_back(std::make_unique<json_multi_export>("parallel/ldjson_multi"));
// CXX-2794: Disable GridFS benchmarks due to long runtime
// _microbenches.push_back(make_unique<gridfs_multi_import>("parallel/gridfs_multi"));
// _microbenches.push_back(make_unique<gridfs_multi_export>("parallel/gridfs_multi"));
// _microbenches.push_back(std::make_unique<gridfs_multi_import>("parallel/gridfs_multi"));
// _microbenches.push_back(std::make_unique<gridfs_multi_export>("parallel/gridfs_multi"));

// Need to remove some
if (!_types.empty()) {
Expand Down
9 changes: 5 additions & 4 deletions benchmark/multi_doc/gridfs_download.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

#pragma once

#include "../microbench.hpp"

#include <algorithm>
#include <fstream>
#include <memory>

#include "../microbench.hpp"
#include <bsoncxx/stdx/make_unique.hpp>
#include <bsoncxx/stdx/optional.hpp>

#include <mongocxx/client.hpp>
#include <mongocxx/gridfs/bucket.hpp>
#include <mongocxx/instance.hpp>
Expand All @@ -29,7 +31,6 @@ namespace benchmark {

using bsoncxx::builder::basic::kvp;
using bsoncxx::builder::basic::make_document;
using bsoncxx::stdx::make_unique;

class gridfs_download : public microbench {
public:
Expand Down Expand Up @@ -74,7 +75,7 @@ void gridfs_download::task() {
auto file_length = downloader.file_length();

auto buffer_size = std::min(file_length, static_cast<std::int64_t>(downloader.chunk_size()));
auto buffer = make_unique<std::uint8_t[]>(static_cast<std::size_t>(buffer_size));
auto buffer = std::make_unique<std::uint8_t[]>(static_cast<std::size_t>(buffer_size));

while ([[maybe_unused]] auto length_read =
downloader.read(buffer.get(), static_cast<std::size_t>(buffer_size))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include <bsoncxx/array/view_or_value.hpp>
#include <bsoncxx/document/view_or_value.hpp>
#include <bsoncxx/stdx/make_unique.hpp>
#include <bsoncxx/types/bson_value/view.hpp>

#include <bsoncxx/config/prelude.hpp>
Expand Down
1 change: 1 addition & 0 deletions src/bsoncxx/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ set_dist_list(src_bsoncxx_lib_DIST
bsoncxx/v_noabi/bsoncxx/config/version.hpp.in
bsoncxx/v_noabi/bsoncxx/private/b64_ntop.hh
bsoncxx/v_noabi/bsoncxx/private/helpers.hh
bsoncxx/v_noabi/bsoncxx/private/make_unique.hh
bsoncxx/v_noabi/bsoncxx/private/itoa.hh
bsoncxx/v_noabi/bsoncxx/private/libbson.hh
bsoncxx/v_noabi/bsoncxx/private/stack.hh
Expand Down
4 changes: 2 additions & 2 deletions src/bsoncxx/lib/bsoncxx/v_noabi/bsoncxx/builder/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#include <bsoncxx/exception/exception.hpp>
#include <bsoncxx/private/itoa.hh>
#include <bsoncxx/private/libbson.hh>
#include <bsoncxx/private/make_unique.hh>
#include <bsoncxx/private/stack.hh>
#include <bsoncxx/private/suppress_deprecation_warnings.hh>
#include <bsoncxx/stdx/make_unique.hpp>
#include <bsoncxx/stdx/string_view.hpp>
#include <bsoncxx/string/to_string.hpp>
#include <bsoncxx/types.hpp>
Expand Down Expand Up @@ -256,7 +256,7 @@ class core::impl {
};

core::core(bool is_array) {
_impl = stdx::make_unique<impl>(is_array);
_impl = make_unique<impl>(is_array);
}

core::core(core&&) noexcept = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include <bsoncxx/stdx/type_traits.hpp>

namespace bsoncxx {
namespace v_noabi {
namespace stdx {
namespace detail {

// Switch backend of make_unique by the type we are creating.
Expand Down Expand Up @@ -95,21 +93,17 @@ template <typename T>
struct make_unique_impl<T&&> {};

} // namespace detail
} // namespace stdx
} // namespace v_noabi
} // namespace bsoncxx

#endif // !defined(BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE) ||
// !defined(__cpp_lib_smart_ptr_for_overwrite)

namespace bsoncxx {
namespace v_noabi {
namespace stdx {

// Unlike other C++17 polyfill features, this is a C++14 feature.
// Use feature testing rather than polyfill library selection macros.
#if defined(BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE)
using ::std::make_unique;
using std::make_unique;
#else

// Equivalent to `std::make_unique<T>(args...)` where `T` is a non-array type.
Expand Down Expand Up @@ -143,7 +137,7 @@ std::unique_ptr<T> make_unique(std::size_t count) {
// Unlike other C++17 polyfill features, this is a C++20 feature.
// Use feature testing rather than polyfill library selection macros.
#if defined(__cpp_lib_smart_ptr_for_overwrite)
using ::std::make_unique_for_overwrite;
using std::make_unique_for_overwrite;
#else

// Equivalent to `std::make_unique_for_overwrite<T>()` where `T` is a non-array type.
Expand All @@ -168,68 +162,8 @@ std::unique_ptr<T> make_unique_for_overwrite(std::size_t count) {

#endif

} // namespace stdx
} // namespace v_noabi
} // namespace bsoncxx

#pragma pop_macro("BSONCXX_DETAIL_USE_STD_MAKE_UNIQUE")

#include <bsoncxx/config/postlude.hpp>

namespace bsoncxx {
namespace stdx {

using ::bsoncxx::v_noabi::stdx::make_unique;
using ::bsoncxx::v_noabi::stdx::make_unique_for_overwrite;

} // namespace stdx
} // namespace bsoncxx

///
/// @file
/// Provides `std::make_unique`-related polyfills for internal use.
///
/// @deprecated Primarily for internal use; will be removed in an upcoming major release.
///

#if defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)

namespace bsoncxx {
namespace v_noabi {
namespace stdx {

///
/// Equivalent to `std::make_unique` for non-array types.
///
/// @deprecated Primarily for internal use; will be removed in an upcoming major release.
///
template <typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args);

///
/// Equivalent to `std::make_unique` for array types.
///
/// @deprecated Primarily for internal use. Will be removed in an upcoming major release.
///
template <typename T>
std::unique_ptr<T> make_unique(std::size_t count);

} // namespace stdx
} // namespace v_noabi
} // namespace bsoncxx

namespace bsoncxx {
namespace stdx {

/// @ref bsoncxx::v_noabi::stdx::make_unique(Args&&... args)
template <typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args);

/// @ref bsoncxx::v_noabi::stdx::make_unique(std::size_t count)
template <typename T>
std::unique_ptr<T> make_unique(std::size_t count);

} // namespace stdx
} // namespace bsoncxx

#endif // defined(BSONCXX_PRIVATE_DOXYGEN_PREPROCESSOR)
Loading