From 51c0a03e9497475e4d486d65a81cc58ccbf0e36a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 7 Oct 2023 10:19:56 +0200 Subject: [PATCH] fs/FileInfo: add `constexpr` and `noexcept` --- src/fs/FileInfo.hxx | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/fs/FileInfo.hxx b/src/fs/FileInfo.hxx index ffe12af4c..75696840f 100644 --- a/src/fs/FileInfo.hxx +++ b/src/fs/FileInfo.hxx @@ -1,8 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef MPD_FS_FILE_INFO_HXX -#define MPD_FS_FILE_INFO_HXX +#pragma once #include "Path.hxx" #include "lib/fmt/PathFormatter.hxx" @@ -19,7 +18,7 @@ class FileInfo { friend bool GetFileInfo(Path path, FileInfo &info, - bool follow_symlinks); + bool follow_symlinks) noexcept; friend class FileReader; #ifdef _WIN32 @@ -29,7 +28,7 @@ class FileInfo { #endif public: - FileInfo() = default; + constexpr FileInfo() noexcept = default; FileInfo(Path path, bool follow_symlinks=true) { if (!GetFileInfo(path, *this, follow_symlinks)) { @@ -41,7 +40,7 @@ public: } } - bool IsRegular() const { + constexpr bool IsRegular() const noexcept { #ifdef _WIN32 return (data.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_DEVICE)) == 0; @@ -50,7 +49,7 @@ public: #endif } - bool IsDirectory() const { + constexpr bool IsDirectory() const noexcept { #ifdef _WIN32 return data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY; #else @@ -58,7 +57,7 @@ public: #endif } - uint64_t GetSize() const { + constexpr uint64_t GetSize() const noexcept { #ifdef _WIN32 return ConstructUint64(data.nFileSizeLow, data.nFileSizeHigh); #else @@ -66,7 +65,8 @@ public: #endif } - std::chrono::system_clock::time_point GetModificationTime() const { + [[gnu::pure]] + std::chrono::system_clock::time_point GetModificationTime() const noexcept { #ifdef _WIN32 return FileTimeToChrono(data.ftLastWriteTime); #else @@ -75,26 +75,26 @@ public: } #ifndef _WIN32 - uid_t GetUid() const { + constexpr uid_t GetUid() const noexcept { return st.st_uid; } - mode_t GetMode() const { + constexpr mode_t GetMode() const noexcept { return st.st_mode; } - dev_t GetDevice() const { + constexpr dev_t GetDevice() const noexcept { return st.st_dev; } - ino_t GetInode() const { + constexpr ino_t GetInode() const noexcept { return st.st_ino; } #endif }; inline bool -GetFileInfo(Path path, FileInfo &info, bool follow_symlinks=true) +GetFileInfo(Path path, FileInfo &info, bool follow_symlinks=true) noexcept { #ifdef _WIN32 (void)follow_symlinks; @@ -107,5 +107,3 @@ GetFileInfo(Path path, FileInfo &info, bool follow_symlinks=true) return ret == 0; #endif } - -#endif