[ 
https://issues.apache.org/jira/browse/SPARK-25093?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16582543#comment-16582543
 ] 

Marco Gaido commented on SPARK-25093:
-------------------------------------

[~igreenfi] do you want to submit a PR for this? Otherwise I can do it. Thanks.

> CodeFormatter could avoid creating regex object again and again
> ---------------------------------------------------------------
>
>                 Key: SPARK-25093
>                 URL: https://issues.apache.org/jira/browse/SPARK-25093
>             Project: Spark
>          Issue Type: Improvement
>          Components: Spark Core
>    Affects Versions: 2.4.0
>            Reporter: Izek Greenfield
>            Priority: Minor
>
> in class `CodeFormatter` 
> method: `stripExtraNewLinesAndComments`
> could be refactored to: 
> {code:scala}
> // Some comments here
>  val commentReg =
>     ("""([ |\t]*?\/\*[\s|\S]*?\*\/[ |\t]*?)|""" +    // strip /*comment*/
>       """([ |\t]*?\/\/[\s\S]*?\n)""").r              // strip //comment
>   val emptyRowsReg = """\n\s*\n""".r
> def stripExtraNewLinesAndComments(input: String): String = {
>     val codeWithoutComment = commentReg.replaceAllIn(input, "")
>     emptyRowsReg.replaceAllIn(codeWithoutComment, "\n") // strip ExtraNewLines
>   }
> {code}
> so the Regex would be compiled only once.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org
For additional commands, e-mail: issues-h...@spark.apache.org

Reply via email to