*: add "noexcept" to many, many function prototypes
This eliminates some overhead, because the compiler doesn't need to consider these functions throwing.
This commit is contained in:
@@ -149,7 +149,7 @@ FormatErrno(const char *fmt, Args&&... args)
|
||||
|
||||
gcc_pure
|
||||
static inline bool
|
||||
IsFileNotFound(const std::system_error &e)
|
||||
IsFileNotFound(const std::system_error &e) noexcept
|
||||
{
|
||||
#ifdef WIN32
|
||||
return e.code().category() == std::system_category() &&
|
||||
@@ -162,7 +162,7 @@ IsFileNotFound(const std::system_error &e)
|
||||
|
||||
gcc_pure
|
||||
static inline bool
|
||||
IsPathNotFound(const std::system_error &e)
|
||||
IsPathNotFound(const std::system_error &e) noexcept
|
||||
{
|
||||
#ifdef WIN32
|
||||
return e.code().category() == std::system_category() &&
|
||||
@@ -175,7 +175,7 @@ IsPathNotFound(const std::system_error &e)
|
||||
|
||||
gcc_pure
|
||||
static inline bool
|
||||
IsAccessDenied(const std::system_error &e)
|
||||
IsAccessDenied(const std::system_error &e) noexcept
|
||||
{
|
||||
#ifdef WIN32
|
||||
return e.code().category() == std::system_category() &&
|
||||
|
@@ -58,14 +58,14 @@
|
||||
#endif
|
||||
|
||||
bool
|
||||
FileDescriptor::Open(const char *pathname, int flags, mode_t mode)
|
||||
FileDescriptor::Open(const char *pathname, int flags, mode_t mode) noexcept
|
||||
{
|
||||
fd = ::open(pathname, flags | O_NOCTTY | O_CLOEXEC, mode);
|
||||
return IsDefined();
|
||||
}
|
||||
|
||||
bool
|
||||
FileDescriptor::OpenReadOnly(const char *pathname)
|
||||
FileDescriptor::OpenReadOnly(const char *pathname) noexcept
|
||||
{
|
||||
return Open(pathname, O_RDONLY);
|
||||
}
|
||||
@@ -73,13 +73,13 @@ FileDescriptor::OpenReadOnly(const char *pathname)
|
||||
#ifndef WIN32
|
||||
|
||||
bool
|
||||
FileDescriptor::OpenNonBlocking(const char *pathname)
|
||||
FileDescriptor::OpenNonBlocking(const char *pathname) noexcept
|
||||
{
|
||||
return Open(pathname, O_RDWR | O_NONBLOCK);
|
||||
}
|
||||
|
||||
bool
|
||||
FileDescriptor::CreatePipe(FileDescriptor &r, FileDescriptor &w)
|
||||
FileDescriptor::CreatePipe(FileDescriptor &r, FileDescriptor &w) noexcept
|
||||
{
|
||||
int fds[2];
|
||||
|
||||
@@ -99,7 +99,7 @@ FileDescriptor::CreatePipe(FileDescriptor &r, FileDescriptor &w)
|
||||
}
|
||||
|
||||
void
|
||||
FileDescriptor::SetNonBlocking()
|
||||
FileDescriptor::SetNonBlocking() noexcept
|
||||
{
|
||||
assert(IsDefined());
|
||||
|
||||
@@ -108,7 +108,7 @@ FileDescriptor::SetNonBlocking()
|
||||
}
|
||||
|
||||
void
|
||||
FileDescriptor::SetBlocking()
|
||||
FileDescriptor::SetBlocking() noexcept
|
||||
{
|
||||
assert(IsDefined());
|
||||
|
||||
@@ -121,7 +121,7 @@ FileDescriptor::SetBlocking()
|
||||
#ifdef USE_EVENTFD
|
||||
|
||||
bool
|
||||
FileDescriptor::CreateEventFD(unsigned initval)
|
||||
FileDescriptor::CreateEventFD(unsigned initval) noexcept
|
||||
{
|
||||
fd = ::eventfd(initval, EFD_NONBLOCK|EFD_CLOEXEC);
|
||||
return fd >= 0;
|
||||
@@ -132,7 +132,7 @@ FileDescriptor::CreateEventFD(unsigned initval)
|
||||
#ifdef USE_SIGNALFD
|
||||
|
||||
bool
|
||||
FileDescriptor::CreateSignalFD(const sigset_t *mask)
|
||||
FileDescriptor::CreateSignalFD(const sigset_t *mask) noexcept
|
||||
{
|
||||
int new_fd = ::signalfd(fd, mask, SFD_NONBLOCK|SFD_CLOEXEC);
|
||||
if (new_fd < 0)
|
||||
@@ -147,7 +147,7 @@ FileDescriptor::CreateSignalFD(const sigset_t *mask)
|
||||
#ifdef HAVE_INOTIFY_INIT
|
||||
|
||||
bool
|
||||
FileDescriptor::CreateInotify()
|
||||
FileDescriptor::CreateInotify() noexcept
|
||||
{
|
||||
#ifdef HAVE_INOTIFY_INIT1
|
||||
int new_fd = inotify_init1(IN_CLOEXEC|IN_NONBLOCK);
|
||||
@@ -168,7 +168,7 @@ FileDescriptor::CreateInotify()
|
||||
#endif
|
||||
|
||||
bool
|
||||
FileDescriptor::Rewind()
|
||||
FileDescriptor::Rewind() noexcept
|
||||
{
|
||||
assert(IsDefined());
|
||||
|
||||
@@ -176,7 +176,7 @@ FileDescriptor::Rewind()
|
||||
}
|
||||
|
||||
off_t
|
||||
FileDescriptor::GetSize() const
|
||||
FileDescriptor::GetSize() const noexcept
|
||||
{
|
||||
struct stat st;
|
||||
return ::fstat(fd, &st) >= 0
|
||||
@@ -187,7 +187,7 @@ FileDescriptor::GetSize() const
|
||||
#ifndef WIN32
|
||||
|
||||
int
|
||||
FileDescriptor::Poll(short events, int timeout) const
|
||||
FileDescriptor::Poll(short events, int timeout) const noexcept
|
||||
{
|
||||
assert(IsDefined());
|
||||
|
||||
@@ -201,13 +201,13 @@ FileDescriptor::Poll(short events, int timeout) const
|
||||
}
|
||||
|
||||
int
|
||||
FileDescriptor::WaitReadable(int timeout) const
|
||||
FileDescriptor::WaitReadable(int timeout) const noexcept
|
||||
{
|
||||
return Poll(POLLIN, timeout);
|
||||
}
|
||||
|
||||
int
|
||||
FileDescriptor::WaitWritable(int timeout) const
|
||||
FileDescriptor::WaitWritable(int timeout) const noexcept
|
||||
{
|
||||
return Poll(POLLOUT, timeout);
|
||||
}
|
||||
|
@@ -70,11 +70,11 @@ public:
|
||||
return fd;
|
||||
}
|
||||
|
||||
void Set(int _fd) {
|
||||
void Set(int _fd) noexcept {
|
||||
fd = _fd;
|
||||
}
|
||||
|
||||
int Steal() {
|
||||
int Steal() noexcept {
|
||||
assert(IsDefined());
|
||||
|
||||
int _fd = fd;
|
||||
@@ -82,7 +82,7 @@ public:
|
||||
return _fd;
|
||||
}
|
||||
|
||||
void SetUndefined() {
|
||||
void SetUndefined() noexcept {
|
||||
fd = -1;
|
||||
}
|
||||
|
||||
@@ -90,42 +90,42 @@ public:
|
||||
return FileDescriptor(-1);
|
||||
}
|
||||
|
||||
bool Open(const char *pathname, int flags, mode_t mode=0666);
|
||||
bool OpenReadOnly(const char *pathname);
|
||||
bool Open(const char *pathname, int flags, mode_t mode=0666) noexcept;
|
||||
bool OpenReadOnly(const char *pathname) noexcept;
|
||||
|
||||
#ifndef WIN32
|
||||
bool OpenNonBlocking(const char *pathname);
|
||||
bool OpenNonBlocking(const char *pathname) noexcept;
|
||||
|
||||
static bool CreatePipe(FileDescriptor &r, FileDescriptor &w);
|
||||
static bool CreatePipe(FileDescriptor &r, FileDescriptor &w) noexcept;
|
||||
|
||||
/**
|
||||
* Enable non-blocking mode on this file descriptor.
|
||||
*/
|
||||
void SetNonBlocking();
|
||||
void SetNonBlocking() noexcept;
|
||||
|
||||
/**
|
||||
* Enable blocking mode on this file descriptor.
|
||||
*/
|
||||
void SetBlocking();
|
||||
void SetBlocking() noexcept;
|
||||
|
||||
/**
|
||||
* Duplicate the file descriptor onto the given file descriptor.
|
||||
*/
|
||||
bool Duplicate(int new_fd) const {
|
||||
bool Duplicate(int new_fd) const noexcept {
|
||||
return ::dup2(Get(), new_fd) == 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_EVENTFD
|
||||
bool CreateEventFD(unsigned initval=0);
|
||||
bool CreateEventFD(unsigned initval=0) noexcept;
|
||||
#endif
|
||||
|
||||
#ifdef USE_SIGNALFD
|
||||
bool CreateSignalFD(const sigset_t *mask);
|
||||
bool CreateSignalFD(const sigset_t *mask) noexcept;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_INOTIFY_INIT
|
||||
bool CreateInotify();
|
||||
bool CreateInotify() noexcept;
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -133,25 +133,25 @@ public:
|
||||
* "undefined" object. After this call, IsDefined() is guaranteed
|
||||
* to return false, and this object may be reused.
|
||||
*/
|
||||
bool Close() {
|
||||
bool Close() noexcept {
|
||||
return ::close(Steal()) == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewind the pointer to the beginning of the file.
|
||||
*/
|
||||
bool Rewind();
|
||||
bool Rewind() noexcept;
|
||||
|
||||
off_t Seek(off_t offset) {
|
||||
off_t Seek(off_t offset) noexcept {
|
||||
return lseek(Get(), offset, SEEK_SET);
|
||||
}
|
||||
|
||||
off_t Skip(off_t offset) {
|
||||
off_t Skip(off_t offset) noexcept {
|
||||
return lseek(Get(), offset, SEEK_CUR);
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
off_t Tell() const {
|
||||
off_t Tell() const noexcept {
|
||||
return lseek(Get(), 0, SEEK_CUR);
|
||||
}
|
||||
|
||||
@@ -159,21 +159,21 @@ public:
|
||||
* Returns the size of the file in bytes, or -1 on error.
|
||||
*/
|
||||
gcc_pure
|
||||
off_t GetSize() const;
|
||||
off_t GetSize() const noexcept;
|
||||
|
||||
ssize_t Read(void *buffer, size_t length) {
|
||||
ssize_t Read(void *buffer, size_t length) noexcept {
|
||||
return ::read(fd, buffer, length);
|
||||
}
|
||||
|
||||
ssize_t Write(const void *buffer, size_t length) {
|
||||
ssize_t Write(const void *buffer, size_t length) noexcept {
|
||||
return ::write(fd, buffer, length);
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
int Poll(short events, int timeout) const;
|
||||
int Poll(short events, int timeout) const noexcept;
|
||||
|
||||
int WaitReadable(int timeout) const;
|
||||
int WaitWritable(int timeout) const;
|
||||
int WaitReadable(int timeout) const noexcept;
|
||||
int WaitWritable(int timeout) const noexcept;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user