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

Side by Side Diff: compiled/storage/FilterStorage.cpp

Issue 29532626: Issue 5603 - Support references in parameters of exported functions (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created Aug. 31, 2017, 12:36 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 20 matching lines...) Expand all
31 31
32 Subscription* FilterStorage::SubscriptionAt(FilterStorage::Subscriptions::size_t ype index) const 32 Subscription* FilterStorage::SubscriptionAt(FilterStorage::Subscriptions::size_t ype index) const
33 { 33 {
34 if (index >= mSubscriptions.size()) 34 if (index >= mSubscriptions.size())
35 return nullptr; 35 return nullptr;
36 36
37 SubscriptionPtr result(mSubscriptions[index]); 37 SubscriptionPtr result(mSubscriptions[index]);
38 return result.release(); 38 return result.release();
39 } 39 }
40 40
41 int FilterStorage::IndexOfSubscription(const Subscription* subscription) const 41 int FilterStorage::IndexOfSubscription(const Subscription& subscription) const
42 { 42 {
43 for (Subscriptions::size_type i = 0; i < mSubscriptions.size(); i++) 43 for (Subscriptions::size_type i = 0; i < mSubscriptions.size(); i++)
44 if (mSubscriptions[i] == subscription) 44 if (mSubscriptions[i] == &subscription)
45 return i; 45 return i;
46 return -1; 46 return -1;
47 } 47 }
48 48
49 Subscription* FilterStorage::GetSubscriptionForFilter(const Filter* filter) cons t 49 Subscription* FilterStorage::GetSubscriptionForFilter(const Filter& filter) cons t
50 { 50 {
51 SubscriptionPtr fallback; 51 SubscriptionPtr fallback;
52 52
53 for (Subscriptions::size_type i = 0; i < mSubscriptions.size(); i++) 53 for (Subscriptions::size_type i = 0; i < mSubscriptions.size(); i++)
54 { 54 {
55 SubscriptionPtr subscription(mSubscriptions[i]); 55 SubscriptionPtr subscription(mSubscriptions[i]);
56 UserDefinedSubscription* userDefinedSubscription = 56 UserDefinedSubscription* userDefinedSubscription =
57 subscription->As<UserDefinedSubscription>(); 57 subscription->As<UserDefinedSubscription>();
58 if (userDefinedSubscription && !userDefinedSubscription->GetDisabled() && 58 if (userDefinedSubscription && !userDefinedSubscription->GetDisabled() &&
59 userDefinedSubscription->IsDefaultFor(filter)) 59 userDefinedSubscription->IsDefaultFor(filter))
60 { 60 {
61 SubscriptionPtr result(subscription); 61 SubscriptionPtr result(subscription);
62 return result.release(); 62 return result.release();
63 } 63 }
64 else if (!fallback && userDefinedSubscription && 64 else if (!fallback && userDefinedSubscription &&
65 userDefinedSubscription->IsGeneric()) 65 userDefinedSubscription->IsGeneric())
66 { 66 {
67 fallback = subscription; 67 fallback = subscription;
68 } 68 }
69 } 69 }
70 70
71 return fallback.release(); 71 return fallback.release();
72 } 72 }
73 73
74 bool FilterStorage::AddSubscription(Subscription* subscription) 74 bool FilterStorage::AddSubscription(Subscription& subscription)
75 { 75 {
76 assert(subscription, u"Attempt to add a null subscription"_str); 76 if (subscription.GetListed())
77
78 if (!subscription || subscription->GetListed())
79 return false; 77 return false;
80 78
81 mSubscriptions.emplace_back(subscription); 79 mSubscriptions.emplace_back(&subscription);
82 subscription->SetListed(true); 80 subscription.SetListed(true);
83 81
84 FilterNotifier::SubscriptionChange( 82 FilterNotifier::SubscriptionChange(
85 FilterNotifier::Topic::SUBSCRIPTION_ADDED, 83 FilterNotifier::Topic::SUBSCRIPTION_ADDED,
86 subscription 84 subscription
87 ); 85 );
88 return true; 86 return true;
89 } 87 }
90 88
91 bool FilterStorage::RemoveSubscription(Subscription* subscription) 89 bool FilterStorage::RemoveSubscription(Subscription& subscription)
92 { 90 {
93 assert(subscription, u"Attempt to remove a null subscription"_str); 91 if (!subscription.GetListed())
94
95 if (!subscription || !subscription->GetListed())
96 return false; 92 return false;
97 93
98 for (auto it = mSubscriptions.begin(); it != mSubscriptions.end(); ++it) 94 for (auto it = mSubscriptions.begin(); it != mSubscriptions.end(); ++it)
99 { 95 {
100 if (*it == subscription) 96 if (*it == &subscription)
101 { 97 {
102 mSubscriptions.erase(it); 98 mSubscriptions.erase(it);
103 break; 99 break;
104 } 100 }
105 } 101 }
106 subscription->SetListed(false); 102 subscription.SetListed(false);
107 103
108 FilterNotifier::SubscriptionChange( 104 FilterNotifier::SubscriptionChange(
109 FilterNotifier::Topic::SUBSCRIPTION_REMOVED, 105 FilterNotifier::Topic::SUBSCRIPTION_REMOVED,
110 subscription 106 subscription
111 ); 107 );
112 return true; 108 return true;
113 } 109 }
114 110
115 bool FilterStorage::MoveSubscription(Subscription* subscription, 111 bool FilterStorage::MoveSubscription(Subscription& subscription,
116 const Subscription* insertBefore) 112 const Subscription* insertBefore)
117 { 113 {
118 assert(subscription, u"Attempt to move a null subscription"_str);
119
120 int oldPos = IndexOfSubscription(subscription); 114 int oldPos = IndexOfSubscription(subscription);
115 assert(oldPos >= 0, u"Attempt to move a subscription that is not in the list"_ str);
121 if (oldPos == -1) 116 if (oldPos == -1)
122 {
123 assert(subscription, u"Attempt to move a subscription that is not in the lis t"_str);
124 return false; 117 return false;
125 }
126 118
127 int newPos = -1; 119 int newPos = -1;
128 if (insertBefore) 120 if (insertBefore)
129 newPos = IndexOfSubscription(insertBefore); 121 newPos = IndexOfSubscription(*insertBefore);
130 if (newPos == -1) 122 if (newPos == -1)
131 newPos = mSubscriptions.size(); 123 newPos = mSubscriptions.size();
132 124
133 if (newPos > oldPos) 125 if (newPos > oldPos)
134 newPos--; 126 newPos--;
135 127
136 if (newPos == oldPos) 128 if (newPos == oldPos)
137 return false; 129 return false;
138 130
139 mSubscriptions.erase(mSubscriptions.begin() + oldPos); 131 mSubscriptions.erase(mSubscriptions.begin() + oldPos);
140 mSubscriptions.emplace(mSubscriptions.begin() + newPos, subscription); 132 mSubscriptions.emplace(mSubscriptions.begin() + newPos, &subscription);
141 133
142 FilterNotifier::SubscriptionChange( 134 FilterNotifier::SubscriptionChange(
143 FilterNotifier::Topic::SUBSCRIPTION_MOVED, 135 FilterNotifier::Topic::SUBSCRIPTION_MOVED,
144 subscription 136 subscription
145 ); 137 );
146 return true; 138 return true;
147 } 139 }
OLDNEW

Powered by Google App Engine
This is Rietveld