Skip to content

Commit 3c217d8

Browse files
fxdupontandrei-pavel
authored andcommitted
[#3262] Optimized getSubnet() (#3268 1st point)
1 parent 8491e56 commit 3c217d8

File tree

4 files changed

+16
-40
lines changed

4 files changed

+16
-40
lines changed

src/lib/dhcpsrv/cfg_subnets4.cc

+4-16
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,6 @@ CfgSubnets4::merge(CfgOptionDefPtr cfg_def, CfgSharedNetworks4Ptr networks,
183183
}
184184
}
185185

186-
ConstSubnet4Ptr
187-
CfgSubnets4::getBySubnetId(const SubnetID& subnet_id) const {
188-
auto const& index = subnets_.get<SubnetSubnetIdIndexTag>();
189-
auto subnet_it = index.find(subnet_id);
190-
return ((subnet_it != index.cend()) ? (*subnet_it) : ConstSubnet4Ptr());
191-
}
192-
193186
ConstSubnet4Ptr
194187
CfgSubnets4::getByPrefix(const std::string& subnet_text) const {
195188
auto const& index = subnets_.get<SubnetPrefixIndexTag>();
@@ -459,15 +452,10 @@ CfgSubnets4::selectSubnet(const std::string& iface,
459452
}
460453

461454
Subnet4Ptr
462-
CfgSubnets4::getSubnet(const SubnetID id) const {
463-
/// @todo: Once this code is migrated to multi-index container, use
464-
/// an index rather than full scan.
465-
for (auto const& subnet : subnets_) {
466-
if (subnet->getID() == id) {
467-
return (subnet);
468-
}
469-
}
470-
return (Subnet4Ptr());
455+
CfgSubnets4::getSubnet(const SubnetID subnet_id) const {
456+
auto const& index = subnets_.get<SubnetSubnetIdIndexTag>();
457+
auto subnet_it = index.find(subnet_id);
458+
return ((subnet_it != index.cend()) ? (*subnet_it) : Subnet4Ptr());
471459
}
472460

473461
Subnet4Ptr

src/lib/dhcpsrv/cfg_subnets4.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ class CfgSubnets4 : public isc::data::CfgToElement {
135135
///
136136
/// @return Pointer to the @c Subnet4 object or null pointer if such
137137
/// subnet doesn't exist.
138-
ConstSubnet4Ptr getBySubnetId(const SubnetID& subnet_id) const;
138+
ConstSubnet4Ptr getBySubnetId(const SubnetID& subnet_id) const {
139+
return (getSubnet(subnet_id));
140+
}
139141

140142
/// @brief Returns const pointer to a subnet which matches the specified
141143
/// prefix in the canonical form.
@@ -221,11 +223,9 @@ class CfgSubnets4 : public isc::data::CfgToElement {
221223

222224
/// @brief Returns subnet with specified subnet-id value
223225
///
224-
/// Warning: this method uses full scan. Its use is not recommended for
225-
/// packet processing.
226226
/// Please use @ref getBySubnetId instead when possible.
227227
///
228-
/// @return Subnet (or NULL)
228+
/// @return Subnet (or null)
229229
Subnet4Ptr getSubnet(const SubnetID id) const;
230230

231231
/// @brief Returns a pointer to a subnet if provided address is in its range.

src/lib/dhcpsrv/cfg_subnets6.cc

+4-16
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,6 @@ CfgSubnets6::merge(CfgOptionDefPtr cfg_def, CfgSharedNetworks6Ptr networks,
185185
}
186186
}
187187

188-
ConstSubnet6Ptr
189-
CfgSubnets6::getBySubnetId(const SubnetID& subnet_id) const {
190-
auto const& index = subnets_.get<SubnetSubnetIdIndexTag>();
191-
auto subnet_it = index.find(subnet_id);
192-
return ((subnet_it != index.cend()) ? (*subnet_it) : ConstSubnet6Ptr());
193-
}
194-
195188
ConstSubnet6Ptr
196189
CfgSubnets6::getByPrefix(const std::string& subnet_text) const {
197190
auto const& index = subnets_.get<SubnetPrefixIndexTag>();
@@ -375,15 +368,10 @@ CfgSubnets6::selectSubnet(const OptionPtr& interface_id,
375368
}
376369

377370
Subnet6Ptr
378-
CfgSubnets6::getSubnet(const SubnetID id) const {
379-
/// @todo: Once this code is migrated to multi-index container, use
380-
/// an index rather than full scan.
381-
for (auto const& subnet : subnets_) {
382-
if (subnet->getID() == id) {
383-
return (subnet);
384-
}
385-
}
386-
return (Subnet6Ptr());
371+
CfgSubnets6::getSubnet(const SubnetID subnet_id) const {
372+
auto const& index = subnets_.get<SubnetSubnetIdIndexTag>();
373+
auto subnet_it = index.find(subnet_id);
374+
return ((subnet_it != index.cend()) ? (*subnet_it) : Subnet6Ptr());
387375
}
388376

389377
SubnetIDSet

src/lib/dhcpsrv/cfg_subnets6.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ class CfgSubnets6 : public isc::data::CfgToElement {
136136
///
137137
/// @return Pointer to the @c Subnet6 object or null pointer if such
138138
/// subnet doesn't exist.
139-
ConstSubnet6Ptr getBySubnetId(const SubnetID& subnet_id) const;
139+
ConstSubnet6Ptr getBySubnetId(const SubnetID& subnet_id) const {
140+
return (getSubnet(subnet_id));
141+
}
140142

141143
/// @brief Returns const pointer to a subnet which matches the specified
142144
/// prefix in the canonical form.
@@ -203,11 +205,9 @@ class CfgSubnets6 : public isc::data::CfgToElement {
203205

204206
/// @brief Returns subnet with specified subnet-id value
205207
///
206-
/// Warning: this method uses full scan. Its use is not recommended for
207-
/// packet processing.
208208
/// Please use @ref getBySubnetId instead when possible.
209209
///
210-
/// @return Subnet (or NULL)
210+
/// @return Subnet (or null)
211211
Subnet6Ptr getSubnet(const SubnetID id) const;
212212

213213
/// @brief Selects the subnet using a specified address.

0 commit comments

Comments
 (0)