@@ -188,29 +188,48 @@ protected function getDefaultBlock(string $tag, int $i1, int $j1): array
188188 }
189189
190190 /**
191- * Format a series of lines suitable for output in a HTML rendered diff.
192- * This involves replacing tab characters with spaces, making the HTML safe
193- * for output, ensuring that double spaces are replaced with etc.
191+ * Make a series of lines suitable for outputting in a HTML rendered diff.
194192 *
195193 * @param string[] $lines array of lines to format
196194 *
197195 * @return string[] array of the formatted lines
198196 */
199197 protected function formatLines (array $ lines ): array
200198 {
201- // glue all lines into a single string to get rid of multiple function calls later
202- // unnecessary, but should improve performance if there are many lines
203- $ string = \implode (RendererConstant::IMPLODE_DELIMITER , $ lines );
199+ /**
200+ * To prevent from invoking the same function calls for several times,
201+ * we can glue lines into a string and call functions for one time.
202+ * After that, we split the string back into lines.
203+ */
204+ return \explode (
205+ RendererConstant::IMPLODE_DELIMITER ,
206+ $ this ->formatStringFromLines (\implode (
207+ RendererConstant::IMPLODE_DELIMITER ,
208+ $ lines
209+ ))
210+ );
211+ }
204212
213+ /**
214+ * Make a string suitable for outputting in a HTML rendered diff.
215+ *
216+ * This my involve replacing tab characters with spaces, making the HTML safe
217+ * for output, ensuring that double spaces are replaced with etc.
218+ *
219+ * @param string $string the string of imploded lines
220+ *
221+ * @return string the formatted string
222+ */
223+ protected function formatStringFromLines (string $ string ): string
224+ {
205225 $ string = $ this ->expandTabs ($ string , $ this ->options ['tabSize ' ]);
206226 $ string = $ this ->htmlSafe ($ string );
207227
208228 if ($ this ->options ['spacesToNbsp ' ]) {
209229 $ string = $ this ->htmlFixSpaces ($ string );
210230 }
211231
212- // split the string back to lines
213- return \explode (RendererConstant::IMPLODE_DELIMITER , $ string );
232+ return $ string ;
214233 }
215234
216235 /**
0 commit comments