Skip to content

Commit

Permalink
perf(shader-ast): avoid nested literals
Browse files Browse the repository at this point in the history
- update `lit()` to avoid nesting if already same type & info
  • Loading branch information
postspectacular committed Aug 14, 2021
1 parent 394dd49 commit 998cf35
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/shader-ast/src/ast/lit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ import type {
import type { NumericB, NumericF, Type } from "../api/types";
import { isVec } from "./checks";

export const lit = <T extends Type>(
type: T,
val: any,
info?: string
): Lit<T> => ({
tag: "lit",
type,
info,
val,
});
export const lit = <T extends Type>(type: T, val: any, info?: string): Lit<T> =>
type === val.type && info === val.info
? val
: {
tag: "lit",
type,
info,
val,
};

export const bool = (x: NumericB) => lit("bool", isNumber(x) ? !!x : x);

Expand Down

0 comments on commit 998cf35

Please sign in to comment.