From 95e646fca72627acd41b2b4fb5add2210cbe5cfd Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 4 Feb 2020 12:50:52 +0100 Subject: [PATCH] util: optimize the normal_path() common case Speeds up Zeek startup by 2%. --- src/util.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/util.cc b/src/util.cc index 37832d089d..b143d0a4ef 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1612,6 +1612,15 @@ TEST_CASE("util normalize_path") string normalize_path(std::string_view path) { + if ( path.find("/.") == std::string_view::npos && + path.find("//") == std::string_view::npos ) + { + // no need to normalize anything + if ( path.size() > 1 && path.back() == '/' ) + path.remove_suffix(1); + return std::string(path); + } + size_t n; vector final_components; string new_path;