diff --git a/src/dir_mem.c b/src/dir_mem.c
index 6930b2b8bad8383ade2f68eac36878ac476263b0..5007980925bbd1213d639c8a84f004e2070412d6 100644
--- a/src/dir_mem.c
+++ b/src/dir_mem.c
@@ -67,10 +67,8 @@ static void hlink_check(struct dir *d) {
 
   /* found in the table? update hlnk */
   if(!i) {
-    t = d->hlnk = kh_key(links, k);
-    if(t->hlnk != NULL)
-      for(t=t->hlnk; t->hlnk!=d->hlnk; t=t->hlnk)
-        ;
+    t = kh_key(links, k);
+    d->hlnk = t->hlnk == NULL ? t : t->hlnk;
     t->hlnk = d;
   }