optimized memory usage of torrent_info and file_storage

This commit is contained in:
Arvid Norberg
2010-11-24 23:49:22 +00:00
parent 7cd628e78d
commit 894db973e8
22 changed files with 501 additions and 204 deletions

View File

@@ -48,12 +48,12 @@ namespace
ct.add_node(std::make_pair(addr, port));
}
void add_file(file_storage& ct, file_entry const& fe
, std::string const& hash, std::string const& linkpath)
{
ct.add_file(fe, hash.empty() ? 0 : &sha1_hash(hash)
, linkpath.empty() ? 0 : &linkpath);
}
void add_file(file_storage& ct, file_entry const& fe
, std::string const& hash, std::string const& linkpath)
{
ct.add_file(fe, hash.empty() ? 0 : hash.c_str()
, linkpath.empty() ? 0 : &linkpath);
}
}
void bind_create_torrent()
@@ -82,6 +82,12 @@ void bind_create_torrent()
#endif
.def("num_files", &file_storage::num_files)
.def("at", &file_storage::at, return_internal_reference<>())
.def("hash", &file_storage::hash)
.def("symlink", &file_storage::symlink, return_internal_reference<>())
.def("file_index", &file_storage::file_index)
.def("file_base", &file_storage::file_base)
.def("set_file_base", &file_storage::set_file_base)
.def("file_path", &file_storage::file_path)
.def("total_size", &file_storage::total_size)
.def("set_num_pieces", &file_storage::set_num_pieces)
.def("num_pieces", &file_storage::num_pieces)

View File

@@ -102,6 +102,20 @@ namespace
bool get_send_stats(announce_entry const& ae)
{ return ae.send_stats; }
bool get_size(file_entry const& fe)
{ return fe.size; }
bool get_offset(file_entry const& fe)
{ return fe.offset; }
bool get_pad_file(file_entry const& fe)
{ return fe.pad_file; }
bool get_executable_attribute(file_entry const& fe)
{ return fe.executable_attribute; }
bool get_hidden_attribute(file_entry const& fe)
{ return fe.hidden_attribute; }
bool get_symlink_attribute(file_entry const& fe)
{ return fe.symlink_attribute; }
} // namespace unnamed
void bind_torrent_info()
@@ -168,14 +182,14 @@ void bind_torrent_info()
;
class_<file_entry>("file_entry")
.add_property("path"
, make_getter(
&file_entry::path, return_value_policy<copy_non_const_reference>()
)
)
.def_readonly("offset", &file_entry::offset)
.def_readonly("size", &file_entry::size)
.def_readonly("file_base", &file_entry::file_base)
.def("filename", &file_entry::filename)
.def("set_name", &file_entry::set_name)
.add_property("pad_file", &get_pad_file)
.add_property("executable_attribute", &get_executable_attribute)
.add_property("hidden_attribute", &get_hidden_attribute)
.add_property("symlink_attribute", &get_symlink_attribute)
.add_property("offset", &get_offset)
.add_property("size", &get_size)
;
class_<announce_entry>("announce_entry", init<std::string const&>())