From 359c8c3a44479144c255372480f4df6911cf2d7c Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Mon, 20 Jan 2025 17:50:47 +0800 Subject: [PATCH] opt:remove custom smallset and use qset instead (#2089) * opt:remove smallset and use qset instead --- src/dict/mediawiki.cc | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/dict/mediawiki.cc b/src/dict/mediawiki.cc index c0865d942..33bfbdb72 100644 --- a/src/dict/mediawiki.cc +++ b/src/dict/mediawiki.cc @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include "audiolink.hh" @@ -408,28 +409,9 @@ class MediaWikiArticleRequest: public MediaWikiDataRequestSlots void requestFinished( QNetworkReply * ) override; - /// This simple set implementation should be much more efficient than tree- - /// and hash-based standard/Qt containers when there are very few elements. - template< typename T > - class SmallSet - { - public: - bool insert( T x ) - { - if ( std::find( elements.begin(), elements.end(), x ) != elements.end() ) { - return false; - } - elements.push_back( x ); - return true; - } - - private: - std::vector< T > elements; - }; - /// The page id set allows to filter out duplicate articles in case MediaWiki /// redirects the main word and words in the alts collection to the same page. - SmallSet< long long > addedPageIds; + QSet< long long > addedPageIds; Class * dictPtr; }; @@ -528,10 +510,14 @@ void MediaWikiArticleRequest::requestFinished( QNetworkReply * r ) else { QDomNode parseNode = dd.namedItem( "api" ).namedItem( "parse" ); - if ( !parseNode.isNull() - && parseNode.toElement().attribute( "revid" ) != "0" - // Don't show the same article more than once: - && addedPageIds.insert( parseNode.toElement().attribute( "pageid" ).toLongLong() ) ) { + long long pageId = 0; + if ( !parseNode.isNull() && parseNode.toElement().attribute( "revid" ) != "0" ) { + pageId = parseNode.toElement().attribute( "pageid" ).toLongLong(); + } + + if ( pageId != 0 && !addedPageIds.contains( pageId ) ) { + addedPageIds.insert( pageId ); + QDomNode textNode = parseNode.namedItem( "text" ); if ( !textNode.isNull() ) {