mirror of
https://gitlab.com/niansa/qcommsy.git
synced 2025-03-06 20:53:33 +01:00
Improved libcommsy performance
This commit is contained in:
parent
04e3532f6b
commit
08a6dbc3c8
1 changed files with 16 additions and 16 deletions
|
@ -69,7 +69,7 @@ std::vector<std::string> merge_strvects(std::vector<std::string> base, const std
|
|||
|
||||
extern long curlreq(std::stringstream &responsebuffer, std::string SID, std::string URL);
|
||||
|
||||
void gumbo_search_by_attr(std::vector<GumboNode *> &elemvect, GumboNode* node, std::string attrname, std::string searchword, GumboTag expectedtag) {
|
||||
void gumbo_search_by_attr(std::vector<GumboNode *> *elemvect, GumboNode* node, const std::string& attrname, const std::string& searchword, const GumboTag& expectedtag) {
|
||||
if (node->type != GUMBO_NODE_ELEMENT) {
|
||||
return;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ void gumbo_search_by_attr(std::vector<GumboNode *> &elemvect, GumboNode* node, s
|
|||
if (node->v.element.tag == expectedtag &&
|
||||
(hclass = gumbo_get_attribute(&node->v.element.attributes, attrname.c_str()))) {
|
||||
if (hclass->value == searchword) {
|
||||
elemvect.push_back(node);
|
||||
elemvect->push_back(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,13 +88,13 @@ void gumbo_search_by_attr(std::vector<GumboNode *> &elemvect, GumboNode* node, s
|
|||
}
|
||||
}
|
||||
|
||||
void gumbo_search_by_class(std::vector<GumboNode *> &elemvect, GumboNode* node, std::string searchword, GumboTag expectedtag) {
|
||||
inline void gumbo_search_by_class(std::vector<GumboNode *> *elemvect, GumboNode* node, const std::string& searchword, const GumboTag& expectedtag) {
|
||||
return gumbo_search_by_attr(elemvect, node, "class", searchword, expectedtag);
|
||||
}
|
||||
|
||||
GumboNode *gumbo_search_by_id(GumboNode* node, std::string searchword, GumboTag expectedtag) {
|
||||
GumboNode *gumbo_search_by_id(GumboNode* node, const std::string& searchword, const GumboTag& expectedtag) {
|
||||
std::vector<GumboNode *> elemvect;
|
||||
gumbo_search_by_attr(elemvect, node, "id", searchword, expectedtag);
|
||||
gumbo_search_by_attr(&elemvect, node, "id", searchword, expectedtag);
|
||||
// Use first node found
|
||||
if (elemvect.size() > 0) {
|
||||
return elemvect[0];
|
||||
|
@ -103,13 +103,13 @@ GumboNode *gumbo_search_by_id(GumboNode* node, std::string searchword, GumboTag
|
|||
throw parsingNoSuchIDError();
|
||||
}
|
||||
|
||||
void gumbo_search_by_tag(std::vector<GumboNode *> &elemvect, GumboNode* node, GumboTag searchedtag) {
|
||||
void gumbo_search_by_tag(std::vector<GumboNode *> *elemvect, GumboNode* node, const GumboTag& searchedtag) {
|
||||
if (node->type != GUMBO_NODE_ELEMENT) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (node->v.element.tag == searchedtag) {
|
||||
elemvect.push_back(node);
|
||||
elemvect->push_back(node);
|
||||
}
|
||||
|
||||
GumboVector* children = &node->v.element.children;
|
||||
|
@ -144,7 +144,7 @@ static std::string gumbo_cleantext(GumboNode* node) {
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> gumbo_get_attr(GumboNode *node, std::string attrkey, GumboTag expected_tag) {
|
||||
std::vector<std::string> gumbo_get_attr(GumboNode *node, const std::string& attrkey, const GumboTag& expected_tag) {
|
||||
std::vector<std::string> attrvals;
|
||||
GumboNode *childnode;
|
||||
GumboVector* children = &node->v.element.children;
|
||||
|
@ -176,7 +176,7 @@ std::vector<std::string> gumbo_get_attr(GumboNode *node, std::string attrkey, Gu
|
|||
return attrvals;
|
||||
}
|
||||
|
||||
std::string gumbo_find_text_by_tag(GumboNode *node, GumboTag searchtag) {
|
||||
std::string gumbo_find_text_by_tag(GumboNode *node, const GumboTag& searchtag) {
|
||||
GumboNode *childnode;
|
||||
GumboVector* children = &node->v.element.children;
|
||||
|
||||
|
@ -194,13 +194,13 @@ std::string gumbo_find_text_by_tag(GumboNode *node, GumboTag searchtag) {
|
|||
|
||||
auto get_posts(GumboNode *node) {
|
||||
std::vector<GumboNode *> posts;
|
||||
gumbo_search_by_class(posts, node, "uk-comment", GUMBO_TAG_ARTICLE);
|
||||
gumbo_search_by_class(&posts, node, "uk-comment", GUMBO_TAG_ARTICLE);
|
||||
return posts;
|
||||
}
|
||||
|
||||
std::string get_post_name(GumboNode *node) {
|
||||
std::vector<GumboNode *> titlenodes;
|
||||
gumbo_search_by_class(titlenodes, node, "uk-comment-title", GUMBO_TAG_H4);
|
||||
gumbo_search_by_class(&titlenodes, node, "uk-comment-title", GUMBO_TAG_H4);
|
||||
return trim(gumbo_cleantext(titlenodes[0]));
|
||||
}
|
||||
|
||||
|
@ -210,19 +210,19 @@ std::string get_post_id(GumboNode *node) {
|
|||
|
||||
std::string get_post_meta(GumboNode *node) {
|
||||
std::vector<GumboNode *> metanodes;
|
||||
gumbo_search_by_class(metanodes, node, "uk-comment-meta", GUMBO_TAG_DIV);
|
||||
gumbo_search_by_class(&metanodes, node, "uk-comment-meta", GUMBO_TAG_DIV);
|
||||
return clean_spaces(trim(gumbo_cleantext(metanodes[1])));
|
||||
}
|
||||
|
||||
std::string get_post_url(GumboNode *node) {
|
||||
std::vector<GumboNode *> titlenodes;
|
||||
gumbo_search_by_class(titlenodes, node, "uk-comment-title", GUMBO_TAG_H4);
|
||||
gumbo_search_by_class(&titlenodes, node, "uk-comment-title", GUMBO_TAG_H4);
|
||||
return gumbo_get_attr(titlenodes[0], "href", GUMBO_TAG_A)[0];
|
||||
}
|
||||
|
||||
bool get_post_unread(GumboNode *node) {
|
||||
std::vector<GumboNode *> elems;
|
||||
gumbo_search_by_class(elems, node, "cs-comment-change-info", GUMBO_TAG_DIV);
|
||||
gumbo_search_by_class(&elems, node, "cs-comment-change-info", GUMBO_TAG_DIV);
|
||||
return !elems.empty();
|
||||
}
|
||||
|
||||
|
@ -253,7 +253,7 @@ std::vector<std::map<std::string, std::string>> get_post_files(GumboNode *node)
|
|||
std::map<std::string, std::string> tmpmap;
|
||||
|
||||
// Get meta nodes
|
||||
gumbo_search_by_class(metanodes, node, "uk-comment-meta", GUMBO_TAG_DIV);
|
||||
gumbo_search_by_class(&metanodes, node, "uk-comment-meta", GUMBO_TAG_DIV);
|
||||
// Get URLs
|
||||
fileurls = gumbo_get_attr(metanodes[2], "href", GUMBO_TAG_A);
|
||||
// Get filenames
|
||||
|
@ -301,7 +301,7 @@ std::string get_post_desc(const std::string& post_url, const std::string& server
|
|||
// Get description element
|
||||
desc_node = gumbo_search_by_id(post_document->root, "description" + material_id, GUMBO_TAG_DIV);
|
||||
// Extract description
|
||||
gumbo_search_by_tag(results, desc_node, GUMBO_TAG_P);
|
||||
gumbo_search_by_tag(&results, desc_node, GUMBO_TAG_P);
|
||||
|
||||
// Cencenate occurencies
|
||||
std::string result_string;
|
||||
|
|
Loading…
Add table
Reference in a new issue