groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jochen Kemnade (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7540) Add a method to StringGroovyMethods for replacing String pairs supplied as a Map
Date Fri, 07 Aug 2015 10:36:45 GMT

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

Jochen Kemnade commented on GROOVY-7540:
----------------------------------------

Is the content of {{<pre class="groovyTestCase">}} run as part of the test suite? Neat!
It looks good to me. The StringBuilder initialization could be tweaked though, it could be
initialized with a definite capacity to avoid calls to ensureCapacity later. The hard part
is to know the correct size. If I'm not mistaken, the worst case is {noformat}text.length()
* ceil(max(replacements.values()*.length()) / min(replacements.keySet()*.length()){noformat}.
And if {noformat}replacements.keySet().find{text.indexOf(it) >= 0} == null{noformat}, we
can exit early to improve the performance of things like {noformat}'foobar'.replace([x:'y']){noformat}.

> Add a method to StringGroovyMethods for replacing String pairs supplied as a Map
> --------------------------------------------------------------------------------
>
>                 Key: GROOVY-7540
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7540
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Jochen Kemnade
>            Priority: Minor
>
> It should be possible to use a map with {{collectReplacements}}, like in
> {code}
> "f006ar".collectReplacements(["0":"o", "6":"b"])
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message