1 | <?php |
||
14 | class Optimizer extends IRProcessor |
||
15 | { |
||
16 | /** |
||
17 | * Optimize an IR |
||
18 | * |
||
19 | * @param DOMDocument $ir |
||
20 | * @return void |
||
21 | */ |
||
22 | public function optimize(DOMDocument $ir) |
||
46 | |||
47 | /** |
||
48 | * Clone closeTag elements that follow a switch into said switch |
||
49 | * |
||
50 | * If there's a <closeTag/> right after a <switch/>, clone the <closeTag/> at the end of |
||
51 | * the every <case/> that does not end with a <closeTag/> |
||
52 | * |
||
53 | * @param DOMDocument $ir |
||
54 | * @return void |
||
55 | */ |
||
56 | protected function cloneCloseTagElementsIntoSwitch(DOMDocument $ir) |
||
71 | |||
72 | /** |
||
73 | * Clone closeTag elements from the head of a switch's cases before said switch |
||
74 | * |
||
75 | * If there's a <closeTag/> at the beginning of every <case/>, clone it and insert it |
||
76 | * right before the <switch/> unless there's already one |
||
77 | * |
||
78 | * @param DOMDocument $ir |
||
79 | * @return void |
||
80 | */ |
||
81 | protected function cloneCloseTagElementsOutOfSwitch(DOMDocument $ir) |
||
100 | |||
101 | /** |
||
102 | * Merge consecutive literal outputs |
||
103 | * |
||
104 | * @param DOMDocument $ir |
||
105 | * @return void |
||
106 | */ |
||
107 | protected function mergeConsecutiveLiteralOutputElements(DOMDocument $ir) |
||
119 | |||
120 | /** |
||
121 | * Test whether the next sibling of an element is a literal output element with matching escaping |
||
122 | * |
||
123 | * @param DOMElement $node |
||
124 | * @param string $disableOutputEscaping |
||
125 | * @return bool |
||
126 | */ |
||
127 | protected function nextSiblingIsLiteralOutput(DOMElement $node, $disableOutputEscaping) |
||
131 | |||
132 | /** |
||
133 | * Optimize closeTags elements |
||
134 | * |
||
135 | * @param DOMDocument $ir |
||
136 | * @return void |
||
137 | */ |
||
138 | protected function optimizeCloseTagElements(DOMDocument $ir) |
||
145 | |||
146 | /** |
||
147 | * Remove redundant closeTag siblings after a switch |
||
148 | * |
||
149 | * If all branches of a switch have a closeTag we can remove any closeTag siblings of the switch |
||
150 | * |
||
151 | * @param DOMDocument $ir |
||
152 | * @return void |
||
153 | */ |
||
154 | protected function removeCloseTagSiblings(DOMDocument $ir) |
||
159 | |||
160 | /** |
||
161 | * Remove content from void elements |
||
162 | * |
||
163 | * For each void element, we find whichever <closeTag/> elements close it and remove everything |
||
164 | * after |
||
165 | * |
||
166 | * @param DOMDocument $ir |
||
167 | * @return void |
||
168 | */ |
||
169 | protected function removeContentFromVoidElements(DOMDocument $ir) |
||
179 | |||
180 | /** |
||
181 | * Remove empty default cases (no test and no descendants) |
||
182 | * |
||
183 | * @param DOMDocument $ir |
||
184 | * @return void |
||
185 | */ |
||
186 | protected function removeEmptyDefaultCases(DOMDocument $ir) |
||
191 | |||
192 | /** |
||
193 | * Remove all nodes that match given XPath query |
||
194 | * |
||
195 | * @param DOMDocument $ir |
||
196 | * @param string $query |
||
197 | * @param DOMNode $contextNode |
||
198 | * @return void |
||
199 | */ |
||
200 | protected function removeNodes(DOMDocument $ir, $query, DOMNode $contextNode = null) |
||
210 | |||
211 | /** |
||
212 | * Remove redundant closeTag elements from the tail of a switch's cases |
||
213 | * |
||
214 | * For each <closeTag/> remove duplicate <closeTag/> nodes that are either siblings or |
||
215 | * descendants of a sibling |
||
216 | * |
||
217 | * @param DOMDocument $ir |
||
218 | * @return void |
||
219 | */ |
||
220 | protected function removeRedundantCloseTagElements(DOMDocument $ir) |
||
230 | |||
231 | /** |
||
232 | * Remove redundant closeTag elements from the tail of a switch's cases |
||
233 | * |
||
234 | * If there's a <closeTag/> right after a <switch/>, remove all <closeTag/> nodes at the |
||
235 | * end of every <case/> |
||
236 | * |
||
237 | * @param DOMDocument $ir |
||
238 | * @return void |
||
239 | */ |
||
240 | protected function removeRedundantCloseTagElementsInSwitch(DOMDocument $ir) |
||
254 | } |