* Converted VariableMap and ViewManager to using const char* as the

key, since they are never changed nor added from outside. This cut the
stripped binary size by 50KB.

* Use a shared have piece queue for each download. Each connection has
a time-stamp for the last have message they sent, which is checked
against the queue. This also avoids the race condition where some
peers would get incomplete views of our bitfield due to lost have
messages during handshake.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@839 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2007-01-01 14:57:10 +00:00
parent fe7adfc999
commit de744ad11d
8 changed files with 72 additions and 52 deletions
+7 -3
View File
@@ -82,9 +82,13 @@ public:
bool is_hash_failed() const { return m_hashFailed; }
void set_hash_failed(bool v) { m_hashFailed = v; }
variable_map_type* variable() { return &m_variables; }
int64_t variable_value(const std::string& key) const { return m_variables.get_value(key); }
const std::string& variable_string(const std::string& key) const { return m_variables.get_string(key); }
variable_map_type* variable() { return &m_variables; }
int64_t variable_value(const std::string& key) const { return m_variables.get_value(key.c_str()); }
const std::string& variable_string(const std::string& key) const { return m_variables.get_string(key.c_str()); }
int64_t variable_value_c(const char* key) const { return m_variables.get_value(key); }
const std::string& variable_string_c(const char* key) const { return m_variables.get_string(key); }
download_type* download() { return &m_download; }
const download_type* c_download() const { return &m_download; }
+9 -11
View File
@@ -66,8 +66,7 @@ public:
class ViewSortVariable : public ViewSort {
public:
ViewSortVariable(const std::string& name, const std::string& value) :
m_name(name), m_value(value) {}
ViewSortVariable(const char* name, const char* value) : m_name(name), m_value(value) {}
virtual bool operator () (Download* d1, Download* d2) const {
return
@@ -76,14 +75,13 @@ public:
}
private:
std::string m_name;
std::string m_value;
const char* m_name;
const char* m_value;
};
class ViewSortVariableValue : public ViewSort {
public:
ViewSortVariableValue(const std::string& name, bool reverse = false) :
m_name(name), m_reverse(reverse) {}
ViewSortVariableValue(const char* name, bool reverse = false) : m_name(name), m_reverse(reverse) {}
virtual bool operator () (Download* d1, Download* d2) const {
if (m_reverse)
@@ -93,7 +91,7 @@ public:
}
private:
std::string m_name;
const char* m_name;
bool m_reverse;
};
@@ -112,7 +110,7 @@ private:
class ViewFilterVariableValue : public ViewFilter {
public:
ViewFilterVariableValue(const std::string& name, torrent::Object::value_type v, bool inverse = false) :
ViewFilterVariableValue(const char* name, torrent::Object::value_type v, bool inverse = false) :
m_name(name), m_value(v), m_inverse(inverse) {}
virtual bool operator () (Download* d1) const {
@@ -120,7 +118,7 @@ public:
}
private:
std::string m_name;
const char* m_name;
torrent::Object::value_type m_value;
bool m_inverse;
};
@@ -191,7 +189,7 @@ ViewManager::build_sort_list(const sort_args& args) {
sortList.reserve(args.size());
for (sort_args::const_iterator itr = args.begin(), last = args.end(); itr != last; ++itr) {
sort_map::const_iterator sortItr = m_sort.find(*itr);
sort_map::const_iterator sortItr = m_sort.find(itr->c_str());
if (sortItr == m_sort.end())
throw torrent::input_error("Invalid sorting identifier.");
@@ -235,7 +233,7 @@ ViewManager::build_filter_list(const filter_args& args) {
filterList.reserve(args.size());
for (filter_args::const_iterator itr = args.begin(), last = args.end(); itr != last; ++itr) {
filter_map::const_iterator filterItr = m_filter.find(*itr);
filter_map::const_iterator filterItr = m_filter.find(itr->c_str());
if (filterItr == m_filter.end())
throw torrent::input_error("Invalid filtering identifier.");
+7 -2
View File
@@ -38,6 +38,7 @@
#define RTORRENT_CORE_VIEW_MANAGER_H
#include <map>
#include <cstring>
#include <string>
#include <rak/unordered_vector.h>
@@ -45,17 +46,21 @@
namespace core {
struct view_manager_comp : public std::binary_function<const char*, const char*, bool> {
bool operator () (const char* arg1, const char* arg2) const { return std::strcmp(arg1, arg2) < 0; }
};
class ViewSort;
class ViewManager : public rak::unordered_vector<View*> {
public:
typedef rak::unordered_vector<View*> base_type;
typedef std::map<std::string, ViewSort*> sort_map;
typedef std::map<const char*, ViewSort*, view_manager_comp> sort_map;
typedef View::sort_list sort_list;
typedef std::list<std::string> sort_args;
typedef std::map<std::string, ViewFilter*> filter_map;
typedef std::map<const char*, ViewFilter*, view_manager_comp> filter_map;
typedef View::filter_list filter_list;
typedef std::list<std::string> filter_args;