1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-01-30 02:42:11 +00:00

refactor: add libsmall dependency (#5649)

* refactor: add small dependency

* refactor: use small in variant.cc

* refactor: use small in cache.h
This commit is contained in:
Charles Kerr 2023-06-20 22:50:36 -05:00 committed by GitHub
parent 548f840b8d
commit 432fc9bafc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 64 additions and 44 deletions

3
.gitmodules vendored
View file

@ -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

View file

@ -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)

View file

@ -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",
);
};

11
cmake/FindSmall.cmake Normal file
View file

@ -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)

View file

@ -297,6 +297,7 @@ target_link_libraries(${TR_NAME}
"$<$<BOOL:${APPLE}>:-framework Foundation>"
PUBLIC
fmt::fmt-header-only
small::small
libevent::event)
if(INSTALL_LIB)

View file

@ -9,13 +9,15 @@
#error only libtransmission should #include this header.
#endif
#include <cstdint> // for size_t
#include <cstddef> // for size_t
#include <cstdint> // for intX_t, uintX_t
#include <ctime>
#include <memory> // for std::unique_ptr
#include <utility> // for std::pair
#include <vector>
#include <small/vector.hpp>
#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<uint8_t, tr_block_info::BlockSize> data_;
size_t const size_;
};
using BlockData = small::max_size_vector<uint8_t, tr_block_info::BlockSize>;
Cache(tr_torrents& torrents, int64_t max_bytes);

View file

@ -19,6 +19,9 @@
#include <process.h> /* _beginthreadex(), _endthreadex() */
#include <windows.h>
#include <shlobj.h> /* SHGetKnownFolderPath(), FOLDERID_... */
#ifdef small // workaround name collision between libsmall and rpcndr.h
#undef small
#endif
#else
#include <pwd.h>
#include <unistd.h> /* getuid() */

View file

@ -17,6 +17,8 @@
#include <fmt/core.h>
#include <small/vector.hpp>
#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<ByKey>& sortbuf)
template<typename Container>
void sort(Container& sortbuf)
{
if (!tr_variantIsDict(&v))
{
@ -763,8 +768,10 @@ public:
private:
size_t size = 0;
std::vector<WalkNode> stack;
std::vector<WalkNode::ByKey> sortbuf;
static auto constexpr InitialCapacity = size_t{ 32U };
small::vector<WalkNode, InitialCapacity> stack;
small::vector<WalkNode::ByKey, InitialCapacity> sortbuf;
};
/**

1
third-party/small vendored Submodule

@ -0,0 +1 @@
Subproject commit 027f6d7eb61c4a5c7eb699acb7c59b8a5e3d085e