groovy-notifications mailing list archives

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

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

Paul King commented on GROOVY-7540:
-----------------------------------

I tweaked to have a larger increase if longer replacements are found, but not as large as
you suggest - that could become wasteful when dealing with large strings. Premature optimization
tends to work well for the cases you have in mind but then make other cases much worse off.
So, I also provided a way to specify your own capacity. It is leaking the implementation to
some degree but in my mind is the preferred option rather than trying to go overboard with
pre-calculations or complex heuristics. The JVM is super efficient at creating objects and
copying arrays (e.g. when expanding a StringBuilder), so we should let it do its job most
of the time unless we know our optimizations will work well for all use cases.

> 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
>            Assignee: Paul King
>            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