bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#36139: [PATCH] Make better use of the switch op in cond forms


From: Stefan Monnier
Subject: bug#36139: [PATCH] Make better use of the switch op in cond forms
Date: Tue, 18 Jun 2019 15:19:25 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> A single `cond' form can how be compiled to any number of switch ops,
> interspersed with non-switch conditions in arbitrary ways.

It can also be compiled to a bunch of switch ops only, right?
(e.g. if it starts with a switch on `x` and then is followed by
a switch on `y`)

> +    (and (> (length cases) 1)

I think this `1` deserves a comment (IIRC it's the number of cases
above which using a switch is expected to be faster than a sequence of
tests).

> +        ;; Since `byte-compile-body' might increase `byte-compile-depth'
> +        ;; by 1, not preserving its value will cause it to potentially
> +        ;; increase by one for every clause body compiled, causing
> +        ;; depth/tag conflicts or violating asserts down the road.
> +        ;; To make sure `byte-compile-body' itself doesn't violate this,
> +        ;; we use `cl-assert'.
> +        (byte-compile-body body byte-compile--for-effect)
> +        (cl-assert (or (= byte-compile-depth init-depth)
> +                       (= byte-compile-depth (1+ init-depth))))

IIRC the depth is altered depending on byte-compile--for-effect (if
byte-compile--for-effect is non-nil when entering the function but nil
afterwards, depth should be identical, and it should be increased by
1 otherwise), so we should be able to tighten this assertion to replace
the `or` with an `if`.

Other than that, the patch looks fine to me.


        Stefan






reply via email to

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