Skip to content

Commit 341aee3

Browse files
theanalystesindril
authored andcommitted
MGM: Quota: avoid needless cstring alloc/conversions
In `GetResponsibleSpaceQuota` we convert to XrdOucString mainly for the beginswith comparision. Use the common utilities to compare std::strings and avoid conversions between c-strings to cpp strings Currently GetSpaceName() would be unused after this refactor, but we'll drop that in a future release Signed-off-by: Abhishek Lekshmanan <abhishek.lekshmanan@cern.ch>
1 parent f5f49f4 commit 341aee3

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

mgm/Quota.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "mgm/Quota.hh"
2525
#include "mgm/Policy.hh"
2626
#include "mgm/XrdMgmOfs.hh"
27+
#include "common/StringUtils.hh"
2728
#include "common/table_formatter/TableFormatterBase.hh"
2829
#include "namespace/interface/IView.hh"
2930
#include "namespace/ns_quarkdb/NamespaceGroup.hh"
@@ -1388,17 +1389,16 @@ Quota::GetSpaceQuota(const std::string& qpath)
13881389
SpaceQuota*
13891390
Quota::GetResponsibleSpaceQuota(const std::string& path)
13901391
{
1391-
XrdOucString matchpath = path.c_str();
13921392
SpaceQuota* squota = nullptr;
13931393

13941394
for (auto it = pMapQuota.begin(); it != pMapQuota.end(); ++it) {
1395-
if (matchpath.beginswith(it->second->GetSpaceName())) {
1395+
if (common::startsWith(path, it->second->GetSpaceName())) {
13961396
if (squota == nullptr) {
13971397
squota = it->second;
13981398
}
13991399

14001400
// Save if it's a better match
1401-
if (strlen(it->second->GetSpaceName()) > strlen(squota->GetSpaceName())) {
1401+
if (it->second->GetSpaceNameStr().size() > squota->GetSpaceNameStr().size()) {
14021402
squota = it->second;
14031403
}
14041404
}
@@ -1417,7 +1417,7 @@ Quota::GetResponsibleSpaceQuotaPath(const std::string& path)
14171417
SpaceQuota* squota = GetResponsibleSpaceQuota(path);
14181418

14191419
if (squota) {
1420-
return squota->GetSpaceName();
1420+
return squota->GetSpaceNameStr();
14211421
} else {
14221422
return "";
14231423
}
@@ -2027,7 +2027,7 @@ Quota::UpdateFromNsQuota(const std::string& path, uid_t uid, gid_t gid)
20272027
SpaceQuota* squota = GetResponsibleSpaceQuota(path);
20282028

20292029
// No quota or this is not the space quota itself - do nothing
2030-
if (!squota || (strcmp(squota->GetSpaceName(), path.c_str()))) {
2030+
if (!squota || squota->GetSpaceNameStr().compare(path)) {
20312031
return false;
20322032
}
20332033

mgm/Quota.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public:
6767
return pPath.c_str();
6868
}
6969

70+
inline const std::string& GetSpaceNameStr() const
71+
{
72+
return pPath;
73+
}
7074
//----------------------------------------------------------------------------
7175
//! Get namespace quota node
7276
//----------------------------------------------------------------------------

0 commit comments

Comments
 (0)