From 2721dee9889f2bd1401ea81874e7c6ab44db0b47 Mon Sep 17 00:00:00 2001 From: freshgum-bubbles Date: Tue, 25 Jul 2023 23:41:15 +0100 Subject: [PATCH] refactor(ContainerInstance): remove boolean casts --- src/container-instance.class.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/container-instance.class.ts b/src/container-instance.class.ts index 473df350..cae5ce0d 100644 --- a/src/container-instance.class.ts +++ b/src/container-instance.class.ts @@ -1117,15 +1117,15 @@ export class ContainerInstance implements Disposable { /** * For the individual bit flags, we don't care about the return from `&`. * All that matters is that, if it doesn't return 0, the flag is activated. - * - * Implementation note: as an optimisation, we use double negative to cast - * the result to boolean instead of an explicit `Boolean` call here. - * To clarify, the "!!" does the *exact* same thing as `Boolean`. + * + * We also don't cast to boolean here, as 0 evaluates to "false", + * while anything nonzero evaluates to "true". + * This saves bytes in the final bundle. */ - const isOptional = !!(constraints & ResolutionConstraintFlag.Optional); - const isSkipSelf = !!(constraints & ResolutionConstraintFlag.SkipSelf); - const isSelf = !!(constraints & ResolutionConstraintFlag.Self); - const isMany = !!(constraints & ResolutionConstraintFlag.Many); + const isOptional = constraints & ResolutionConstraintFlag.Optional; + const isSkipSelf = constraints & ResolutionConstraintFlag.SkipSelf; + const isSelf = constraints & ResolutionConstraintFlag.Self; + const isMany = constraints & ResolutionConstraintFlag.Many; /** SkipSelf() and Self() are incompatible. */ if (isSkipSelf && isSelf) {