Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/FilterEngine.cpp

Issue 29391775: Issue 5013 - Improve some const-correctness (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Patch Set: Feedback + another small patch related. Created March 22, 2017, 4:50 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/FilterEngine.cpp
===================================================================
--- a/src/FilterEngine.cpp
+++ b/src/FilterEngine.cpp
@@ -32,17 +32,17 @@ extern std::string jsSources[];
Filter::Filter(JsValue&& value)
: JsValue(std::move(value))
{
if (!IsObject())
throw std::runtime_error("JavaScript value is not an object");
}
-Filter::Type Filter::GetType()
+Filter::Type Filter::GetType() const
{
std::string className = GetClass();
if (className == "BlockingFilter")
return TYPE_BLOCKING;
else if (className == "WhitelistFilter")
return TYPE_EXCEPTION;
else if (className == "ElemHideFilter")
return TYPE_ELEMHIDE;
@@ -270,21 +270,20 @@ std::string FilterEngine::ContentTypeToS
return it->second;
throw std::invalid_argument("Argument is not a valid ContentType");
}
FilterEngine::ContentType FilterEngine::StringToContentType(const std::string& contentType)
{
std::string contentTypeUpper = contentType;
std::transform(contentType.begin(), contentType.end(), contentTypeUpper.begin(), ::toupper);
- for (ContentTypeMap::const_iterator it = contentTypes.begin();
- it != contentTypes.end(); it++)
+ for (const auto& contentType : contentTypes)
{
- if (it->second == contentTypeUpper)
- return it->first;
+ if (contentType.second == contentTypeUpper)
+ return contentType.first;
}
throw std::invalid_argument("Cannot convert argument to ContentType");
}
bool FilterEngine::IsFirstRun() const
{
return firstRun;
}
@@ -373,19 +372,17 @@ AdblockPlus::FilterPtr FilterEngine::Mat
AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
ContentTypeMask contentTypeMask,
const std::vector<std::string>& documentUrls) const
{
if (documentUrls.empty())
return CheckFilterMatch(url, contentTypeMask, "");
std::string lastDocumentUrl = documentUrls.front();
- for (std::vector<std::string>::const_iterator it = documentUrls.begin();
- it != documentUrls.end(); it++) {
- const std::string documentUrl = *it;
+ for (const auto& documentUrl : documentUrls) {
AdblockPlus::FilterPtr match = CheckFilterMatch(documentUrl,
CONTENT_TYPE_DOCUMENT,
lastDocumentUrl);
if (match && match->GetType() == AdblockPlus::Filter::TYPE_EXCEPTION)
return match;
lastDocumentUrl = documentUrl;
}
@@ -422,18 +419,18 @@ AdblockPlus::FilterPtr FilterEngine::Che
std::vector<std::string> FilterEngine::GetElementHidingSelectors(const std::string& domain) const
{
JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors");
JsValueList params;
params.push_back(jsEngine->NewValue(domain));
JsValueList result = func->Call(params)->AsList();
std::vector<std::string> selectors;
- for (JsValueList::iterator it = result.begin(); it != result.end(); ++it)
- selectors.push_back((*it)->AsString());
+ for (const auto& r: result)
+ selectors.push_back(r->AsString());
return selectors;
}
JsValuePtr FilterEngine::GetPref(const std::string& pref) const
{
JsValuePtr func = jsEngine->Evaluate("API.getPref");
JsValueList params;
params.push_back(jsEngine->NewValue(pref));

Powered by Google App Engine
This is Rietveld