mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-10 04:02:30 +00:00
* Optimized view filtering and sorting.
git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1213 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -106,6 +106,8 @@ CommandScheduler::call_item(value_type item) {
|
||||
|
||||
// Unquote the root function object so 'parse_command_execute'
|
||||
// doesn't end up calling it.
|
||||
//
|
||||
// TODO: Only call this if mask_function is set?
|
||||
uint32_t flags = tmp_command.flags() & torrent::Object::mask_function;
|
||||
tmp_command.unset_flags(torrent::Object::mask_function);
|
||||
tmp_command.set_flags((flags >> 1) & torrent::Object::mask_function);
|
||||
|
||||
+20
-18
@@ -67,32 +67,34 @@ parse_string(const char* first, const char* last, std::string* dest, bool (*deli
|
||||
if (first == last)
|
||||
return first;
|
||||
|
||||
bool quoted = parse_is_quote(*first);
|
||||
|
||||
if (quoted)
|
||||
if (parse_is_quote(*first)) {
|
||||
first++;
|
||||
|
||||
while (first != last) {
|
||||
if (quoted) {
|
||||
while (first != last) {
|
||||
if (parse_is_quote(*first))
|
||||
return ++first;
|
||||
|
||||
} else {
|
||||
if (delim(*first))
|
||||
return first;
|
||||
}
|
||||
|
||||
if (parse_is_escape(*first) && ++first == last)
|
||||
throw torrent::input_error("Escape character at end of input.");
|
||||
if (parse_is_escape(*first) && ++first == last)
|
||||
throw torrent::input_error("Escape character at end of input.");
|
||||
|
||||
dest->push_back(*first++);
|
||||
}
|
||||
|
||||
dest->push_back(*first);
|
||||
first++;
|
||||
}
|
||||
|
||||
if (quoted)
|
||||
throw torrent::input_error("Missing closing quote.");
|
||||
|
||||
return first;
|
||||
} else {
|
||||
while (first != last) {
|
||||
if (delim(*first))
|
||||
return first;
|
||||
|
||||
if (parse_is_escape(*first) && ++first == last)
|
||||
throw torrent::input_error("Escape character at end of input.");
|
||||
|
||||
dest->push_back(*first++);
|
||||
}
|
||||
|
||||
return first;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+19
-15
@@ -112,6 +112,21 @@ parse_command_execute(target_type target, torrent::Object* object) {
|
||||
}
|
||||
}
|
||||
|
||||
// Use a static length buffer for dest.
|
||||
inline const char*
|
||||
parse_command_name(const char* first, const char* last, char* dest_first, char* dest_last) {
|
||||
if (first == last || !std::isalpha(*first))
|
||||
throw torrent::input_error("Invalid start of command name.");
|
||||
|
||||
last = first + std::min(std::distance(first, last), std::distance(dest_first, dest_last) - 1);
|
||||
|
||||
while (first != last && (std::isalnum(*first) || *first == '_' || *first == '.'))
|
||||
*dest_first++ = *first++;
|
||||
|
||||
*dest_first = '\0';
|
||||
return first;
|
||||
}
|
||||
|
||||
// Set 'download' to NULL to call the generic functions, thus reusing
|
||||
// the code below for both cases.
|
||||
parse_command_type
|
||||
@@ -121,8 +136,9 @@ parse_command(target_type target, const char* first, const char* last) {
|
||||
if (first == last || *first == '#')
|
||||
return std::make_pair(torrent::Object(), first);
|
||||
|
||||
std::string key;
|
||||
first = parse_command_name(first, last, &key);
|
||||
char key[128];
|
||||
|
||||
first = parse_command_name(first, last, key, key + 128);
|
||||
first = std::find_if(first, last, std::not1(command_map_is_space()));
|
||||
|
||||
if (first == last || *first != '=')
|
||||
@@ -147,7 +163,7 @@ parse_command(target_type target, const char* first, const char* last) {
|
||||
// following command.
|
||||
parse_command_execute(target, &args);
|
||||
|
||||
return std::make_pair(commands.call_command(key.c_str(), args, target), first);
|
||||
return std::make_pair(commands.call_command(key, args, target), first);
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
@@ -223,18 +239,6 @@ parse_command_file(const std::string& path) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Use a static length buffer for dest.
|
||||
const char*
|
||||
parse_command_name(const char* first, const char* last, std::string* dest) {
|
||||
if (first == last || !std::isalpha(*first))
|
||||
throw torrent::input_error("Invalid start of name.");
|
||||
|
||||
for ( ; first != last && (std::isalnum(*first) || *first == '_' || *first == '.'); ++first)
|
||||
dest->push_back(*first);
|
||||
|
||||
return first;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user