소스 검색

Use some noexcept and pure attributes

Bryan Drewery 7 년 전
부모
커밋
de794ef714
7개의 변경된 파일45개의 추가작업 그리고 36개의 파일을 삭제
  1. 3 1
      src/EncryptedStream.h
  2. 4 3
      src/RfcString.cc
  3. 4 3
      src/RfcString.h
  4. 12 11
      src/auth.cc
  5. 18 14
      src/auth.h
  6. 2 2
      src/misc_file.cc
  7. 2 2
      src/misc_file.h

+ 3 - 1
src/EncryptedStream.h

@@ -34,7 +34,9 @@ class EncryptedStream : public bd::Stream {
         EncryptedStream(bd::String& keyStr) : Stream(), key(keyStr), enc_flags(ENC_DEFAULT) {};
         EncryptedStream(EncryptedStream& stream) : Stream(stream), key(stream.key), enc_flags(ENC_DEFAULT) {};
 
-        void setFlags(const char _enc_flags) const { enc_flags = _enc_flags; }
+        void setFlags(const char _enc_flags) const noexcept {
+          enc_flags = _enc_flags;
+        }
         virtual int loadFile(const int fd);
         using bd::Stream::loadFile;
 

+ 4 - 3
src/RfcString.cc

@@ -5,14 +5,15 @@
 #include "RfcString.h"
 
 bool
-RfcString::rfc_equal(const char c1, const char c2) {
+RfcString::rfc_equal(const char c1, const char c2) noexcept {
   if (c1 == c2)
     return true;
   return (rfc_toupper(c1) == rfc_toupper(c2));
 }
 
 int
-RfcString::compare(const RfcString& str, size_t n) const {
+RfcString::compare(const RfcString& str, size_t n) const noexcept
+{
   /* Same string? */
   if (cbegin() == str.cbegin() && length() == str.length())
     return 0;
@@ -41,7 +42,7 @@ RfcString::compare(const RfcString& str, size_t n) const {
 }
 
 size_t
-RfcString::hash() const {
+RfcString::hash() const noexcept {
   if (my_hash != 0) return my_hash;
   std::hash<value_type> hasher;
   size_t _hash = 5381;

+ 4 - 3
src/RfcString.h

@@ -9,7 +9,8 @@ namespace bd {
 
 class RfcString : public bd::String {
   private:
-    static bool rfc_equal(const char c1, const char c2) __attribute__((pure));
+    static bool rfc_equal(const char c1, const char c2) noexcept
+      __attribute__((pure));
 
   protected:
 
@@ -18,7 +19,7 @@ class RfcString : public bd::String {
     RfcString(const String &str) : String(str) {};
     RfcString(String &&str) : String(std::move(str)) {};
 
-    int compare(const RfcString& str, size_t n = npos) const
+    int compare(const RfcString& str, size_t n = npos) const noexcept
       __attribute__((pure));
     friend bool operator==(const RfcString&, const RfcString&);
     friend bool operator!=(const RfcString&, const RfcString&);
@@ -27,7 +28,7 @@ class RfcString : public bd::String {
     friend bool operator>(const RfcString&, const RfcString&);
     friend bool operator>=(const RfcString&, const RfcString&);
 
-    virtual size_t hash() const;
+    virtual size_t hash() const noexcept;
 };
 
 inline bool __attribute__((pure))

+ 12 - 11
src/auth.cc

@@ -65,20 +65,21 @@ Auth::~Auth()
   ht_nick.remove(nick);
 }
 
-void Auth::MakeHash()
+void Auth::MakeHash() noexcept
 {
  make_rand_str(rand, 50);
  makehash(user, rand, hash, 50);
 }
 
-void Auth::Done()
+void Auth::Done() noexcept
 {
   hash[0] = 0;
   rand[0] = 0;
   Status(AUTHED);
 }
 
-void Auth::NewNick(const char *newnick) {
+void Auth::NewNick(const char *newnick) noexcept
+{
   if (ht_nick.contains(nick)) {
     Auth::ht_nick.remove(nick);
   }
@@ -86,7 +87,7 @@ void Auth::NewNick(const char *newnick) {
   ht_nick[newnick] = this;
 }
 
-Auth *Auth::Find(const char *_host)
+Auth *Auth::Find(const char *_host) noexcept
 {
 
   if (ht_host.contains(_host)) {
@@ -107,7 +108,7 @@ static void auth_clear_users_block(const bd::String key, Auth* auth, void *param
   }
 }
 
-void Auth::NullUsers(const char *nick)
+void Auth::NullUsers(const char *nick) noexcept
 {
   if (nick == NULL) {
     ht_host.each(auth_clear_users_block);
@@ -129,7 +130,7 @@ static void auth_fill_users_block(const bd::String key, Auth* auth, void* param)
   auth->user = get_user_by_host(from);
 }
 
-void Auth::FillUsers(const char *nick)
+void Auth::FillUsers(const char *nick) noexcept
 {
   if (nick == NULL) {
     ht_host.each(auth_fill_users_block);
@@ -151,7 +152,7 @@ static void auth_expire_block(const bd::String key, Auth* auth, void* param)
   }
 }
 
-void Auth::ExpireAuths()
+void Auth::ExpireAuths() noexcept
 {
   if (!ischanhub())
     return;
@@ -166,7 +167,7 @@ static void auth_delete_all_block(const bd::String, Auth* auth, void* param)
   delete auth;
 }
 
-void Auth::DeleteAll()
+void Auth::DeleteAll() noexcept
 {
   if (ischanhub()) {
     putlog(LOG_DEBUG, "*", STR("Removing auth entries."));
@@ -176,12 +177,12 @@ void Auth::DeleteAll()
   }
 }
 
-void Auth::InitTimer()
+void Auth::InitTimer() noexcept
 {
   timer_create_secs(60, STR("Auth::ExpireAuths"), (Function) Auth::ExpireAuths);
 }
 
-bool Auth::GetIdx(const char *chname)
+bool Auth::GetIdx(const char *chname) noexcept
 {
 sdprintf(STR("GETIDX: auth: %s, idx: %d"), nick, idx);
   if (idx != -1) {
@@ -252,7 +253,7 @@ static void auth_tell_block(const bd::String key, Auth* auth, void* param)
         (long)auth->authtime, (long)auth->atime, auth->Status());
 }
 
-void Auth::TellAuthed(int idx)
+void Auth::TellAuthed(int idx) noexcept
 {
   ht_host.each(auth_tell_block, (void *) (long) idx);
 }

+ 18 - 14
src/auth.h

@@ -17,20 +17,24 @@ class Auth {
   Auth(const char *, const char *, struct userrec * = NULL);
   ~Auth();
 
-  int Status(int newstat = -1) { if (newstat >= 0) { status = newstat; } return status; }
-  void MakeHash();
-  bool Authed() { return (status == AUTHED); }
-  bool GetIdx(const char *);
-  void Done();
-  void NewNick(const char *nick);
-
-  static Auth *Find(const char * host);
-  static void NullUsers(const char *nick = NULL);
-  static void FillUsers(const char *nick = NULL);
-  static void ExpireAuths();
-  static void InitTimer();
-  static void DeleteAll();
-  static void TellAuthed(int);
+  int Status(int newstat = -1) noexcept {
+    if (newstat >= 0) { status = newstat; } return status;
+  }
+  void MakeHash() noexcept;
+  bool Authed() const noexcept __attribute__((pure)) {
+    return (status == AUTHED);
+  }
+  bool GetIdx(const char *) noexcept;
+  void Done() noexcept;
+  void NewNick(const char *nick) noexcept;
+
+  static Auth *Find(const char * host) noexcept __attribute__((pure));
+  static void NullUsers(const char *nick = NULL) noexcept;
+  static void FillUsers(const char *nick = NULL) noexcept;
+  static void ExpireAuths() noexcept;
+  static void InitTimer() noexcept;
+  static void DeleteAll() noexcept;
+  static void TellAuthed(int) noexcept;
 
   struct userrec *user;
   time_t authtime;              /* what time they authed at */

+ 2 - 2
src/misc_file.cc

@@ -197,7 +197,7 @@ void Tempfile::AllocTempfile()
   MakeTemp();
 }
 
-void Tempfile::MakeTemp()
+void Tempfile::MakeTemp() noexcept
 {
   if ((fd = mkstemp(file)) < 0) {
     f = NULL;
@@ -284,7 +284,7 @@ static bool check_tempdir(bool do_mod)
   return 1;
 }
 
-bool Tempfile::FindDir()
+bool Tempfile::FindDir() noexcept
 {
   /* this is temporary until we make tmpdir customizable */
 

+ 2 - 2
src/misc_file.h

@@ -29,7 +29,7 @@ class Tempfile
     void AllocTempfile();			//constructor with file prefix
     void my_close();
     ~Tempfile();				//destructor
-    static bool FindDir();
+    static bool FindDir() noexcept;
 
     bool error;					//exceptions are lame.
     FILE *f;
@@ -40,7 +40,7 @@ class Tempfile
   private:
     char *prefix;
     int plen;
-    void MakeTemp();				//Used for mktemp() and checking
+    void MakeTemp() noexcept;			//Used for mktemp() and checking
     bool useFopen;
 };