MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / optimize

Function optimize

extern/tinyexpr/tinyexpr.c:563–586  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

561#undef M
562
563static void optimize(te_expr *n) {
564 /* Evaluates as much as possible. */
565 if (n->type == TE_CONSTANT) return;
566 if (n->type == TE_VARIABLE) return;
567
568 /* Only optimize out functions flagged as pure. */
569 if (IS_PURE(n->type)) {
570 const int arity = ARITY(n->type);
571 int known = 1;
572 int i;
573 for (i = 0; i < arity; ++i) {
574 optimize(n->parameters[i]);
575 if (((te_expr*)(n->parameters[i]))->type != TE_CONSTANT) {
576 known = 0;
577 }
578 }
579 if (known) {
580 const double value = te_eval(n);
581 te_free_parameters(n);
582 n->type = TE_CONSTANT;
583 n->value = value;
584 }
585 }
586}
587
588
589te_expr *te_compile(const char *expression, const te_variable *variables, int var_count, int *error) {

Callers 2

psincos_floatFunction · 0.85
te_compileFunction · 0.85

Calls 2

te_evalFunction · 0.85
te_free_parametersFunction · 0.85

Tested by

no test coverage detected