@@ -188,29 +188,48 @@ protected function getDefaultBlock(string $tag, int $i1, int $j1): array
188
188
}
189
189
190
190
/**
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.
194
192
*
195
193
* @param string[] $lines array of lines to format
196
194
*
197
195
* @return string[] array of the formatted lines
198
196
*/
199
197
protected function formatLines (array $ lines ): array
200
198
{
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
+ }
204
212
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
+ {
205
225
$ string = $ this ->expandTabs ($ string , $ this ->options ['tabSize ' ]);
206
226
$ string = $ this ->htmlSafe ($ string );
207
227
208
228
if ($ this ->options ['spacesToNbsp ' ]) {
209
229
$ string = $ this ->htmlFixSpaces ($ string );
210
230
}
211
231
212
- // split the string back to lines
213
- return \explode (RendererConstant::IMPLODE_DELIMITER , $ string );
232
+ return $ string ;
214
233
}
215
234
216
235
/**
0 commit comments