guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[shepherd] 03/03: Remove manual hash table resizing code.


From: Ludovic Courtès
Subject: [shepherd] 03/03: Remove manual hash table resizing code.
Date: Wed, 13 Jan 2016 22:49:05 +0000

civodul pushed a commit to branch master
in repository shepherd.

commit 4fb3a18499a325d194d99ab14feb557c9b9f90fd
Author: Ludovic Courtès <address@hidden>
Date:   Wed Jan 13 22:24:40 2016 +0100

    Remove manual hash table resizing code.
    
    * modules/shepherd/service.scm (services-max-cnt, services-cnt): Remove.
    (register-services)[register-single-service]: Remove manual hash table
    resizing code.
    (deregister-service)[deregister]: Likewise.
    * modules/shepherd/support.scm (copy-hashq-table): Remove.
---
 modules/shepherd/service.scm |   27 +++------------------------
 modules/shepherd/support.scm |   11 -----------
 2 files changed, 3 insertions(+), 35 deletions(-)

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index b5da166..e7ead91 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -748,15 +748,8 @@ given USER and/or GROUP to run COMMAND."
 
 ;;; Registered services.
 
-;; Current size of the hash table below.  The table will be resized on
-;; demand.
-(define services-max-cnt 100)
-
-;; Number of used entries in the table below.
-(define services-cnt 0)
-
 ;; All registered services.
-(define services (make-hash-table services-max-cnt))
+(define services (make-hash-table 75))
 
 ;;; Perform actions with services:
 
@@ -880,16 +873,6 @@ otherwise by updating its state."
     ;; Insert into the hash table.
     (for-each (lambda (name)
                (let ((old (lookup-services name)))
-                 ;; Counting the number of used entries.
-                 (and (null? old)
-                      (set! services-cnt (1+ services-cnt)))
-                 (and (= services-cnt services-max-cnt)
-                      (begin
-                        ;; Double the size, so that we don't have to
-                        ;; do all this too often.
-                        (set! services-max-cnt (* 2 services-max-cnt))
-                        (set! services
-                              (copy-hashq-table services services-max-cnt))))
                  ;; Actually add the new service now.
                  (hashq-set! services name (cons new old))))
              (provided-by new)))
@@ -912,12 +895,8 @@ requested to be removed."
      (lambda (name)
        (let ((old (lookup-services name)))
          (if (= 1 (length old))
-             ;; Only service provides this service, ergo:
-             (begin
-               ;; Reduce provided services count
-               (set! services-cnt (1- services-cnt))
-               ;; Remove service entry from services.
-               (hashq-remove! services name))
+             ;; Only service provides this service; remove it.
+             (hashq-remove! services name)
              ;; ELSE: remove service from providing services.
              (hashq-set! services name
                          (remove
diff --git a/modules/shepherd/support.scm b/modules/shepherd/support.scm
index f505967..dad7b2c 100644
--- a/modules/shepherd/support.scm
+++ b/modules/shepherd/support.scm
@@ -26,7 +26,6 @@
             assert
             label
             can-apply?
-            copy-hashq-table
 
             catch-system-error
             with-system-error-handling
@@ -102,16 +101,6 @@
                (or rest? (<= num-args (+ required optional)))))
          (_ #t))))
 
-;; Put the data from TABLE into a new hash-table of size SIZE.  Use
-;; `eq?' when inserting.  This will be dropped as soon as stable Guile
-;; supports resizable hash tables (it's in the Guile CVS already).
-(define (copy-hashq-table table size)
-  (hash-fold (lambda (key value new-table)
-              (hashq-set! new-table key value)
-              new-table)
-            (make-hash-table size)
-            table))
-
 ;; Evaluate `EXPR ...' until a system error occurs, then skip the
 ;; remaining code.
 (define-syntax-rule (catch-system-error EXPR ...)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]