From cc2129808b8dabce3f8457d9006890ce1557131c Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Mon, 17 Jun 2024 16:45:29 +0300 Subject: [PATCH] file: Use lighter access to map of fs-info-s Every time make_file_impl() creates a file it first counts the number of entries for the device, then tries to lookup the entry. Instead of relying on compiler to optimize it, it's nicer to lookup the entry once. Signed-off-by: Pavel Emelyanov --- src/core/file.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/file.cc b/src/core/file.cc index 1a05f819cf7..f2088404fb9 100644 --- a/src/core/file.cc +++ b/src/core/file.cc @@ -1078,7 +1078,8 @@ make_file_impl(int fd, file_open_options options, int flags, struct stat st) noe auto st_dev = st.st_dev; static thread_local std::unordered_map s_fstype; - if (s_fstype.count(st_dev) == 0) { + auto i = s_fstype.find(st_dev); + if (i == s_fstype.end()) [[unlikely]] { return engine().fstatfs(fd).then([fd, options = std::move(options), flags, st = std::move(st)] (struct statfs sfs) { internal::fs_info fsi; fsi.block_size = sfs.f_bsize; @@ -1126,13 +1127,12 @@ make_file_impl(int fd, file_open_options options, int flags, struct stat st) noe fsi.fsync_is_exclusive = true; fsi.nowait_works = false; } - auto st_dev = st.st_dev; - s_fstype[st_dev] = std::move(fsi); + s_fstype.insert(std::make_pair(st.st_dev, std::move(fsi))); return make_file_impl(fd, std::move(options), flags, std::move(st)); }); } - const internal::fs_info& fsi = s_fstype[st_dev]; + const internal::fs_info& fsi = i->second; if (!fsi.append_challenged || options.append_is_unlikely || ((flags & O_ACCMODE) == O_RDONLY)) { return make_ready_future>(make_shared(fd, open_flags(flags), std::move(options), fsi, st_dev)); }