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

Delta Between Two Patch Sets: compiled/ElemHideEmulation.h

Issue 29594607: Issue 5143 - Convert ElemHideEmulation to C++ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created Nov. 1, 2017, 2:42 p.m.
Right Patch Set: Review comments addressed Created Jan. 30, 2018, 5:37 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « compiled/ElemHide.h ('k') | compiled/ElemHideEmulation.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #pragma once 18 #pragma once
19 19
20 #include <vector> 20 #include <vector>
21 21
22 #include "bindings/runtime.h" 22 #include "bindings/runtime.h"
23 #include "intrusive_ptr.h" 23 #include "intrusive_ptr.h"
24 #include "filter/ElemHideBase.h" 24 #include "filter/ElemHideBase.h"
25 25
26 class _ElemHideEmulation_FilterList : public ref_counted 26 class ElemHide;
sergei 2017/11/16 09:58:07 IMO it's not a good idea to have names starting wi
hub 2017/11/20 19:16:01 That was part of the "spec" but indeed it conflict
27
28 class ElemHideEmulation_FilterList : public ref_counted
27 { 29 {
28 std::vector<ElemHideBasePtr> mFilters; 30 std::vector<ElemHideBasePtr> mFilters;
29 public: 31 public:
30 size_t BINDINGS_EXPORTED GetFilterCount() const 32 size_t BINDINGS_EXPORTED GetFilterCount() const
31 { 33 {
32 return mFilters.size(); 34 return mFilters.size();
33 } 35 }
34 ElemHideBase* BINDINGS_EXPORTED FilterAt(size_t idx) 36
37 ElemHideBase* BINDINGS_EXPORTED FilterAt(size_t index)
35 { 38 {
36 return mFilters[idx].get(); 39 if (index >= mFilters.size())
40 return nullptr;
41
42 ElemHideBasePtr result(mFilters[index]);
43 return result.release();
37 } 44 }
38 45
39 void push_back(ElemHideBasePtr filter) 46 void push_back(const ElemHideBasePtr& filter)
sergei 2017/11/16 09:58:07 What about using r-value or l-value reference here
hub 2017/11/20 19:16:01 r-value is impossible: we don't want to move the v
sergei 2018/01/25 16:04:00 Acknowledged. Perhaps we should revisit such metho
hub 2018/01/25 19:05:26 Looking at the use case, move doesn't make sense h
40 { 47 {
41 mFilters.push_back(filter); 48 mFilters.push_back(filter);
42 } 49 }
43 50
44 }; 51 };
45 52
46 class ElemHideEmulation : public ref_counted 53 class ElemHideEmulation : public ref_counted
47 { 54 {
48 StringMap<ElemHideBasePtr> mFilters; 55 StringMap<ElemHideBasePtr> mFilters;
49 56
50 static ElemHideEmulation* mInstance;
51
52 public: 57 public:
53 static ElemHideEmulation* BINDINGS_EXPORTED GetInstance() 58 static ElemHideEmulation* BINDINGS_EXPORTED Create()
sergei 2017/11/16 09:58:07 IMO the growth of usage of the singleton pattern i
hub 2017/11/20 19:16:00 yes.
54 { 59 {
55 return mInstance; 60 return new ElemHideEmulation();
56 } 61 }
57 62
58 void BINDINGS_EXPORTED Add(ElemHideBase&); 63 void BINDINGS_EXPORTED Add(ElemHideBase&);
59 void BINDINGS_EXPORTED Remove(ElemHideBase&); 64 void BINDINGS_EXPORTED Remove(ElemHideBase&);
60 void BINDINGS_EXPORTED Clear(); 65 void BINDINGS_EXPORTED Clear();
61 _ElemHideEmulation_FilterList* BINDINGS_EXPORTED GetRulesForDomain(DependentSt ring&); 66 ElemHideEmulation_FilterList* BINDINGS_EXPORTED GetRulesForDomain(const ElemHi de&, DependentString&);
62 }; 67 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld