MCPcopy Create free account
hub / github.com/crownengine/crown / optimize

Function optimize

3rdparty/tinyexpr/tinyexpr.c:639–662  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

637#undef M
638
639static void optimize(te_expr *n) {
640 /* Evaluates as much as possible. */
641 if (n->type == TE_CONSTANT) return;
642 if (n->type == TE_VARIABLE) return;
643
644 /* Only optimize out functions flagged as pure. */
645 if (IS_PURE(n->type)) {
646 const int arity = ARITY(n->type);
647 int known = 1;
648 int i;
649 for (i = 0; i < arity; ++i) {
650 optimize(n->parameters[i]);
651 if (((te_expr*)(n->parameters[i]))->type != TE_CONSTANT) {
652 known = 0;
653 }
654 }
655 if (known) {
656 const double value = te_eval(n);
657 te_free_parameters(n);
658 n->type = TE_CONSTANT;
659 n->value = value;
660 }
661 }
662}
663
664
665te_expr *te_compile(const char *expression, const te_variable *variables, int var_count, int *error) {

Callers 1

te_compileFunction · 0.85

Calls 2

te_evalFunction · 0.85
te_free_parametersFunction · 0.85

Tested by

no test coverage detected