Skip to content

Commit

Permalink
speed up compile by map
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwzbwcom committed Sep 3, 2021
1 parent 6622ecb commit 984dd10
Showing 1 changed file with 72 additions and 69 deletions.
141 changes: 72 additions & 69 deletions src/backend/function-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,75 @@ const acorn = require('acorn');
const { utils } = require('../utils');
const { FunctionTracer } = require('./function-tracer');

const mathProperties = {
'E': true,
'PI': true,
'SQRT2': true,
'SQRT1_2': true,
'LN2': true,
'LN10': true,
'LOG2E': true,
'LOG10E': true,
};

const mathFunctions = {
'abs': true,
'acos': true,
'acosh': true,
'asin': true,
'asinh': true,
'atan': true,
'atan2': true,
'atanh': true,
'cbrt': true,
'ceil': true,
'clz32': true,
'cos': true,
'cosh': true,
'expm1': true,
'exp': true,
'floor': true,
'fround': true,
'imul': true,
'log': true,
'log2': true,
'log10': true,
'log1p': true,
'max': true,
'min': true,
'pow': true,
'random': true,
'round': true,
'sign': true,
'sin': true,
'sinh': true,
'sqrt': true,
'tan': true,
'tanh': true,
'trunc': true,
};

const allowedExpressions = {
'value': true,
'value[]': true,
'value[][]': true,
'value[][][]': true,
'value[][][][]': true,
'value.value': true,
'value.thread.value': true,
'this.thread.value': true,
'this.output.value': true,
'this.constants.value': true,
'this.constants.value[]': true,
'this.constants.value[][]': true,
'this.constants.value[][][]': true,
'this.constants.value[][][][]': true,
'fn()[]': true,
'fn()[][]': true,
'fn()[][][]': true,
'[][]': true,
};

/**
*
* @desc Represents a single function, inside JS, webGL, or openGL.
Expand Down Expand Up @@ -592,61 +661,15 @@ class FunctionNode {
}

isAstMathVariable(ast) {
const mathProperties = [
'E',
'PI',
'SQRT2',
'SQRT1_2',
'LN2',
'LN10',
'LOG2E',
'LOG10E',
];
return ast.type === 'MemberExpression' &&
ast.object && ast.object.type === 'Identifier' &&
ast.object.name === 'Math' &&
ast.property &&
ast.property.type === 'Identifier' &&
mathProperties.indexOf(ast.property.name) > -1;
!!mathProperties[ast.property.name];
}

isAstMathFunction(ast) {
const mathFunctions = [
'abs',
'acos',
'acosh',
'asin',
'asinh',
'atan',
'atan2',
'atanh',
'cbrt',
'ceil',
'clz32',
'cos',
'cosh',
'expm1',
'exp',
'floor',
'fround',
'imul',
'log',
'log2',
'log10',
'log1p',
'max',
'min',
'pow',
'random',
'round',
'sign',
'sin',
'sinh',
'sqrt',
'tan',
'tanh',
'trunc',
];
return ast.type === 'CallExpression' &&
ast.callee &&
ast.callee.type === 'MemberExpression' &&
Expand All @@ -655,7 +678,7 @@ class FunctionNode {
ast.callee.object.name === 'Math' &&
ast.callee.property &&
ast.callee.property.type === 'Identifier' &&
mathFunctions.indexOf(ast.callee.property.name) > -1;
!!mathFunctions[ast.callee.property.name];
}

isAstVariable(ast) {
Expand Down Expand Up @@ -844,27 +867,7 @@ class FunctionNode {
return signatureString;
}

const allowedExpressions = [
'value',
'value[]',
'value[][]',
'value[][][]',
'value[][][][]',
'value.value',
'value.thread.value',
'this.thread.value',
'this.output.value',
'this.constants.value',
'this.constants.value[]',
'this.constants.value[][]',
'this.constants.value[][][]',
'this.constants.value[][][][]',
'fn()[]',
'fn()[][]',
'fn()[][][]',
'[][]',
];
if (allowedExpressions.indexOf(signatureString) > -1) {
if (!!allowedExpressions[signatureString]) {
return signatureString;
}
return null;
Expand Down

0 comments on commit 984dd10

Please sign in to comment.