groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patric Bechtel <patric.bech...@gmail.com>
Subject Re: [4/7] groovy git commit: 'new String()' is redundant
Date Wed, 04 Apr 2018 07:05:00 GMT
Hi Daniel,

sorry to intervene here, but this new String() is actually necessary, otherwise you're constantly
changing the very same instance from the constant pool. *Very* dangerous.

/Patric

sunlan@apache.org schrieb am 04.04.2018 um 02:14:
> 'new String()' is redundant
> 
> (cherry picked from commit b07369a)
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
> Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/3abc4c5c
> Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3abc4c5c
> Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3abc4c5c
> 
> Branch: refs/heads/GROOVY_2_6_X
> Commit: 3abc4c5c6dc8deb6946630a46c085d4453923d9f
> Parents: aa837f8
> Author: sunlan <sunlan@apache.org>
> Authored: Wed Apr 4 08:05:38 2018 +0800
> Committer: sunlan <sunlan@apache.org>
> Committed: Wed Apr 4 08:14:04 2018 +0800
> 
> ----------------------------------------------------------------------
>  .../java/org/apache/groovy/jsondirect/DirectFastStringService.java | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/groovy/blob/3abc4c5c/subprojects/groovy-json-direct/src/main/java/org/apache/groovy/jsondirect/DirectFastStringService.java
> ----------------------------------------------------------------------
> diff --git a/subprojects/groovy-json-direct/src/main/java/org/apache/groovy/jsondirect/DirectFastStringService.java
b/subprojects/groovy-json-direct/src/main/java/org/apache/groovy/jsondirect/DirectFastStringService.java
> index 0d7d4ad..a2ed84a 100644
> --- a/subprojects/groovy-json-direct/src/main/java/org/apache/groovy/jsondirect/DirectFastStringService.java
> +++ b/subprojects/groovy-json-direct/src/main/java/org/apache/groovy/jsondirect/DirectFastStringService.java
> @@ -37,7 +37,7 @@ public class DirectFastStringService implements FastStringService {
>      @Override
>      public String noCopyStringFromChars(char[] chars) {
>          if (WRITE_TO_FINAL_FIELDS) {
> -            String string = new String();
> +            String string = "";
>              UNSAFE.putObject(string, STRING_VALUE_FIELD_OFFSET, chars);
>              return string;
>          } else {
> 
> 


Mime
View raw message