class InlineSimpleMethods extends MethodCompilerPass
A.prototype.foo = function() { return this.b; } B.prototype.foo = function() { return this.b; }will inline foo, but
A.prototype.foo = function() { return this.b; } B.prototype.foo = function() { return this.c; }will not. Declarations are not removed because we do not find all possible call sites. For examples, calls of the form foo["bar"] are not detected.
Modifier and Type | Class and Description |
---|---|
private class |
InlineSimpleMethods.InlineTrivialAccessors
For each method call, see if it is a candidate for inlining.
|
MethodCompilerPass.SignatureStore
Modifier and Type | Field and Description |
---|---|
(package private) static MethodCompilerPass.SignatureStore |
DUMMY_SIGNATURE_STORE
A do-nothing signature store.
|
private static java.util.logging.Logger |
logger |
compiler, externMethods, externMethodsWithoutSignatures, methodDefinitions, nonMethodProperties
Constructor and Description |
---|
InlineSimpleMethods(AbstractCompiler compiler) |
Modifier and Type | Method and Description |
---|---|
private boolean |
allDefinitionsEquivalent(java.util.Collection<Node> definitions)
Given a set of method definitions, verify they are the same.
|
private boolean |
argsMayHaveSideEffects(Node call)
Check whether the given method call's arguments have side effects.
|
(package private) NodeTraversal.Callback |
getActingCallback()
Subclasses should return a callback that does the actual work they
want to perform given the computed list of method signatures
|
private static Node |
getMethodBlock(Node fn)
Return a BLOCK node if the given FUNCTION node is a valid method
definition, null otherwise.
|
(package private) MethodCompilerPass.SignatureStore |
getSignatureStore()
Subclasses should return a SignatureStore for storing discovered
signatures.
|
private void |
inlineConstReturn(Node parent,
Node call,
Node returnedValue)
Replace the provided object and its method call with the tree specified
in returnedValue.
|
private void |
inlineEmptyMethod(Node parent,
Node call)
Remove the provided object and its method call.
|
private void |
inlinePropertyReturn(Node parent,
Node call,
Node returnedValue)
Replace the provided method call with the tree specified in returnedValue
Parse tree of a call is
name
call
getprop
obj
string
|
private static boolean |
isEmptyMethod(Node fn)
Return whether the given FUNCTION node is an empty method definition.
|
private static boolean |
isPropertyTree(Node expectedGetprop)
Returns true if the provided node is a getprop for
which the left child is this or a valid property tree
and for which the right side is a string.
|
private static void |
replaceThis(Node expectedGetprop,
Node replacement)
Finds the occurrence of "this" in the provided property tree and replaces
it with replacement
|
private static Node |
returnedExpression(Node fn)
Return the node that represents the expression returned
by the method, given a FUNCTION node.
|
process
private static final java.util.logging.Logger logger
static final MethodCompilerPass.SignatureStore DUMMY_SIGNATURE_STORE
InlineSimpleMethods(AbstractCompiler compiler)
NodeTraversal.Callback getActingCallback()
MethodCompilerPass
getActingCallback
in class MethodCompilerPass
private static boolean isPropertyTree(Node expectedGetprop)
private static void replaceThis(Node expectedGetprop, Node replacement)
private static Node returnedExpression(Node fn)
private static boolean isEmptyMethod(Node fn)
private static Node getMethodBlock(Node fn)
private boolean allDefinitionsEquivalent(java.util.Collection<Node> definitions)
private void inlinePropertyReturn(Node parent, Node call, Node returnedValue)
private void inlineConstReturn(Node parent, Node call, Node returnedValue)
private void inlineEmptyMethod(Node parent, Node call)
private boolean argsMayHaveSideEffects(Node call)
call
- The call node of a method invocation.MethodCompilerPass.SignatureStore getSignatureStore()
MethodCompilerPass
getSignatureStore
in class MethodCompilerPass