From ef4584a60f35a8464eb5811ad4dc1860244db6bc Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Thu, 3 May 2018 22:56:40 +0100 Subject: [PATCH] Skip apply-patch! make-work if patch is empty --- syndicate/dataspace.rkt | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/syndicate/dataspace.rkt b/syndicate/dataspace.rkt index c8d3823..ce6ccf1 100644 --- a/syndicate/dataspace.rkt +++ b/syndicate/dataspace.rkt @@ -362,18 +362,19 @@ (run-all-pending-scripts! ds)))) (define (apply-patch! ds ac delta [restriction-path #f]) - (define ds-assertions (dataspace-assertions ds)) - (define rt (dataspace-routing-table ds)) - (define new-cleanup-changes - (for/fold [(cleanup-changes (actor-cleanup-changes ac))] [((a count) (in-bag/count delta))] - (match (bag-change! ds-assertions (cons a restriction-path) count) - ['present->absent (remove-assertion! rt a restriction-path)] - ['absent->present (add-assertion! rt a restriction-path)] - ;; 'absent->absent absurd - ['present->present (void)]) ;; i.e. no visible change - (define-values (updated-bag _summary) (bag-change cleanup-changes a (- count))) - updated-bag)) - (set-actor-cleanup-changes! ac new-cleanup-changes)) + (when (not (bag-empty? delta)) + (define ds-assertions (dataspace-assertions ds)) + (define rt (dataspace-routing-table ds)) + (define new-cleanup-changes + (for/fold [(cleanup-changes (actor-cleanup-changes ac))] [((a count) (in-bag/count delta))] + (match (bag-change! ds-assertions (cons a restriction-path) count) + ['present->absent (remove-assertion! rt a restriction-path)] + ['absent->present (add-assertion! rt a restriction-path)] + ;; 'absent->absent absurd + ['present->present (void)]) ;; i.e. no visible change + (define-values (updated-bag _summary) (bag-change cleanup-changes a (- count))) + updated-bag)) + (set-actor-cleanup-changes! ac new-cleanup-changes))) (define (run-scripts! ds) (run-all-pending-scripts! ds)