Skip to content

Commit 886f40c

Browse files
committed
Small micro-optimizations and rebase
1 parent e10fb67 commit 886f40c

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

lib/src/HostRedirector.cc

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,11 @@ void HostRedirector::initAndStart(const Json::Value &config)
171171
const auto &redirectFromValue = rules[redirectToStr];
172172

173173
auto toIdx = rulesTo_.size();
174-
rulesTo_.push_back({
175-
std::move(redirectToHost.empty() && pathIdx != 0
176-
? redirectToStr
177-
: redirectToHost),
178-
std::move(redirectToPath),
179-
});
174+
rulesTo_.emplace_back(std::move(redirectToHost.empty() &&
175+
pathIdx != 0
176+
? redirectToStr
177+
: redirectToHost),
178+
std::move(redirectToPath));
180179

181180
if (redirectFromValue.isArray())
182181
{
@@ -210,12 +209,10 @@ void HostRedirector::initAndStart(const Json::Value &config)
210209
: redirectFromHost;
211210
if (!fromHost.empty())
212211
doHostLookup_ = true; // We have hosts in lookup rules
213-
rulesFromData_.push_back({
214-
std::move(fromHost),
215-
std::move(redirectFromPath),
216-
isWildcard,
217-
toIdx,
218-
});
212+
rulesFromData_.emplace_back(std::move(fromHost),
213+
std::move(redirectFromPath),
214+
isWildcard,
215+
toIdx);
219216
}
220217
}
221218
// TODO: This commented block can be used to support {from: to}
@@ -239,11 +236,11 @@ void HostRedirector::initAndStart(const Json::Value &config)
239236
for (const auto &redirectFrom : rulesFromData_)
240237
{
241238
const auto &path = redirectFrom.path;
242-
auto &rule = rulesFrom_[redirectFrom.host];
243239
if (path == "/") // Root rules are part of the host group
244240
continue;
245241

246242
auto len = path.size();
243+
auto &rule = rulesFrom_[redirectFrom.host];
247244
if (len < rule.maxPathLen)
248245
rule.maxPathLen = len;
249246
}
@@ -284,7 +281,7 @@ void HostRedirector::initAndStart(const Json::Value &config)
284281
}
285282

286283
auto &leaf = leafs[group];
287-
leaf.fromData.push_back(&redirectFrom);
284+
leaf.fromData.emplace_back(&redirectFrom);
288285
leaf.maxPathLen = maxLen;
289286
}
290287

@@ -331,7 +328,7 @@ void HostRedirector::initAndStart(const Json::Value &config)
331328
}
332329

333330
auto &leaf = leafsBackbuffer[childGroup];
334-
leaf.fromData.push_back(redirectFrom);
331+
leaf.fromData.emplace_back(redirectFrom);
335332
leaf.maxPathLen = maxIdx;
336333
}
337334
}

0 commit comments

Comments
 (0)