]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Slightly refactor set iteration
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 15 Aug 2018 14:33:29 +0000 (15:33 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 15 Aug 2018 14:33:29 +0000 (15:33 +0100)
contrib/libucl/khash.h
src/libserver/events.c

index a91db5b2a528e797b33968d734052d21b09b9ea1..3e580011dbd6b78da0ad73d30096fd3fb9480347 100644 (file)
@@ -583,6 +583,14 @@ static kh_inline khint_t __ac_Wang_hash(khint_t key)
                code;                                                                                           \
        } }
 
+#define kh_foreach_key(h, kvar, code) {                                                \
+       khint_t __i;                                                                                    \
+       for (__i = kh_begin(h); __i != kh_end(h); ++__i) {              \
+               if (!kh_exist(h,__i)) continue;                                         \
+               (kvar) = kh_key(h,__i);                                                         \
+               code;                                                                                           \
+       } }
+
 /* More conenient interfaces */
 
 /*! @function
index bff35351f3e9a3b0de41f9e50ac931e26d642237..c23c903285d1adf3be072ec9a2b3a1072c043040 100644 (file)
@@ -309,17 +309,13 @@ void
 rspamd_session_cleanup (struct rspamd_async_session *session)
 {
        struct rspamd_async_event *ev;
-       int i;
 
        if (session == NULL) {
                msg_err ("session is NULL");
                return;
        }
 
-       for (i = kh_begin (session->events); i != kh_end (session->events); i ++) {
-               if (!kh_exist (session->events, i)) continue;
-               ev = kh_key (session->events, i);
-
+       kh_foreach_key (session->events, ev, {
                /* Call event's finalizer */
                msg_debug_session ("removed event on destroy: %p, subsystem: %s",
                                ev->user_data,
@@ -328,7 +324,7 @@ rspamd_session_cleanup (struct rspamd_async_session *session)
                if (ev->fin != NULL) {
                        ev->fin (ev->user_data);
                }
-       }
+       });
 
        kh_clear (rspamd_events_hash, session->events);
 }