BranchOutputOptimizer
class BranchOutputOptimizer
Properties
protected int | $cnt | ||
protected int | $i | ||
protected array | $tokens |
Methods
Optimize the code used to output content
Capture the expressions used in any number of consecutive output statements
Capture an expression used in output at current index
Capture the source of a control structure from its keyword to its opening brace
Test whether the token at current index is an if/elseif/else token
Merge the branches of an if/elseif/else block
Merge two consecutive series of consecutive output expressions together
Optimize the "head" part of a series of branches in-place
Optimize the output of given branches
Optimize the "tail" part of a series of branches in-place
Parse the if, elseif or else branch starting at current index
Parse the if block (including elseif/else branches) starting at current index
Serialize a recorded branch back to PHP
Serialize a series of recorded branch back to PHP
Serialize a series of output expressions
Serialize a token back to PHP
Attempt to move past output assignment at current index
Details
at line 36
string
optimize(array $tokens)
Optimize the code used to output content
This method will go through the array of tokens, identify if/elseif/else blocks that contain identical code at the beginning or the end and move the common code outside of the block
at line 69
protected string[]
captureOutput()
Capture the expressions used in any number of consecutive output statements
Starts looking at current index. Ends at the first token that's not part of an output statement
at line 91
protected string
captureOutputExpression()
Capture an expression used in output at current index
Ends on "." or ";"
at line 128
protected string
captureStructure()
Capture the source of a control structure from its keyword to its opening brace
Ends after the brace, but the brace itself is not returned
at line 148
protected bool
isBranchToken()
Test whether the token at current index is an if/elseif/else token
at line 165
protected array
mergeIfBranches(array $branches)
Merge the branches of an if/elseif/else block
Returns an array that contains the following:
- before: array of PHP expressions to be output before the block
- source: PHP code for the if block
- after: array of PHP expressions to be output after the block
at line 200
protected array
mergeOutput(array $left, array $right)
Merge two consecutive series of consecutive output expressions together
at line 231
protected string[]
optimizeBranchesHead(array $branches)
Optimize the "head" part of a series of branches in-place
at line 259
protected string[]
optimizeBranchesOutput(array $branches, string $which)
Optimize the output of given branches
at line 290
protected string[]
optimizeBranchesTail(array $branches)
Optimize the "tail" part of a series of branches in-place
at line 302
protected array
parseBranch()
Parse the if, elseif or else branch starting at current index
Ends at the last }
at line 372
protected array
parseIfBlock()
Parse the if block (including elseif/else branches) starting at current index
at line 393
protected string
serializeBranch(array $branch)
Serialize a recorded branch back to PHP
at line 413
protected string
serializeIfBlock(array $block)
Serialize a series of recorded branch back to PHP
at line 424
protected string
serializeOutput(array $expressions)
Serialize a series of output expressions
at line 440
protected string
serializeToken(array|string $token)
Serialize a token back to PHP
at line 450
protected bool
skipOutputAssignment()
Attempt to move past output assignment at current index