You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Wenchen Fan (JIRA)" <ji...@apache.org> on 2018/08/22 06:34:00 UTC

[jira] [Resolved] (SPARK-25093) CodeFormatter could avoid creating regex object again and again

     [ https://issues.apache.org/jira/browse/SPARK-25093?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Wenchen Fan resolved SPARK-25093.
---------------------------------
       Resolution: Fixed
    Fix Version/s: 2.4.0

Issue resolved by pull request 22135
[https://github.com/apache/spark/pull/22135]

> 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
>            Assignee: Marco Gaido
>            Priority: Minor
>             Fix For: 2.4.0
>
>
> 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-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org