diff --git a/.gitmodules b/.gitmodules index c6831a364..817760bb4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -47,3 +47,6 @@ [submodule "third-party/wide-integer"] path = third-party/wide-integer url = https://github.com/transmission/wide-integer +[submodule "third-party/small"] + path = third-party/small + url = https://github.com/transmission/small.git diff --git a/CMakeLists.txt b/CMakeLists.txt index d48c3e825..5f1e55123 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -204,11 +204,12 @@ if(WIN32) endif() set(CMAKE_FOLDER "third-party") - -find_package(Fmt) -find_package(WideInteger) find_package(FastFloat) +find_package(Fmt) +find_package(Small) find_package(UtfCpp) +find_package(WideInteger) + find_package(Threads) find_package(PkgConfig QUIET) diff --git a/Transmission.xcodeproj/project.pbxproj b/Transmission.xcodeproj/project.pbxproj index b1eebfd55..505b3413e 100644 --- a/Transmission.xcodeproj/project.pbxproj +++ b/Transmission.xcodeproj/project.pbxproj @@ -3753,6 +3753,7 @@ "third-party/dht", "third-party/fast_float/include", "third-party/fmt/include", + "third-party/small/include", "third-party/jsonsl", "third-party/libb64/include", "third-party/libdeflate", @@ -3798,6 +3799,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", ); WRAPPER_EXTENSION = app; }; @@ -3819,6 +3821,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -3844,6 +3847,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -3865,6 +3869,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4007,6 +4012,7 @@ "third-party/dht", "third-party/fast_float/include", "third-party/fmt/include", + "third-party/small/include", "third-party/jsonsl", "third-party/libb64/include", "third-party/libdeflate", @@ -4042,6 +4048,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4073,6 +4080,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", ); WRAPPER_EXTENSION = app; }; @@ -4274,6 +4282,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", ); WRAPPER_EXTENSION = app; }; @@ -4295,6 +4304,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4333,6 +4343,7 @@ "third-party/dht", "third-party/fast_float/include", "third-party/fmt/include", + "third-party/small/include", "third-party/jsonsl", "third-party/libb64/include", "third-party/libdeflate", @@ -4372,6 +4383,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4393,6 +4405,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4472,6 +4485,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", ); WRAPPER_EXTENSION = qlgenerator; }; @@ -4501,6 +4515,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", ); WRAPPER_EXTENSION = qlgenerator; }; @@ -4530,6 +4545,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", ); WRAPPER_EXTENSION = qlgenerator; }; @@ -4599,6 +4615,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4620,6 +4637,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4812,6 +4830,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4833,6 +4852,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4854,6 +4874,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4875,6 +4896,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4896,6 +4918,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4917,6 +4940,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4938,6 +4962,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4959,6 +4984,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; @@ -4980,6 +5006,7 @@ SYSTEM_HEADER_SEARCH_PATHS = ( "$(inherited)", "third-party/fmt/include", + "third-party/small/include", "third-party/libevent/include", ); }; diff --git a/cmake/FindSmall.cmake b/cmake/FindSmall.cmake new file mode 100644 index 000000000..5905ac47a --- /dev/null +++ b/cmake/FindSmall.cmake @@ -0,0 +1,11 @@ +add_library(small::small INTERFACE IMPORTED) + +target_include_directories(small::small + INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/../third-party/small/include) + + +target_compile_definitions(fmt::fmt-header-only + INTERFACE + SMALL_DISABLE_EXCEPTIONS=1) + diff --git a/libtransmission/CMakeLists.txt b/libtransmission/CMakeLists.txt index b684196e0..7a48df458 100644 --- a/libtransmission/CMakeLists.txt +++ b/libtransmission/CMakeLists.txt @@ -297,6 +297,7 @@ target_link_libraries(${TR_NAME} "$<$:-framework Foundation>" PUBLIC fmt::fmt-header-only + small::small libevent::event) if(INSTALL_LIB) diff --git a/libtransmission/cache.h b/libtransmission/cache.h index 8c50e1188..de521ce33 100644 --- a/libtransmission/cache.h +++ b/libtransmission/cache.h @@ -9,13 +9,15 @@ #error only libtransmission should #include this header. #endif -#include // for size_t +#include // for size_t #include // for intX_t, uintX_t #include #include // for std::unique_ptr #include // for std::pair #include +#include + #include "transmission.h" #include "block-info.h" @@ -26,43 +28,7 @@ struct tr_torrent; class Cache { public: - class BlockData - { - public: - BlockData(size_t size) - : size_{ size } - { - } - - [[nodiscard]] constexpr auto size() const noexcept - { - return size_; - } - - [[nodiscard]] constexpr auto* data() noexcept - { - return std::data(data_); - } - - [[nodiscard]] constexpr const auto* data() const noexcept - { - return std::data(data_); - } - - [[nodiscard]] constexpr auto* begin() const noexcept - { - return data(); - } - - [[nodiscard]] constexpr auto* end() const noexcept - { - return begin() + size(); - } - - private: - std::array data_; - size_t const size_; - }; + using BlockData = small::max_size_vector; Cache(tr_torrents& torrents, int64_t max_bytes); diff --git a/libtransmission/platform.cc b/libtransmission/platform.cc index fd434b750..2557063f0 100644 --- a/libtransmission/platform.cc +++ b/libtransmission/platform.cc @@ -19,6 +19,9 @@ #include /* _beginthreadex(), _endthreadex() */ #include #include /* SHGetKnownFolderPath(), FOLDERID_... */ +#ifdef small // workaround name collision between libsmall and rpcndr.h +#undef small +#endif #else #include #include /* getuid() */ diff --git a/libtransmission/variant.cc b/libtransmission/variant.cc index d62544e93..10086fc22 100644 --- a/libtransmission/variant.cc +++ b/libtransmission/variant.cc @@ -17,6 +17,8 @@ #include +#include + #define LIBTRANSMISSION_VARIANT_MODULE #include "libtransmission/transmission.h" @@ -640,6 +642,8 @@ bool tr_variantDictRemove(tr_variant* dict, tr_quark key) class WalkNode { public: + WalkNode() = default; + explicit WalkNode(tr_variant const* v_in) { assign(v_in); @@ -683,7 +687,8 @@ protected: size_t idx = {}; }; - void sort(std::vector& sortbuf) + template + void sort(Container& sortbuf) { if (!tr_variantIsDict(&v)) { @@ -763,8 +768,10 @@ public: private: size_t size = 0; - std::vector stack; - std::vector sortbuf; + + static auto constexpr InitialCapacity = size_t{ 32U }; + small::vector stack; + small::vector sortbuf; }; /** diff --git a/third-party/small b/third-party/small new file mode 160000 index 000000000..027f6d7eb --- /dev/null +++ b/third-party/small @@ -0,0 +1 @@ +Subproject commit 027f6d7eb61c4a5c7eb699acb7c59b8a5e3d085e