diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2023-07-20 22:11:42 +0300 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2023-07-20 22:11:42 +0300 |
commit | d63f0523399ab2d93c1c6ca6c2dca082be5e52ba (patch) | |
tree | 1123a7aa3ac1d42f3ceaae288e639931d9dca92a /library/cpp/monlib/service/pages/index_mon_page.cpp | |
parent | 068d4453cf9fc68c875eee73f5c637bb076f6a71 (diff) | |
download | ydb-d63f0523399ab2d93c1c6ca6c2dca082be5e52ba.tar.gz |
Ydb stable 23-2-1123.2.11
x-stable-origin-commit: 758ace972646c843c5e0785d75c8f4fe044580a1
Diffstat (limited to 'library/cpp/monlib/service/pages/index_mon_page.cpp')
-rw-r--r-- | library/cpp/monlib/service/pages/index_mon_page.cpp | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/library/cpp/monlib/service/pages/index_mon_page.cpp b/library/cpp/monlib/service/pages/index_mon_page.cpp index 2bfa0faca8..c9b2f82cc0 100644 --- a/library/cpp/monlib/service/pages/index_mon_page.cpp +++ b/library/cpp/monlib/service/pages/index_mon_page.cpp @@ -28,9 +28,8 @@ void TIndexMonPage::Output(IMonHttpRequest& request) { TGuard<TMutex> g(Mtx); TStringBuf pathTmp = request.GetPathInfo(); for (;;) { - TPagesByPath::iterator i = PagesByPath.find(pathTmp); - if (i != PagesByPath.end()) { - found = i->second; + if (TPagesByPath::iterator i = PagesByPath.find(pathTmp); i != PagesByPath.end()) { + found = *i->second; pathInfo = request.GetPathInfo().substr(pathTmp.size()); Y_VERIFY(pathInfo.empty() || pathInfo.StartsWith('/')); break; @@ -67,18 +66,12 @@ void TIndexMonPage::OutputIndex(IOutputStream& out, bool pathEndsWithSlash) { void TIndexMonPage::Register(TMonPagePtr page) { TGuard<TMutex> g(Mtx); - auto insres = PagesByPath.insert(std::make_pair("/" + page->GetPath(), page)); - if (insres.second) { - // new unique page just inserted, update Pages - Pages.push_back(page); + if (auto [it, inserted] = PagesByPath.try_emplace("/" + page->GetPath()); inserted) { + // new unique page just inserted, insert it to the end + it->second = Pages.insert(Pages.end(), page); } else { // a page with the given path is already present, replace it with the new page - - // find old page, sorry for O(n) - auto it = std::find(Pages.begin(), Pages.end(), insres.first->second); - *it = page; - // this already present, replace it - insres.first->second = page; + *it->second = page; } page->Parent = this; } @@ -101,7 +94,7 @@ IMonPage* TIndexMonPage::FindPage(const TString& relativePath) { if (i == PagesByPath.end()) { return nullptr; } else { - return i->second.Get(); + return i->second->Get(); } } @@ -171,7 +164,7 @@ void TIndexMonPage::OutputBody(IMonHttpRequest& req) { void TIndexMonPage::SortPages() { TGuard<TMutex> g(Mtx); - std::sort(Pages.begin(), Pages.end(), [](const TMonPagePtr& a, const TMonPagePtr& b) { + Pages.sort([](const TMonPagePtr& a, const TMonPagePtr& b) { return AsciiCompareIgnoreCase(a->GetTitle(), b->GetTitle()) < 0; }); } |