[Git][ghc/ghc][wip/hash-free] rts/Hash: Don't iterate over chunks if we don't need to free data

Ben Gamari (@bgamari) gitlab at gitlab.haskell.org
Tue Feb 6 18:18:30 UTC 2024



Ben Gamari pushed to branch wip/hash-free at Glasgow Haskell Compiler / GHC


Commits:
cf20c828 by Ben Gamari at 2024-02-06T13:18:02-05:00
rts/Hash: Don't iterate over chunks if we don't need to free data

When freeing a `HashTable` there is no reason to walk over the hash list
before freeing it if the user has not given us a `dataFreeFun`.

Noticed while looking at #24410.

- - - - -


1 changed file:

- rts/Hash.c


Changes:

=====================================
rts/Hash.c
=====================================
@@ -442,14 +442,15 @@ freeHashTable(HashTable *table, void (*freeDataFun)(void *) )
 
     /* Free table segments */
     while (segment >= 0) {
-        while (index >= 0) {
-            HashList *next;
-            for (HashList *hl = table->dir[segment][index]; hl != NULL; hl = next) {
-                next = hl->next;
-                if (freeDataFun != NULL)
+        if (freeDataFun) {
+            while (index >= 0) {
+                HashList *next;
+                for (HashList *hl = table->dir[segment][index]; hl != NULL; hl = next) {
+                    next = hl->next;
                     (*freeDataFun)((void *) hl->data);
+                }
+                index--;
             }
-            index--;
         }
         stgFree(table->dir[segment]);
         segment--;



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cf20c828f68d7e1cb3c2f0ece40856ab5768be86

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cf20c828f68d7e1cb3c2f0ece40856ab5768be86
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240206/16800fcd/attachment-0001.html>


More information about the ghc-commits mailing list