forked from premiere/premiere-libtorrent
use string_view in find_metric_idx
This commit is contained in:
parent
9c7f87ed5d
commit
53ff169db1
|
@ -561,6 +561,11 @@ namespace
|
|||
return p;
|
||||
}
|
||||
|
||||
int find_metric_idx_wrap(char const* name)
|
||||
{
|
||||
return lt::find_metric_idx(name);
|
||||
}
|
||||
|
||||
} // namespace unnamed
|
||||
|
||||
struct dummy1 {};
|
||||
|
@ -994,7 +999,7 @@ void bind_session()
|
|||
;
|
||||
|
||||
def("session_stats_metrics", session_stats_metrics);
|
||||
def("find_metric_idx", find_metric_idx);
|
||||
def("find_metric_idx", find_metric_idx_wrap);
|
||||
|
||||
scope().attr("create_ut_metadata_plugin") = "ut_metadata";
|
||||
scope().attr("create_ut_pex_plugin") = "ut_pex";
|
||||
|
|
|
@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#define TORRENT_SESSION_STATS_HPP_INCLUDED
|
||||
|
||||
#include "libtorrent/config.hpp"
|
||||
#include "libtorrent/string_view.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -59,8 +60,7 @@ namespace libtorrent {
|
|||
// given a name of a metric, this function returns the counter index of it,
|
||||
// or -1 if it could not be found. The counter index is the index into the
|
||||
// values array returned by session_stats_alert.
|
||||
TORRENT_EXPORT int find_metric_idx(char const* name);
|
||||
|
||||
TORRENT_EXPORT int find_metric_idx(string_view name);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -571,15 +571,13 @@ namespace {
|
|||
return stats;
|
||||
}
|
||||
|
||||
// TODO: 3 use string_view for name
|
||||
int find_metric_idx(char const* name)
|
||||
int find_metric_idx(string_view name)
|
||||
{
|
||||
auto const i = std::find_if(std::begin(metrics), std::end(metrics)
|
||||
, [name](stats_metric_impl const& metr)
|
||||
{ return std::strcmp(metr.name, name) == 0; });
|
||||
{ return metr.name == name; });
|
||||
|
||||
if (i == std::end(metrics)) return -1;
|
||||
return i->value_index;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/bdecode.hpp"
|
||||
#include "libtorrent/bencode.hpp"
|
||||
#include "libtorrent/torrent_info.hpp"
|
||||
#include "libtorrent/session_stats.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#include <fstream>
|
||||
|
@ -218,6 +219,9 @@ TORRENT_TEST(session_stats)
|
|||
{
|
||||
TEST_EQUAL(stats[i].value_index, i);
|
||||
}
|
||||
|
||||
TEST_EQUAL(lt::find_metric_idx("peer.incoming_connections")
|
||||
, lt::counters::incoming_connections);
|
||||
}
|
||||
|
||||
TORRENT_TEST(paused_session)
|
||||
|
|
Loading…
Reference in New Issue